Skip to content

-x <language> flag gets inserted in the end. #22702

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

Closed
mcourteaux opened this issue Jan 31, 2025 · 4 comments
Closed

-x <language> flag gets inserted in the end. #22702

mcourteaux opened this issue Jan 31, 2025 · 4 comments
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@mcourteaux
Copy link

Zig Version

0.14.0-dev.2802

Steps to Reproduce and Observed Behavior

In the spirit of using zig as a drop-in compiler, I bumped into the issue that some C++ code from a third-party library #includes an Objective C header. Their build system simply adds -x objective-c++ to that file, but trying to do the same from build.zig fails, because the compilation flag goes in the end, which is a no-op. The flag should go in front of the files that need to be impacted.

Currently zig solely determines the language based on the extension, with no way to override it from build.zig.
A low-effort hack might be to simply detect the "-x" string being passed to the CSourceFile.flags and instead put that flag in the front?

I read in #13544 that @motiejus worked on something related to this, and did explicitly not include supporting specifying -x <language> from build.zig, because there was doubt whether that was a good idea or not.

Expected Behavior

const lib = b.addSharedLibrary(...);
lib.addCSourceFile(.{
   .file = "some_file.cpp",
   .flags = &.{"-x", "objective-c++"},
});

works and compiles this as Objective-C++.

@mcourteaux mcourteaux added the bug Observed behavior contradicts documented or intended behavior label Jan 31, 2025
@alexrp
Copy link
Member

alexrp commented Jan 31, 2025

Isn't this addressed by #20687?

@mcourteaux
Copy link
Author

Isn't this addressed by #20687?

Lol! Yesterday?! 😲 😝 I'll try it and close this in a couple minutes then. I hope it's in the nightly.

@mcourteaux
Copy link
Author

Not yet in the nightly build. I'll wait until tomorrow then to try to compile this. Thanks for the extremely quick reply!

@mcourteaux
Copy link
Author

mcourteaux commented Jan 31, 2025

Well, instead of waiting for tomorrow's nightly...,

git apply <(curl https://patch-diff.githubusercontent.com/raw/ziglang/zig/pull/20687.patch)

did the trick. Really neat feature on Github. The patch works. Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

2 participants