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

make zig cc use clang-compatible -target and -mcpu parameters #7360

Closed
eira-fransham opened this issue Dec 9, 2020 · 4 comments
Closed

make zig cc use clang-compatible -target and -mcpu parameters #7360

eira-fransham opened this issue Dec 9, 2020 · 4 comments
Labels
frontend Tokenization, parsing, AstGen, Sema, and Liveness. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. zig cc Zig as a drop-in C compiler feature
Milestone

Comments

@eira-fransham
Copy link

eira-fransham commented Dec 9, 2020

If you run clang with --target=arm64-unknown-linux-gnu it will understand it to mean the same as arm64-linux-gnu, but with zig cc it returns UnknownOperatingSystem. I wanted to use zig cc in a Rust build script, and this is an issue as Rust only uses 4-part target triples - and so <arch>-unknown-<sys>-<abi> is by far the most common format for targets. While I can work around this in my particular case, I wouldn't expect it to be particularly difficult to implement in Zig and it would make zig cc compatible with clang in more contexts.

@eira-fransham eira-fransham changed the title zig cc doesn't understand target triples including unknown zig cc doesn't understand target triples including unknown for vendor Dec 9, 2020
@eira-fransham eira-fransham reopened this Dec 9, 2020
@LemonBoy
Copy link
Contributor

I've hit this very same problem today and indeed having to patch the triple every time is annoying.
This said, Zig has no concept of vendors yet so we could:

  • Parse and ignore the field,
  • Parse the field and relay it to LLVM, Zig is still oblivious to the vendor part,
  • Same as above, but only when running zig cc,
  • Enhance Zig's triple to include the vendor part too.

@Vexu Vexu added bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness. zig cc Zig as a drop-in C compiler feature labels Dec 18, 2020
@Vexu Vexu added this to the 0.8.0 milestone Dec 18, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.8.1 Jun 4, 2021
@kubkon kubkon added proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. and removed bug Observed behavior contradicts documented or intended behavior labels Jul 30, 2021
@kubkon kubkon modified the milestones: 0.8.1, 0.9.0 Jul 30, 2021
@kubkon kubkon changed the title zig cc doesn't understand target triples including unknown for vendor handle "vendor" in target triple Jul 30, 2021
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 Nov 16, 2021
@andrewrk
Copy link
Member

andrewrk commented Nov 16, 2021

Currently the -target and -mcpu CLI parameters are parsed according to zig's understanding of these values rather than LLVM's, including in zig cc mode. This is intentional because Zig has a different set of targets than LLVM does, and we do want you to be able to specify operating systems, architectures, and CPU features according to zig's model rather than LLVM's model.

Of course it does have the downside noted by this issue, and when using zig cc the intent is to be clang-compatible. Whether to extend that to -target and -mcpu is the suggestion proposed by this issue.

It's annoying but I think the best solution to the problem is to parse the triple according to LLVM rules, only in zig cc (as @LemonBoy notes in the 3rd option), which involves a more onerous process than simply omitting the vendor, because the CPU model names and CPU features have different syntax (underscore instead of dash, for instance, but also the sets of features are not the same, and some are renamed).

I also haven't marked this as accepted, because, maybe it's better to not be clang-compatible in this one way?

@andrewrk andrewrk changed the title handle "vendor" in target triple make zig cc use clang-compatible -target and -mcpu parameters Nov 16, 2021
@eira-fransham
Copy link
Author

eira-fransham commented Nov 16, 2021

Maybe if there was some standard way to convert between LLVM and Zig triples (and -mcpu arguments) that existed outside of Zig then it wouldn't be so bad? You could then have a really thin script called, like zig clang or whatever, that does the conversion and passes it to zig cc. Seems kinda silly but it could lead to more flexibility in zig cc's argument syntax if you have an entirely separate binary whose only purpose is converting the arguments. So long as some method of conversion is maintained by you or someone else closely connected to the developments in zig cc (so that the conversion doesn't go out of date and/or rely on implementation details or unstable features) then the job of actually writing that binary can go to someone else.

@andrewrk
Copy link
Member

Duplicate of #4911

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frontend Tokenization, parsing, AstGen, Sema, and Liveness. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. zig cc Zig as a drop-in C compiler feature
Projects
None yet
Development

No branches or pull requests

5 participants