1

linkers: basic support for the 'zig cc' linker by Akaricchi · Pull Request #1229...

 7 months ago
source link: https://github.com/mesonbuild/meson/pull/12293
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Conversation

Contributor

Zig has a C/C++ compiler frontend that may be useful for cross-compiling. The compiler presents as clang (because it actually is), but since zig 0.11.0 the linker reports itself as zig ld, which confuses meson. It seems mostly compatible with lld, except lacking support for --thinlto-cache-dir (for now?).

I haven't tested this too thoroughly, but I was able to build the latest Taisei with this patch and a trivial cross file, for linux and windows.

Contributor

Mind adding a release notes snippet? Just something simple with an example on how to us it would be good enough

Contributor

Author

I'll add a release snippet but I'm sure if a usage example is necessary. You use it like any other compiler; zig cc/zig c++ are drop-in replacements for clang/clang++ respectively. This already worked with zig 0.10, because it just used the lld linker. Now it just works with zig 0.11 too.

Member

Previously, #11918

This PR seems to be better as it resolves an outstanding review comment from that PR about adding a unique linker class, and even smooths over some incompatibilities. ;)

I would still like to see zig installed in CI and tested, in addition to the release notes. Please also see the comment there about -fuse-ld.

Contributor

You can squash the commits. Thanks!

Contributor

Author

Now that I think about it, the linker id should probably be ld.zig, to be consistent with other GNU-style linkers. That way there should be less confusion if e.g. we ever support Zig as a language in Meson — the linker will probably have a different interface there.

Contributor

Author

Please also see the comment there about -fuse-ld

@eli-schwartz
Zig seems to completely ignore -fuse-ld. What should we do about it?

Contributor

Author

Some of the comments in the other PR seem inaccurate.

That just means that if users try to configure a linker for zig, meson will error out when trying to pass that linker as -fuse-ld.

There's no error or even a warning; as I said above, -fuse-ld is just ignored.

It depends on the target platform. In linux, it's compatible to clang. It will probably be a different story on MacOS or Windows, which I did not test.

zig cc has the same clang/lld-compatible interface on all platforms. The article I linked even shows this by running it in Wine.
EDIT: or so it seems; I'm actually not sure about the linker part anymore. One thing I know is I did cross-compile a moderately complex project for windows with this patch.

Member

Now that I think about it, the linker id should probably be ld.zig, to be consistent with other GNU-style linkers. That way there should be less confusion if e.g. we ever support Zig as a language in Meson — the linker will probably have a different interface there.

I might be working on that. For the moment Zig looks more like Rust, generating a final output directly. Like Rust it can compile object files but getting Meson to the point it does that will be non-trivial.

I would prefer that the linker be called someting other than just zig, I don't love ld.zig, but I could live with it. what about zigcc ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Back to tour

jpakkane

Awaiting requested review from jpakkanejpakkane is a code owner
Assignees

No one assigned

Labels
None yet
Projects

None yet

Milestone

1.4.0

Development

Successfully merging this pull request may close these issues.

None yet

5 participants

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK