Use rules based c++ toolchain
Is your feature request related to a problem? Please describe. The current toolchain definitions are long and verbose: https://github.com/tweag/rules_nixpkgs/blob/master/core/private/cc_toolchain/cc_toolchain_config.bzl
Describe the solution you'd like Use the new rules based toolchain, example here: https://github.com/bazelbuild/rules_cc/tree/main/examples/rule_based_toolchain
Thank you for reaching out. I have seen the new, rules based approach and it looks very promising. Without having looked at it at a deeper level, I’m not sure how much work this entails. I think we should consider doing this.
In any case, if you or someone else wants to take a stab, we are open to contributions.
Hello,
Let me paste here some of my tiny findings for giving it a try yesterday evening. I ended up with such an error list:
ERROR: /home/kczulko/Projects/kczulko/rule_based_cc_toolchain_nixpkgs_rules_nim/BUILD.bazel:76:10: Compiling hello-world.cc failed: absolute path inclusion(s) found in rule '//:bin':
the source file 'hello-world.cc' includes the following non-builtin files with absolute paths (if these are builtin files, make sure these paths are in your toolchain):
'/nix/store/lcxvgkg659vbvdq86mhxa599wn48f35c-glibc-2.40-36-dev/include/stdc-predef.h'
'/nix/store/62qjb50708fdhb4f2y7zxyqr1afir4fk-gcc-13.3.0/include/c++/13.3.0/iostream'
'/nix/store/62qjb50708fdhb4f2y7zxyqr1afir4fk-gcc-13.3.0/include/c++/13.3.0/bits/requires_hosted.h'
'/nix/store/62qjb50708fdhb4f2y7zxyqr1afir4fk-gcc-13.3.0/include/c++/13.3.0/x86_64-unknown-linux-gnu/bits/c++config.h'
'/nix/store/62qjb50708fdhb4f2y7zxyqr1afir4fk-gcc-13.3.0/include/c++/13.3.0/x86_64-unknown-linux-gnu/bits/os_defines.h'
'/nix/store/lcxvgkg659vbvdq86mhxa599wn48f35c-glibc-2.40-36-dev/include/features.h'
...
which lead me to conclusion that what I am missing here is: https://github.com/tweag/rules_nixpkgs/blob/4b193df3b1a03415db74628944beb05c3320aae3/toolchains/cc/cc.bzl#L219 which is not exposed, I think (subject to additional check), by the rule based toolchain api. I also tried some combo with symlinkJoin/buildEnv where I could pass allowlist_include_directories but that also didn't work. cc_args with both -no-canonical-prefixes and -fno-canonical-system-headers also didn't help.