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

Support custom CC/CXX args #18

Closed
zRedShift opened this issue Mar 23, 2022 · 9 comments
Closed

Support custom CC/CXX args #18

zRedShift opened this issue Mar 23, 2022 · 9 comments

Comments

@zRedShift
Copy link

Currently, in order to cross-compile macos targets, additional arguments are required (see ziglang/zig#1349 (comment)).
As a cargo zigbuild user, I have to manually modify the generated linker script ~/.cargo/bin/cargo-zigbuild zig c++ -- -target aarch64-macos-gnu -g $@
to e.g. ~/.cargo/bin/cargo-zigbuild zig cc -- -target aarch64-macos --sysroot=${MACOS_SDK} -I${MACOS_SDK}/usr/include -L${MACOS_SDK}/usr/lib -F${MACOS_SDK}/System/Library/Frameworks -framework Corefoundation -g $@ when I want to compile to a macos target, and link a framework. Then I manually add it to .cargo/config as the linker, along with the CC/CXX env vars, instead of simply running running cargo zigbuild --cc-args ... or something.

It would be nice to support this feature, I think, or maybe even have a couple of macos-only flags.

@messense
Copy link
Member

I guess it's only needed when linking frameworks?

@zRedShift
Copy link
Author

Not just frameworks, but also bundled libraries (like openssl). This isn't required for projects that are fully Rust, but for anything more involved, it may be necessary,

@messense
Copy link
Member

Does CFLAGS/CXXFLAGS/LDFLAGS or RUSTFLAGS supports setting --sysroot ?

@messense
Copy link
Member

Alternative we can add support to download a MacOS SDK automatically and set up --sysroot properly.

@zRedShift
Copy link
Author

I think I can set --sysroot with CFLAGS, I'll try it out now.

Regarding the SDK, I'm not sure we can rely on that reposity to last forever without Apple DMCAing it. They allowed to download the SDKs (as part of Command Line Tools for Xcode) freely before, but now you need to be authenticated now to download e.g. https://download.developer.apple.com/Developer_Tools/Command_Line_Tools_for_Xcode_13.3/Command_Line_Tools_for_Xcode_13.3.dmg.
I imagine it would be quite a hassle to automate and maintain this feature...

@messense
Copy link
Member

If we need to add --sysroot support, I think we can read it from the SDKROOT environment variable, CMake also does this:

If not set explicitly the value is initialized by the SDKROOT environment variable, if set

https://cmake.org/cmake/help/latest/variable/CMAKE_OSX_SYSROOT.html

@zRedShift
Copy link
Author

I tried setting CFLAGS/CXXFLAGS/LDFLAGS all to --sysroot=${SDKROOT} -I${SDKROOT}/usr/include -L${SDKROOT}/usr/lib -F${SDKROOT}/System/Library/Frameworks but it didn't work with cargo zigbuild (tried without the env as well).

I managed to compile without setting sysroot in the linker script with just: ~/.cargo/bin/cargo-zigbuild zig cc -- -target aarch64-macos -I${SDKROOT}/usr/include -L${SDKROOT}/usr/lib -F${SDKROOT}/System/Library/Frameworks -g $@ so I guess it's more of an include/library/framework lookup issue.

@messense
Copy link
Member

Can you try #20 ?

@zRedShift
Copy link
Author

Hey, thanks for the swift implementation!

I tried it out and can confirm it works for sufficiently new versions of zig (at least 0.9.1 ziglang/zig#10568, https://ziglang.org/download/0.9.1/release-notes.html#zig-cc--zig-c)
Doesn't work for 0.9.0 (the current version on arch), but I guess that's shouldn't be this project's problem.

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

2 participants