tweag / rules_nixpkgs

Rules for importing Nixpkgs packages into Bazel.
Apache License 2.0
285 stars 81 forks source link

compiler-rt-libc-*-dev not available in nixpkgs cc toolchain #442

Open iphydf opened 10 months ago

iphydf commented 10 months ago

Describe the bug #include <sanitizer/msan_interface.h> fails to compile on bazel with nixpkgs. It works with clang++.

To Reproduce Create a C file with #include <sanitizer/msan_interface.h> in it. Observe:

myfile.c:1:10: fatal error: 'sanitizer/msan_interface.h' file not found

Expected behavior It should compile.

Environment

Additional context The include directory is known to clang++:

[nix-shell:/src/workspace]$ clang++ -c -xc++ - -v
...
 /nix/store/l4mfdpx5d4ybn6ki1gjhlcmz6hv5p6kh-compiler-rt-libc-16.0.1-dev/include
...
avdv commented 10 months ago

Hi.

I think you should be able to use the library like any other, e.g. with

nixpkgs_package(
    name = "compiler-rt-libc",
    attribute_path = "llvmPackages_16.compiler-rt-libc",
    nix_file_content = """import <nixpkgs> { }""",
    repository = "@nixpkgs",
)

nixpkgs_package(
    name = "compiler-rt-libc.dev",
    attribute_path = "llvmPackages_16.compiler-rt-libc.dev",
    build_file_content = """\
load("@rules_cc//cc:defs.bzl", "cc_library")
filegroup(
    name = "include",
    srcs = glob(["include/**/*.h"]),
    visibility = ["//visibility:public"],
)
cc_library(
    name = "compiler-rt-libc",
    srcs = ["@compiler-rt-libc//:lib"],
    hdrs = [":include"],
    strip_include_prefix = "include",
    visibility = ["//visibility:public"],
)
""",
    nix_file_content = """import <nixpkgs> { }""",
    repository = "@nixpkgs",
)
iphydf commented 10 months ago

The problem is that Go stdlib uses that (when compiling with msan) but doesn't declare it, because it's assumed to be part of the toolchain. Same with absl and probably other third party dependencies.