提交 e552c0d8 编写于 作者: D David Wood

bootstrap: add config option for nix patching

On NixOS systems, bootstrap will patch rustc used in bootstrapping after
checking `/etc/os-release` (to confirm the current distribution is NixOS).
However, when using Nix on a non-NixOS system, it can be desirable for
bootstrap to patch rustc. In this commit, a `patch-binaries-for-nix`
option is added to `config.toml`, which allows for user opt-in to
bootstrap's Nix patching.
Signed-off-by: NDavid Wood <david.wood@huawei.com>
上级 4e4942df
...@@ -313,6 +313,12 @@ changelog-seen = 2 ...@@ -313,6 +313,12 @@ changelog-seen = 2
# this setting's very existence, are all subject to change.) # this setting's very existence, are all subject to change.)
#print-step-rusage = false #print-step-rusage = false
# Always patch binaries for usage with Nix toolchains. If `true` then binaries
# will be patched unconditionally. If `false` or unset, binaries will be patched
# only if the current distribution is NixOS. This option is useful when using
# a Nix toolchain on non-NixOS distributions.
#patch-binaries-for-nix = false
# ============================================================================= # =============================================================================
# General install configuration options # General install configuration options
# ============================================================================= # =============================================================================
......
...@@ -594,19 +594,23 @@ class RustBuild(object): ...@@ -594,19 +594,23 @@ class RustBuild(object):
if ostype != "Linux": if ostype != "Linux":
return return
# Use `/etc/os-release` instead of `/etc/NIXOS`. # If the user has asked binaries to be patched for Nix, then
# The latter one does not exist on NixOS when using tmpfs as root. # don't check for NixOS or `/lib`, just continue to the patching.
try: if self.get_toml('patch-binaries-for-nix', 'build') != 'true':
with open("/etc/os-release", "r") as f: # Use `/etc/os-release` instead of `/etc/NIXOS`.
if not any(line.strip() == "ID=nixos" for line in f): # The latter one does not exist on NixOS when using tmpfs as root.
return try:
except FileNotFoundError: with open("/etc/os-release", "r") as f:
return if not any(line.strip() == "ID=nixos" for line in f):
if os.path.exists("/lib"): return
return except FileNotFoundError:
return
if os.path.exists("/lib"):
return
# At this point we're pretty sure the user is running NixOS # At this point we're pretty sure the user is running NixOS or
nix_os_msg = "info: you seem to be running NixOS. Attempting to patch" # using Nix
nix_os_msg = "info: you seem to be using Nix. Attempting to patch"
print(nix_os_msg, fname) print(nix_os_msg, fname)
# Only build `.nix-deps` once. # Only build `.nix-deps` once.
......
...@@ -397,6 +397,7 @@ struct Build { ...@@ -397,6 +397,7 @@ struct Build {
install_stage: Option<u32>, install_stage: Option<u32>,
dist_stage: Option<u32>, dist_stage: Option<u32>,
bench_stage: Option<u32>, bench_stage: Option<u32>,
patch_binaries_for_nix: Option<bool>,
} }
/// TOML representation of various global install decisions. /// TOML representation of various global install decisions.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册