Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Add support for zig #897

Closed
2 tasks
cathaysia opened this issue Nov 10, 2023 · 14 comments
Closed
2 tasks

[Feature Request] Add support for zig #897

cathaysia opened this issue Nov 10, 2023 · 14 comments

Comments

@cathaysia
Copy link
Contributor

cathaysia commented Nov 10, 2023

zig supports an easy-to-use cross-compilation experience, and also supports c and cpp. However, cc-rs' support for zig needs to be improved (mainly to perform some special processing when zig is recognized).

If cc-rs can accept these changes, I can make these work.

Tasks

Preview Give feedback
@NobodyXu
Copy link
Collaborator

disable sccache when using zig cc

Does zig-cc not work with sccache?
Is this something that can be fixed in zig itself?

@cathaysia
Copy link
Contributor Author

cathaysia commented Nov 10, 2023 via email

@NobodyXu
Copy link
Collaborator

NobodyXu commented Nov 10, 2023

the problem is sccache does not support zig,

That's unfortunate...

I think we need to doc this behavior when implementing support for zig cc.

zig has it's own cache system.

Can you provide me a link to the doc please?

I've been using cargo-zigbuild for a while but I never look deep into it, didn't know it has a caching system.

@cathaysia
Copy link
Contributor Author

maybe this?

https://ziglang.org/documentation/master/#C-Translation-Caching

and here are some links:

@NobodyXu
Copy link
Collaborator

Thanks, but https://gist.github.com/matu3ba/92e5df1166c51b3725dbd04f7ff1cb4e is outdated (its content says it's outdated).

For https://ziglang.org/documentation/master/#C-Translation-Caching , it just says it uses zig caching system but there's no doc for the zig caching system.

@cathaysia
Copy link
Contributor Author

Yeah, but I guess we don't need to look into zig's caching system? We just need to know that it does.

@NobodyXu
Copy link
Collaborator

NobodyXu commented Nov 10, 2023

Yeah, but I guess we don't need to look into zig's caching system? We just need to know that it does.

Yeah I'm just interested in how it works, I do think it's a good idea to support zig-cc, I would work on it after #893 is done

@cathaysia
Copy link
Contributor Author

I can't find the author's specific description of the zig cache system. Here it may be useful to you:

Of course, the best thing is probably to read the source code:

@NobodyXu
Copy link
Collaborator

Thanks!

I also found the cache dir using zig env and checks its content, now I have a rough idea on how it works.

@thomcc
Copy link
Member

thomcc commented Nov 12, 2023

The problem with supporting zig is that they don't use a standard names for the different target triples, and have indicated they'll likely change how this works in a future version. We'd need mappings for this and it would be a big pain, as they're likely to change.

In the mean time cargo-zigbuild sets everything right to use cc with zig, I'd recommend that.

Edit: More broadly, this is more work than just supporting zig cc and skipping wrappers. While zig has the ability to provide a nearly-seamless cross-compile experience (it's crazy, honestly -- I use it frequently). We have to correctly use its versions of the rest of the toolchain as well (ar, ranlib, etc). And even then, it's only really worth-while if you're also using it as the linker for the Rust build, hence my cargo-zigbuild suggestion.

When zig hits 1.0, I think I'd be more open to it.

@cathaysia
Copy link
Contributor Author

emm, let me explain why I don't want rust-zigbuild.

This question originally arose because I wanted to compile some c source code into a static library in rust, the cargo-zigbuild was descripted "Compile Cargo project with zig as linker", but I don't need using it as a linker.

so I use cc-rs, and pass zig's triple to $CC, it works fine. I open this issue in the hope that cc can solve some common problems (for example, a compiler like zig cc can only be passed through $CC, but not through the compiler function).

Of course, I now know why my cross-compiling with clang failed (because the nix-shell I used replaced the default clang, and the clang they provided added some OS-specific parameters, and just needed to change the compiler to the system The default will do)

@NobodyXu
Copy link
Collaborator

P.S. cargo-zigbuild cc can be used as a wrapper, though I do think cc should support zig-cc

@cathaysia
Copy link
Contributor Author

ok, so let's close this issue

@NobodyXu
Copy link
Collaborator

NobodyXu commented Jan 3, 2025

cc @cathaysia I now think rustup should ship zig-cc for cc-rs to use and use it for linking

https://internals.rust-lang.org/t/bundle-zig-cc-in-rustup-by-default/22096

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants