Skip to content

Commit

Permalink
Move lre-cc into the lre overlay (#1529)
Browse files Browse the repository at this point in the history
This change makes lre-cc more portable and provides the structure into
which we can add additional toolchains, like the upcoming lre-rs.

The lre-cc logic now automatically registers the "implementation detail"
packages automatically.

The new command to regenerate lre-cc is now called `lre-cc`.
  • Loading branch information
aaronmondal authored Dec 9, 2024
1 parent d75d20d commit 2c1643d
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 86 deletions.
22 changes: 6 additions & 16 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,7 @@

nativelink-is-executable-test = pkgs.callPackage ./tools/nativelink-is-executable-test.nix {inherit nativelink;};

rbe-configs-gen = pkgs.callPackage ./local-remote-execution/rbe-configs-gen.nix {};

generate-toolchains = pkgs.callPackage ./tools/generate-toolchains.nix {inherit rbe-configs-gen;};
generate-toolchains = pkgs.callPackage ./tools/generate-toolchains.nix {};

native-cli = pkgs.callPackage ./native-cli/default.nix {};

Expand Down Expand Up @@ -243,10 +241,6 @@

nativelink-worker-init = pkgs.callPackage ./tools/nativelink-worker-init.nix {inherit buildImage self nativelink-image;};

rbe-autogen = pkgs.callPackage ./local-remote-execution/rbe-autogen.nix {
inherit buildImage;
inherit (pkgs.lre) stdenv;
};
createWorker = pkgs.callPackage ./tools/create-worker.nix {inherit buildImage self;};
buck2-toolchain = let
buck2-nightly-rust-version = "2024-04-28";
Expand Down Expand Up @@ -285,9 +279,6 @@
os = "linux";
};
};
lre-cc = pkgs.callPackage ./local-remote-execution/lre-cc.nix {
inherit buildImage;
};
toolchain-drake = buildImage {
name = "toolchain-drake";
# imageDigest and sha256 are generated by toolchain-drake.sh for non-reproducible builds.
Expand Down Expand Up @@ -364,7 +355,6 @@
rec {
inherit
local-image-test
lre-cc
native-cli
nativelink
nativelinkCoverageForHost
Expand All @@ -378,10 +368,9 @@
;
default = nativelink;

rbe-autogen-lre-cc = rbe-autogen lre-cc;
nativelink-worker-lre-cc = createWorker lre-cc;
nativelink-worker-lre-cc = createWorker pkgs.lre.lre-cc.image;
lre-java = pkgs.callPackage ./local-remote-execution/lre-java.nix {inherit buildImage;};
rbe-autogen-lre-java = rbe-autogen lre-java;
rbe-autogen-lre-java = pkgs.rbe-autogen lre-java;
nativelink-worker-lre-java = createWorker lre-java;
nativelink-worker-siso-chromium = createWorker siso-chromium;
nativelink-worker-toolchain-drake = createWorker toolchain-drake;
Expand Down Expand Up @@ -420,7 +409,7 @@
};
};
local-remote-execution.settings = {
Env =
Env = with pkgs.lre;
if pkgs.stdenv.isDarwin
then [] # Doesn't support Darwin yet.
else lre-cc.meta.Env;
Expand Down Expand Up @@ -483,6 +472,7 @@
# Additional tools from within our development environment.
local-image-test
generate-toolchains
pkgs.lre.lre-cc.lre-cc-configs-gen
pkgs.lre.clang
native-cli
docs
Expand Down Expand Up @@ -547,7 +537,7 @@
nixos = ./tools/nixos/flake-module.nix;
};
overlays = {
lre = import ./local-remote-execution/overlays/default.nix;
lre = import ./local-remote-execution/overlays/default.nix {inherit nix2container;};
};
};
}
2 changes: 1 addition & 1 deletion kubernetes/overlays/lre/worker-lre-cc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ spec:
args:
- |
git config --global --add safe.directory "*"
NATIVELINK_WORKER_PLATFORM=docker://lre-cc:$(nix eval /mnt/src_root#lre-cc.imageTag --raw) &&
NATIVELINK_WORKER_PLATFORM=docker://lre-cc:$(nix eval /mnt/src_root#nativelink-worker-lre-cc.imageTag --raw) &&
printf '#!/bin/sh\nexport NATIVELINK_WORKER_PLATFORM=%s\nexec "$@"' "$NATIVELINK_WORKER_PLATFORM" > /entrypoint/entrypoint.sh &&
chmod +x /entrypoint/entrypoint.sh
volumeMounts:
Expand Down
8 changes: 8 additions & 0 deletions local-remote-execution/flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,12 @@
}
);
};

config = {
perSystem = {pkgs, ...}: {
packages = {
rbe-autogen-lre-cc = pkgs.rbe-autogen pkgs.lre.lre-cc.image;
};
};
};
}
37 changes: 0 additions & 37 deletions local-remote-execution/lre-cc.nix

This file was deleted.

12 changes: 11 additions & 1 deletion local-remote-execution/overlays/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
final: _prev: {
{nix2container}: final: _prev: {
inherit (nix2container.packages.${final.system}) nix2container;

rbe-configs-gen = final.callPackage ./rbe-configs-gen {};

rbe-autogen = final.callPackage ./rbe-autogen.nix {
inherit (final.lre) stdenv;
};

lre = {
stdenv = final.callPackage ./stdenv.nix {
llvmPackages = final.llvmPackages_19;
Expand All @@ -8,5 +16,7 @@ final: _prev: {
clang = final.callPackage ./clang.nix {
inherit (final.lre) stdenv;
};

lre-cc = final.callPackage ./lre-cc.nix {};
};
}
84 changes: 84 additions & 0 deletions local-remote-execution/overlays/lre-cc.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
nix2container,
lre,
lib,
coreutils,
findutils,
gnutar,
bazel_7,
writeShellScriptBin,
rbe-configs-gen,
}: let
lre-cc-configs-gen = writeShellScriptBin "lre-cc" ''
set -xeuo pipefail
SRC_ROOT=$(git rev-parse --show-toplevel)/local-remote-execution
cd "''${SRC_ROOT}"
LRE_CC_IMAGE_TAG=${lre.lre-cc.image.imageTag};
nix run .#rbe-autogen-lre-cc.copyTo \
docker-daemon:rbe-autogen-lre-cc:''${LRE_CC_IMAGE_TAG} -L
${rbe-configs-gen}/bin/rbe_configs_gen \
--toolchain_container=rbe-autogen-lre-cc:''${LRE_CC_IMAGE_TAG} \
--exec_os=linux \
--target_os=linux \
--bazel_version=${bazel_7.version} \
--output_src_root=''${SRC_ROOT} \
--output_config_path=generated-cc \
--generate_java_configs=false \
--generate_cpp_configs=true \
--bazel_path=${bazel_7}/bin/bazel \
--cpp_env_json=cpp_env.json
# The rbe_configs_gen tool automatically sets the exec_properties of the
# generated platform to the generator container name and tag. For efficiency
# reasons the actual deployment won't be the same as this generator
# container, so we modify this in the generated configuration.
sed -i \
's|rbe-autogen-lre-cc|lre-cc|g' \
''${SRC_ROOT}/generated-cc/config/BUILD
chmod 644 \
''${SRC_ROOT}/generated-cc/LICENSE \
''${SRC_ROOT}/generated-cc/config/BUILD \
pre-commit run -a
'';

# TODO(aaronmondal): Move the generator logic into this packageset.
# This environment is shared between toolchain autogen images and the final
# toolchain image.
Env = [
# Add all tooling here so that the generated toolchains use `/nix/store/*`
# paths instead of `/bin` or `/usr/bin`. This way we're guaranteed to use
# binary identical toolchains during local and remote execution.
("PATH="
+ (lib.strings.concatStringsSep ":" [
"${lre.stdenv.cc.bintools}/bin"
"${lre.clang}/bin"
"${lre.stdenv}/bin"
"${coreutils}/bin"
"${findutils}/bin"
"${gnutar}/bin"
]))

"CC=${lre.clang}/bin/customClang"
];

image = nix2container.buildImage {
name = "lre-cc";
maxLayers = 100;
config = {inherit Env;};
# Attached for passthrough to rbe-configs-gen.
meta = {inherit Env;};

# Don't set a tag here so that the image is tagged by its derivation hash.
# tag = null;
};
in {
inherit lre-cc-configs-gen image;
meta = {inherit Env;};
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
bash,
bazel_7,
buildEnv,
buildImage,
nix2container,
cacert,
coreutils,
findutils,
Expand Down Expand Up @@ -96,7 +96,7 @@
};
in
image:
buildImage {
nix2container.buildImage {
name = "autogen-${image.imageName}";
fromImage = image;
maxLayers = 20;
Expand Down
File renamed without changes.
29 changes: 0 additions & 29 deletions tools/generate-toolchains.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,6 @@ writeShellScriptBin "generate-toolchains" ''
cd "''${SRC_ROOT}"
LRE_CC_IMAGE_TAG=$(nix eval .#lre-cc.imageTag --raw)
nix run .#rbe-autogen-lre-cc.copyTo \
docker-daemon:rbe-autogen-lre-cc:''${LRE_CC_IMAGE_TAG} -L
${rbe-configs-gen}/bin/rbe_configs_gen \
--toolchain_container=rbe-autogen-lre-cc:''${LRE_CC_IMAGE_TAG} \
--exec_os=linux \
--target_os=linux \
--bazel_version=${bazel_7.version} \
--output_src_root=''${SRC_ROOT} \
--output_config_path=generated-cc \
--generate_java_configs=false \
--generate_cpp_configs=true \
--bazel_path=${bazel_7}/bin/bazel \
--cpp_env_json=cpp_env.json
# The rbe_configs_gen tool automatically sets the exec_properties of the
# generated platform to the generator container name and tag. For efficiency
# reasons the actual deployment won't be the same as this generator
# container, so we modify this in the generated configuration.
sed -i \
's|rbe-autogen-lre-cc|lre-cc|g' \
''${SRC_ROOT}/generated-cc/config/BUILD
chmod 644 \
''${SRC_ROOT}/generated-cc/LICENSE \
''${SRC_ROOT}/generated-cc/config/BUILD \
LRE_JAVA_IMAGE_TAG=$(nix eval .#lre-java.imageTag --raw)
nix run .#rbe-autogen-lre-java.copyTo \
Expand Down

0 comments on commit 2c1643d

Please sign in to comment.