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

Windows Builds Fail when clang-cl Flags are added to CXXFLAGS #435

Open
Redfire75369 opened this issue Dec 6, 2023 · 1 comment · May be fixed by #437
Open

Windows Builds Fail when clang-cl Flags are added to CXXFLAGS #435

Redfire75369 opened this issue Dec 6, 2023 · 1 comment · May be fixed by #437

Comments

@Redfire75369
Copy link
Contributor

Redfire75369 commented Dec 6, 2023

The root issue here is that bindgen uses clang (not clang-cl) on windows, and on unrecognised flags, it fails. Upon adding CXXFLAGS="/clang:-flto=thin /clang:-fuse-ld=lld-link", the below code automatically adds it to bindgen's flags as well. As /clang: flags are only recognised by clang-cl, there is no way for cc and the makefile.cargo to receive the CXXFLAGS but not bindgen.

mozjs/mozjs-sys/build.rs

Lines 334 to 338 in c7fb1b8

if let Ok(flags) = env::var("CXXFLAGS") {
for flag in flags.split_whitespace() {
builder = builder.clang_arg(flag);
}
}

There are a few possible approaches:

  1. If a flag starts with /clang: on windows, do not add it to bindgen.
  2. Add a separate BINDGEN_CXXFLAGS variable for bindgen's flags.

As said earlier, the root issue is the usage of clang, which means this error may not be just from /clang: flags but almost any cl flag. Hence, I would suggest the latter approach.

For a concrete example of the failure, see https://github.com/Redfire75369/spiderfire/actions/runs/7112793006/job/19363443030#step:6:18053, where a libclang error is caused.

In the event it matters for updating whatever depends on it, #136 was the original PR where this behaviour was introduced.

@jschwe
Copy link
Contributor

jschwe commented May 29, 2024

Does setting the CLANG_PATH environment variable to clang-cl fix this issue?

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

Successfully merging a pull request may close this issue.

2 participants