Closed Strum355 closed 1 year ago
Sorry for the delay in responding, I've only just had time to look into this. In summary, I was able to fix the missing tool issue by commenting out attribute_path
like this. More details below.
The @toolchain-darwin-aarch64_info
repository is created here:
nixpkgs_package(
name = "{}_info".format(name),
nix_file = "@rules_nixpkgs_cc//:cc.nix",
nix_file_deps = nix_file_deps,
build_file_content = "exports_files(['CC_TOOLCHAIN_INFO'])",
repositories = repositories,
repository = repository,
nixopts = nixopts,
quiet = quiet,
fail_not_supported = fail_not_supported,
)
Note the nixopts
parameter. By passing attribute_path
to nixpkgs_cc_configure
, we follow this path to construct it:
elif attribute_path:
nix_expr = "(import <nixpkgs> {{}}).{0}".format(attribute_path)
attribute_path = None
ccType=ccTypeExpression
in nixopts
:
elif nix_expr:
nixopts.extend([
"--argstr",
"ccType",
"ccTypeExpression",
"--arg",
"ccExpr",
nix_expr,
"--argstr",
"ccLang",
cc_lang,
])
ccTypeExpression
causes the special case handling for Darwin to be overridden:
cc =
if ccType == "ccTypeAttribute" then
pkgs.lib.attrByPath (pkgs.lib.splitString "." ccAttrPath) null ccAttrSet
else if ccType == "ccTypeExpression" then
ccExpr # <--- Passing attribute_path causes us to end up here ...
else # <--- ... but we want to be here for special handling of Darwin tools
pkgs.buildEnv (
let
cc = if pkgs.stdenv.isDarwin then darwinCC else pkgs.stdenv.cc;
in
{
name = "bazel-nixpkgs-cc";
# XXX: `gcov` is missing in `/bin`.
# It exists in `stdenv.cc.cc` but that collides with `stdenv.cc`.
paths = [ cc cc.bintools ] ++ pkgs.lib.optional pkgs.stdenv.isDarwin pkgs.darwin.cctools;
pathsToLink = [ "/bin" ];
passthru = {
isClang = cc.isClang;
};
}
)
If you really do need a custom nix expression, you'll have to make a copy of that bazel-nixpkgs-cc
derivation as a base to work from. Ideally, just passing attribute_path
wouldn't break the special handling for Darwin but the logic around nixopts
is pretty convoluted and some thought is needed for a proper fix.
Closing this as I gave a fix for the specific issue, while the more general problem is being tracked by #374.
Is your feature request related to a problem? Please describe. Using clang or gcc fails when building https://github.com/sourcegraph/scip-clang using nixpkgs provided toolchain via rules_nixpkgs. Progress/repro case can be found here: https://github.com/sourcegraph/scip-clang/commit/e17078a5b6d4d2e52796ae0c318cdc0b5a23bc31
Describe the solution you'd like
We currently use https://github.com/grailbio/bazel-toolchain for https://github.com/sourcegraph/scip-clang, which I want to experiment replacing with nixpkgs provided toolchains.
Additional context
Example errors from e.g.
bazelisk build //...
Output from
bazelisk build @toolchain-darwin-aarch64_info//:CC_TOOLCHAIN_INFO
(note all the missing tools replaced withfalse
)