|
| 1 | +load("@bazel_tools//tools/cpp:cc_configure.bzl", "cc_autoconf_impl") |
| 2 | + |
1 | 3 | """Rules for importing Nixpkgs packages."""
|
2 | 4 |
|
3 | 5 | def _nixpkgs_git_repository_impl(repository_ctx):
|
@@ -190,3 +192,70 @@ def _executable_path(repository_ctx, exe_name, extra_msg=""):
|
190 | 192 | fail("Could not find the `{}` executable in PATH.{}\n"
|
191 | 193 | .format(exe_name, " " + extra_msg if extra_msg else ""))
|
192 | 194 | return path
|
| 195 | + |
| 196 | + |
| 197 | +def _cc_configure_custom(ctx): |
| 198 | + overriden_tools = { |
| 199 | + "gcc": ctx.path(ctx.attr.gcc), |
| 200 | + "ld": ctx.path(ctx.attr.ld), |
| 201 | + } |
| 202 | + return cc_autoconf_impl(ctx, overriden_tools) |
| 203 | + |
| 204 | + |
| 205 | +cc_configure_custom = repository_rule( |
| 206 | + implementation = _cc_configure_custom, |
| 207 | + attrs = { |
| 208 | + "gcc": attr.label( |
| 209 | + executable=True, |
| 210 | + cfg="host", |
| 211 | + allow_single_file=True, |
| 212 | + doc="`gcc` to use in cc toolchain", |
| 213 | + ), |
| 214 | + "ld": attr.label( |
| 215 | + executable=True, |
| 216 | + cfg="host", |
| 217 | + allow_single_file=True, |
| 218 | + doc="`ld` to use in cc toolchain", |
| 219 | + ), |
| 220 | + }, |
| 221 | + local = True, |
| 222 | + environ = [ |
| 223 | + "ABI_LIBC_VERSION", |
| 224 | + "ABI_VERSION", |
| 225 | + "BAZEL_COMPILER", |
| 226 | + "BAZEL_HOST_SYSTEM", |
| 227 | + "BAZEL_LINKOPTS", |
| 228 | + "BAZEL_PYTHON", |
| 229 | + "BAZEL_SH", |
| 230 | + "BAZEL_TARGET_CPU", |
| 231 | + "BAZEL_TARGET_LIBC", |
| 232 | + "BAZEL_TARGET_SYSTEM", |
| 233 | + "BAZEL_USE_CPP_ONLY_TOOLCHAIN", |
| 234 | + "BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN", |
| 235 | + "BAZEL_USE_LLVM_NATIVE_COVERAGE", |
| 236 | + "BAZEL_VC", |
| 237 | + "BAZEL_VS", |
| 238 | + "CC", |
| 239 | + "CC_CONFIGURE_DEBUG", |
| 240 | + "CC_TOOLCHAIN_NAME", |
| 241 | + "CPLUS_INCLUDE_PATH", |
| 242 | + "CUDA_COMPUTE_CAPABILITIES", |
| 243 | + "CUDA_PATH", |
| 244 | + "GCOV", |
| 245 | + "HOMEBREW_RUBY_PATH", |
| 246 | + "NO_WHOLE_ARCHIVE_OPTION", |
| 247 | + "SYSTEMROOT", |
| 248 | + "USE_DYNAMIC_CRT", |
| 249 | + "USE_MSVC_WRAPPER", |
| 250 | + "VS90COMNTOOLS", |
| 251 | + "VS100COMNTOOLS", |
| 252 | + "VS110COMNTOOLS", |
| 253 | + "VS120COMNTOOLS", |
| 254 | + "VS140COMNTOOLS", |
| 255 | + ], |
| 256 | +) |
| 257 | +"""Overwrite cc toolchain by supplying custom `gcc` and `ld` (e.g. from |
| 258 | +Nix). This allows to fix mismatch of `gcc` versions between what is used by |
| 259 | +packages that come from Nix (e.g. `ghc`) and what Bazel detects |
| 260 | +automatically (i.e. system-level `gcc`). |
| 261 | +""" |
0 commit comments