Update rules_nixpgks to HEAD and drop rules-nixpkgs-arm.patch (#13798)

* Update `rules_nixpgks` to HEAD

Since [rules_nixpkgs#191] has been merged, we can drop the `rules-nixpkgs-arm.patch` from rules_nixpkgs.

Also, rules_nixpkgs has been split into several components which need to be
added explicitly in `deps.bzl`, see [#182].

[#191]: https://github.com/tweag/rules_nixpkgs/pull/191
[#182]: https://github.com/tweag/rules_nixpkgs/issues/182

* Adapt `compatibility/deps.bzl`

* Update platforms repository to version 0.0.4

It has been updated in rules_nixpkgs, so this just follows suite.

* Pass through `isClang` attribute for the cc-toolchain

In rules_nixpkgs, this attribute is now used to determine whether the compiler is clang, see [#216].

[#216]: https://github.com/tweag/rules_nixpkgs/pull/216

CHANGELOG_BEGIN
CHANGELOG_END
This commit is contained in:
Claudio Bley 2022-05-10 10:16:20 +02:00 committed by GitHub
parent 34a2c7aa6f
commit 38f424155a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 59 additions and 234 deletions

View File

@ -1,7 +1,7 @@
diff --git a/nixpkgs/nixpkgs.bzl b/nixpkgs/nixpkgs.bzl
diff --git a/core/nixpkgs.bzl b/core/nixpkgs.bzl
index 16fe59c..d590d44 100644
--- a/nixpkgs/nixpkgs.bzl
+++ b/nixpkgs/nixpkgs.bzl
--- a/core/nixpkgs.bzl
+++ b/core/nixpkgs.bzl
@@ -136,7 +136,7 @@ def _nixpkgs_package_impl(repository_ctx):
"The NIX_PATH environment variable is not inherited."
)

View File

@ -1,223 +0,0 @@
diff --git a/README.md b/README.md
index e7d15ca..a1f7440 100644
--- a/README.md
+++ b/README.md
@@ -1332,7 +1332,7 @@ Constraints for the target platform.
### nixpkgs_sh_posix_configure
<pre>
-nixpkgs_sh_posix_configure(<a href="#nixpkgs_sh_posix_configure-name">name</a>, <a href="#nixpkgs_sh_posix_configure-packages">packages</a>, <a href="#nixpkgs_sh_posix_configure-kwargs">kwargs</a>)
+nixpkgs_sh_posix_configure(<a href="#nixpkgs_sh_posix_configure-name">name</a>, <a href="#nixpkgs_sh_posix_configure-packages">packages</a>, <a href="#nixpkgs_sh_posix_configure-exec_constraints">exec_constraints</a>, <a href="#nixpkgs_sh_posix_configure-kwargs">kwargs</a>)
</pre>
Create a POSIX toolchain from nixpkgs.
@@ -1378,6 +1378,20 @@ default is <code>["stdenv.initialPath"]</code>
List of Nix attribute paths to draw Unix tools from.
+</p>
+</td>
+</tr>
+<tr id="nixpkgs_sh_posix_configure-exec_constraints">
+<td><code>exec_constraints</code></td>
+<td>
+
+optional.
+default is <code>None</code>
+
+<p>
+
+Constraints for the execution platform.
+
</p>
</td>
</tr>
diff --git a/nixpkgs/nixpkgs.bzl b/nixpkgs/nixpkgs.bzl
index d590d44..01b4ba0 100644
--- a/nixpkgs/nixpkgs.bzl
+++ b/nixpkgs/nixpkgs.bzl
@@ -11,7 +11,12 @@ load(
)
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load(":private/location_expansion.bzl", "expand_location")
-load(":private/constraints.bzl", "ensure_constraints")
+load(
+ ":private/constraints.bzl",
+ "default_constraints",
+ "ensure_constraints",
+ "ensure_constraints_pure",
+)
def _nixpkgs_git_repository_impl(repository_ctx):
repository_ctx.file(
@@ -443,7 +448,7 @@ def _parse_cc_toolchain_info(content, filename):
def _nixpkgs_cc_toolchain_config_impl(repository_ctx):
cpu_value = get_cpu_value(repository_ctx)
- darwin = cpu_value == "darwin"
+ darwin = cpu_value == "darwin" or cpu_value == "darwin_arm64"
cc_toolchain_info_file = repository_ctx.path(repository_ctx.attr.cc_toolchain_info)
if not cc_toolchain_info_file.exists and not repository_ctx.attr.fail_not_supported:
@@ -1344,36 +1349,37 @@ create_posix_toolchain()
# should run.
def _nixpkgs_sh_posix_toolchain_impl(repository_ctx):
- cpu = get_cpu_value(repository_ctx)
+ exec_constraints, _ = ensure_constraints_pure(
+ default_constraints = default_constraints(repository_ctx),
+ exec_constraints = repository_ctx.attr.exec_constraints,
+ )
repository_ctx.file("BUILD", executable = False, content = """
toolchain(
name = "nixpkgs_sh_posix_toolchain",
toolchain = "@{workspace}//:nixpkgs_sh_posix",
toolchain_type = "@rules_sh//sh/posix:toolchain_type",
- exec_compatible_with = [
- "@platforms//cpu:x86_64",
- "@platforms//os:{os}",
- "@io_tweag_rules_nixpkgs//nixpkgs/constraints:support_nix",
- ],
+ exec_compatible_with = {exec_constraints},
# Leaving the target constraints empty matter for cross-compilation.
# See Note [Target constraints for POSIX tools]
target_compatible_with = [],
)
""".format(
workspace = repository_ctx.attr.workspace,
- os = {"darwin": "osx"}.get(cpu, "linux"),
+ exec_constraints = exec_constraints,
))
_nixpkgs_sh_posix_toolchain = repository_rule(
_nixpkgs_sh_posix_toolchain_impl,
attrs = {
"workspace": attr.string(),
+ "exec_constraints": attr.string_list(),
},
)
def nixpkgs_sh_posix_configure(
name = "nixpkgs_sh_posix_config",
packages = ["stdenv.initialPath"],
+ exec_constraints = None,
**kwargs):
"""Create a POSIX toolchain from nixpkgs.
@@ -1387,6 +1393,7 @@ def nixpkgs_sh_posix_configure(
Args:
name: Name prefix for the generated repositories.
packages: List of Nix attribute paths to draw Unix tools from.
+ exec_constraints: Constraints for the execution platform.
nix_file_deps: See nixpkgs_package.
repositories: See nixpkgs_package.
repository: See nixpkgs_package.
@@ -1396,6 +1403,7 @@ def nixpkgs_sh_posix_configure(
nixpkgs_sh_posix_config(
name = name,
packages = packages,
+ exec_constraints = exec_constraints,
**kwargs
)
diff --git a/nixpkgs/private/constraints.bzl b/nixpkgs/private/constraints.bzl
index b35ec0b..fe353b7 100644
--- a/nixpkgs/private/constraints.bzl
+++ b/nixpkgs/private/constraints.bzl
@@ -1,26 +1,66 @@
load("@bazel_tools//tools/cpp:lib_cc_configure.bzl", "get_cpu_value")
-def ensure_constraints(repository_ctx):
+def default_constraints(repository_ctx):
+ """Calculate the default CPU and OS constraints based on the host platform.
+
+ Args:
+ repository_ctx: The repository context of the current repository rule.
+
+ Returns:
+ A list containing the cpu and os constraints.
+ """
+ cpu_value = get_cpu_value(repository_ctx)
+ cpu = {
+ "darwin": "@platforms//cpu:x86_64",
+ "darwin_arm64": "@platforms//cpu:arm64",
+ }.get(cpu_value, "@platforms//cpu:x86_64")
+ os = {
+ "darwin": "@platforms//os:osx",
+ "darwin_arm64": "@platforms//os:osx",
+ }.get(cpu_value, "@platforms//os:linux")
+ return [cpu, os]
+
+def ensure_constraints_pure(default_constraints, target_constraints = [], exec_constraints = []):
"""Build exec and target constraints for repository rules.
- If these are user-provided, then they are passed through. Otherwise we build for x86_64 on the current OS.
+ If these are user-provided, then they are passed through.
+ Otherwise, use the provided default constraints.
In either case, exec_constraints always contain the support_nix constraint, so the toolchain can be rejected on non-Nix environments.
Args:
- repository_ctx: The repository context of the current repository rule.
+ target_constraints: optional, User provided target_constraints.
+ exec_constraints: optional, User provided exec_constraints.
+ default_constraints: Fall-back constraints.
Returns:
exec_constraints, The generated list of exec constraints
target_constraints, The generated list of target constraints
"""
- cpu = get_cpu_value(repository_ctx)
- os = {"darwin": "osx"}.get(cpu, "linux")
- if not repository_ctx.attr.target_constraints and not repository_ctx.attr.exec_constraints:
- target_constraints = ["@platforms//cpu:x86_64"]
- target_constraints.append("@platforms//os:{}".format(os))
+ if not target_constraints and not exec_constraints:
+ target_constraints = default_constraints
exec_constraints = target_constraints
else:
- target_constraints = list(repository_ctx.attr.target_constraints)
- exec_constraints = list(repository_ctx.attr.exec_constraints)
+ target_constraints = list(target_constraints)
+ exec_constraints = list(exec_constraints)
exec_constraints.append("@io_tweag_rules_nixpkgs//nixpkgs/constraints:support_nix")
return exec_constraints, target_constraints
+
+def ensure_constraints(repository_ctx):
+ """Build exec and target constraints for repository rules.
+
+ If these are user-provided, then they are passed through.
+ Otherwise we build for the current CPU on the current OS, one of darwin-x86_64, darwin-arm64, or the default linux-x86_64.
+ In either case, exec_constraints always contain the support_nix constraint, so the toolchain can be rejected on non-Nix environments.
+
+ Args:
+ repository_ctx: The repository context of the current repository rule.
+
+ Returns:
+ exec_constraints, The generated list of exec constraints
+ target_constraints, The generated list of target constraints
+ """
+ return ensure_constraints_pure(
+ default_constraints = default_constraints(repository_ctx),
+ target_constraints = repository_ctx.attr.target_constraints,
+ exec_constraints = repository_ctx.attr.exec_constraints,
+ )
diff --git a/nixpkgs/toolchains/go.bzl b/nixpkgs/toolchains/go.bzl
index 0384a64..5b9f168 100644
--- a/nixpkgs/toolchains/go.bzl
+++ b/nixpkgs/toolchains/go.bzl
@@ -8,7 +8,6 @@ dependencies on rules_go for those who don't need go toolchain.
"""
load("//nixpkgs:nixpkgs.bzl", "nixpkgs_package")
-load("@bazel_tools//tools/cpp:lib_cc_configure.bzl", "get_cpu_value")
load("@io_bazel_rules_go//go/private:platforms.bzl", "PLATFORMS")
def _detect_host_platform(ctx):
@@ -150,7 +149,6 @@ declare_toolchains("{goos}", "{goarch}")
"""
def _nixpkgs_go_toolchain_impl(repository_ctx):
- cpu = get_cpu_value(repository_ctx)
goos, goarch = _detect_host_platform(repository_ctx)
content = go_toolchain_func.format(
sdk_repo = repository_ctx.attr.sdk_repo,

View File

@ -71,9 +71,15 @@ def daml_deps():
)
if "io_tweag_rules_nixpkgs" not in native.existing_rules():
# N.B. rules_nixpkgs was split into separate components, which need to be loaded separately
#
# See https://github.com/tweag/rules_nixpkgs/issues/182 for the rational
strip_prefix = "rules_nixpkgs-%s" % rules_nixpkgs_version
http_archive(
name = "io_tweag_rules_nixpkgs",
strip_prefix = "rules_nixpkgs-%s" % rules_nixpkgs_version,
strip_prefix = strip_prefix,
urls = ["https://github.com/tweag/rules_nixpkgs/archive/%s.tar.gz" % rules_nixpkgs_version],
sha256 = rules_nixpkgs_sha256,
patches = [
@ -83,6 +89,26 @@ def daml_deps():
patch_args = ["-p1"],
)
http_archive(
name = "rules_nixpkgs_core",
strip_prefix = strip_prefix + "/core",
urls = ["https://github.com/tweag/rules_nixpkgs/archive/%s.tar.gz" % rules_nixpkgs_version],
sha256 = rules_nixpkgs_sha256,
patches = [
p.replace("@com_github_digital_asset_daml", "@daml")
for p in rules_nixpkgs_patches
],
patch_args = ["-p2"],
)
for toolchain in ["cc", "java", "python", "go", "rust", "posix"]:
http_archive(
name = "rules_nixpkgs_" + toolchain,
strip_prefix = strip_prefix + "/toolchains/" + toolchain,
urls = ["https://github.com/tweag/rules_nixpkgs/archive/%s.tar.gz" % rules_nixpkgs_version],
sha256 = rules_nixpkgs_sha256,
)
if "com_github_bazelbuild_buildtools" not in native.existing_rules():
http_archive(
name = "com_github_bazelbuild_buildtools",

View File

@ -49,8 +49,8 @@ rules_haskell_patches = [
# This should be upstreamed
"@com_github_digital_asset_daml//bazel_tools:haskell-arm-m1.patch",
]
rules_nixpkgs_version = "b39b20edc4637032bc65f6a93af888463027767c"
rules_nixpkgs_sha256 = "69bbc7aceaeab20693ae8bdc46b7d7a208ef3d3f1e5c295bef474d9b2e6aa39f"
rules_nixpkgs_version = "210d30a81cedde04b4281fd163428722278fddfb"
rules_nixpkgs_sha256 = "61b24e273821a15146f9ae7577e64b53f6aa332d5a7056abe8221ae2c346fdbd"
rules_nixpkgs_patches = [
# On CI and locally we observe occasional segmantation faults
# of nix. A known issue since Nix 2.2.2 is that HTTP2 support
@ -59,8 +59,6 @@ rules_nixpkgs_patches = [
# reportedly solves the issue. See
# https://github.com/NixOS/nix/issues/2733#issuecomment-518324335
"@com_github_digital_asset_daml//bazel_tools:nixpkgs-disable-http2.patch",
# This should be upstreamed
"@com_github_digital_asset_daml//bazel_tools:rules-nixpkgs-arm.patch",
]
buildifier_version = "4.0.0"
@ -90,8 +88,8 @@ davl_v3_sha256 = "e8e76e21b50fb3adab36df26045b1e8c3ee12814abc60f137d39b864d2eae1
daml_cheat_sheet_version = "2710b8df28d97253b5487a68feb2d1452d29fc54" # 2021-09-17
daml_cheat_sheet_sha256 = "eb022565a929a69d869f0ab0497f02d1a3eacb4dafdafa076a82ecbe7c401315"
platforms_version = "0.0.3"
platforms_sha256 = "15b66b5219c03f9e8db34c1ac89c458bb94bfe055186e5505d5c6f09cb38307f"
platforms_version = "0.0.4"
platforms_sha256 = "2697e95e085c6e1f970637d178e9dfa1231dca3a099d584ff85a7cb9c0af3826"
rules_sh_version = "47b4d823128f484ec1b06aa20349c4898216f486"
rules_sh_sha256 = "107d4312073d80a9977d3ccff236060d3906bda939fa2fbda4d724268c5b5383"
@ -124,15 +122,38 @@ def daml_deps():
)
if "io_tweag_rules_nixpkgs" not in native.existing_rules():
# N.B. rules_nixpkgs was split into separate components, which need to be loaded separately
#
# See https://github.com/tweag/rules_nixpkgs/issues/182 for the rational
strip_prefix = "rules_nixpkgs-%s" % rules_nixpkgs_version
http_archive(
name = "io_tweag_rules_nixpkgs",
strip_prefix = "rules_nixpkgs-%s" % rules_nixpkgs_version,
strip_prefix = strip_prefix,
urls = ["https://github.com/tweag/rules_nixpkgs/archive/%s.tar.gz" % rules_nixpkgs_version],
sha256 = rules_nixpkgs_sha256,
patches = rules_nixpkgs_patches,
patch_args = ["-p1"],
)
http_archive(
name = "rules_nixpkgs_core",
strip_prefix = strip_prefix + "/core",
urls = ["https://github.com/tweag/rules_nixpkgs/archive/%s.tar.gz" % rules_nixpkgs_version],
sha256 = rules_nixpkgs_sha256,
patches = rules_nixpkgs_patches,
patch_args = ["-p2"],
)
for toolchain in ["cc", "java", "python", "go", "rust", "posix"]:
http_archive(
name = "rules_nixpkgs_" + toolchain,
strip_prefix = strip_prefix + "/toolchains/" + toolchain,
urls = ["https://github.com/tweag/rules_nixpkgs/archive/%s.tar.gz" % rules_nixpkgs_version],
sha256 = rules_nixpkgs_sha256,
)
if "com_github_madler_zlib" not in native.existing_rules():
http_archive(
name = "com_github_madler_zlib",

View File

@ -65,4 +65,5 @@ buildEnv {
name = "bazel-cc-toolchain";
paths = [ customStdenv.cc ] ++ (if stdenv.isDarwin then [ darwinBinutils ] else [ binutils ]);
ignoreCollisions = true;
passthru = { isClang = customStdenv.cc.isClang; };
}