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

cc: make CXX_FLAG configurable #298

Merged
merged 1 commit into from
Jan 3, 2023
Merged

cc: make CXX_FLAG configurable #298

merged 1 commit into from
Jan 3, 2023

Conversation

evertedsphere
Copy link
Contributor

@evertedsphere evertedsphere commented Dec 22, 2022

This offers an alternative to the solution proposed in #219 to the problem of nixpkgs_cc_configure providing a non-configurable -x c++ in CXX_OPTS when calling a C compiler. We add a new optional cc_lang argument to nixpkgs_cc_configure, and then pass -x <cc_lang> instead.

Fixes #218.

@dmadisetti
Copy link
Contributor

Sure, this looks like the correct way to do things.

Plug and play into my project yields:

cannot find CUDA installation; provide its path via '--cuda-path', or pass '-nocudainc' to build without CUDA includes

While build a regular cc dependency. Not a massive blocker, I reckon this can be solved with setting environmental variables. But as in #219, auto-detection seems to work well enough so setting none seems to be best.

LGMT, but would suggest discussing the none option in the documentation since it is not well documented in clang (I had to refer to https://github.com/llvm-mirror/clang/blob/release_60/include/clang/Driver/Types.def)

Copy link
Member

@aherrmann aherrmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into this!

@dmadisetti does this solve the issue for you?

One issue I see with this approach is that it fixes the language for all targets built with that toolchain. Concretely, I'd expect the following type of thing to fail:

# WORKSPACE
nixpkgs_cc_configure(..., cc_lang = "cuda")
# BUILD
cc_binary(
    name = "cxx-bin",
    srcs = ["main.cc"],  # this is C++ code  -  I'd expect this to fail
)
cc_binary(
    name = "cude-bin",
    srcs = ["main.cu"],  # this is Cuda code
)

In that regard, bazelbuild/bazel#15499 seems like a much better solution.

That said, I'm not opposed to making the -x flag configurable, if it solves the issue.

@dmadisetti
Copy link
Contributor

Yes setting cc_lang = none works for me!

@evertedsphere
Copy link
Contributor Author

@dmadisetti perhaps cc_lang = none together with cc_library(copts = "-x whatever") is one possible way to go about it?

@aherrmann
Copy link
Member

Yes setting cc_lang = none works for me!

Nice!

@dmadisetti perhaps cc_lang = none together with cc_library(copts = "-x whatever") is one possible way to go about it?

@evertedsphere if that works, then that would be a good thing to recommend in the docs, instead of setting cuda at the top-level.

@dmadisetti
Copy link
Contributor

It's not needed from what I can see.
However, I did some basic testing to make sure this works. It looks like the none flag is properly overloaded.

@evertedsphere
Copy link
Contributor Author

evertedsphere commented Jan 2, 2023

@dmadisetti what about without none? Does using copts = "-x cuda" with a vanilla nixpkgs_cc_configure toolchain work?

@dmadisetti
Copy link
Contributor

@evertedsphere no, the conflicting flags fall back to the original

@dmadisetti
Copy link
Contributor

LGTM

Copy link
Member

@aherrmann aherrmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thank you!

@evertedsphere evertedsphere added the merge-queue merge on green CI label Jan 3, 2023
@mergify mergify bot merged commit 841eee4 into master Jan 3, 2023
@mergify mergify bot deleted the es/cxx_flag branch January 3, 2023 12:22
@mergify mergify bot removed the merge-queue merge on green CI label Jan 3, 2023
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 this pull request may close these issues.

CXX_FLAGS should allow for overload
3 participants