Skip to content

Commit

Permalink
🎠 Sync flake module conventions to LRE (#258)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronmondal authored Dec 29, 2024
1 parent 67bf75e commit f3d2c7a
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ build --noexperimental_profile_include_primary_output
build --remote_instance_name=main

# Nix-generated action env for rules_ll.
try-import %workspace%/.bazelrc.ll
try-import %workspace%/ll.bazelrc

# Nix-generated flags for LRE.
try-import %workspace%/lre.bazelrc
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ MODULE.bazel.lock
examples/MODULE.bazel.lock

# Generated by the rules_ll bazelrc hook.
.bazelrc.ll
ll.bazelrc

# Generated by the LRE bazelrc hook.
.bazelrc.lre
lre.bazelrc

# Ignore NativeLink's local Pulumi stack.
Pulumi.dev.yaml
Expand Down
4 changes: 2 additions & 2 deletions examples/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ build --noexperimental_profile_include_primary_output
build --remote_instance_name=main

# Nix-generated action env for rules_ll. Usually this would be
# `%workspace%/.bazelrc.ll`, but since this example flake is in the rules_ll
# `%workspace%/ll.bazelrc`, but since this example flake is in the rules_ll
# repository we need to reference the file from the parent directory.
try-import %workspace%/../.bazelrc.ll
try-import %workspace%/../ll.bazelrc

# Nix-generated flags for LRE.
try-import %workspace%/../lre.bazelrc
Expand Down
10 changes: 6 additions & 4 deletions examples/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,12 @@
local-remote-execution.settings = {
inherit (pkgs.lre.lre-cc.meta) Env;
};
rules_ll.settings.llEnv = rules_ll.lib.defaultLlEnv {
inherit pkgs;
LL_CFLAGS = "-I${openssl.dev}/include";
LL_LDFLAGS = "-L${openssl.out}/lib";
rules_ll.settings = {
Env = rules_ll.lib.defaultLlEnv {
inherit pkgs;
LL_CFLAGS = "-I${openssl.dev}/include";
LL_LDFLAGS = "-L${openssl.out}/lib";
};
};
devShells.default = pkgs.mkShell {
nativeBuildInputs =
Expand Down
2 changes: 1 addition & 1 deletion flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ in
};
installationScript = mkOption {
type = types.str;
description = lib.mdDoc "A .bazelrc.ll generator for rules_ll.";
description = lib.mdDoc "A ll.bazelrc generator for rules_ll.";
default = cfg.settings.installationScript;
defaultText = lib.literalMD "bazelrc contents";
readOnly = true;
Expand Down
24 changes: 13 additions & 11 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,17 @@
pre-commit.settings = {
hooks = import ./pre-commit-hooks.nix { inherit pkgs; };
};
rules_ll.settings.llEnv =
let
openssl = (pkgs.openssl.override { static = true; });
in
self.lib.defaultLlEnv {
inherit pkgs;
LL_CFLAGS = "-I${openssl.dev}/include";
LL_LDFLAGS = "-L${openssl.out}/lib";
};
rules_ll.settings = {
Env =
let
openssl = (pkgs.openssl.override { static = true; });
in
self.lib.defaultLlEnv {
inherit pkgs;
LL_CFLAGS = "-I${openssl.dev}/include";
LL_LDFLAGS = "-L${openssl.out}/lib";
};
};
packages = {
ll = import ./devtools/ll.nix {
inherit pkgs;
Expand Down Expand Up @@ -145,11 +147,11 @@
# development shell.
${config.pre-commit.installationScript}
# Generate .bazelrc.ll which contains Bazel configuration
# Generate ll.bazelrc which contains Bazel configuration
# when rules_ll is run from a nix environment.
${config.rules_ll.installationScript}
# Generate .bazelrc.lre which configures the LRE toolchains.
# Generate lre.bazelrc which configures the LRE toolchains.
${config.local-remote-execution.installationScript}
# Ensure that the ll command points to our ll binary.
Expand Down
28 changes: 14 additions & 14 deletions modules/rules_ll.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ let

inherit (pkgs) runCommand writeText git;

processedActionEnvs = map (x: "build --@rules_ll//ll:" + x) config.llEnv;
processedActionEnvs = map (x: "build --@rules_ll//ll:" + x) config.Env;

configFile = runCommand ".bazelrc.ll" { } ''
configFile = runCommand "ll.bazelrc" { } ''
printf '# These flags are dynamically generated by rules_ll.
#
# Add try-import %%workspace%%/.bazelrc.ll to your .bazelrc to
# Add try-import %%workspace%%/ll.bazelrc to your .bazelrc to
# include these flags when running Bazel in a nix environment.
${lib.concatLines processedActionEnvs}' >$out
Expand All @@ -20,23 +20,23 @@ in
installationScript = mkOption {
type = types.str;
description = lib.mkDoc ''
A bash snippet which creates a .bazelrc.ll file in the repository.
A bash snippet which creates an ll.bazelrc file in the repository.
'';
};
llEnv = mkOption {
Env = mkOption {
type = types.listOf types.str;
description = lib.mdDoc ''
Environment variables for `--@rules_ll//ll:*` settings.
For instance:
```nix
llEnv = [
Env = [
"LL_CFLAGS=-I''${openssl.dev}/include"
]
```
results in the following line in `.bazelrc.ll`:
results in the following line in `ll.bazelrc`:
```bash
build --@rules_ll//ll:LL_CFLAGS=-I''${openssl.dev}/include
Expand Down Expand Up @@ -72,16 +72,16 @@ in
# filesystem churn. This improves performance with watch tools like
# lorri and prevents installation loops by lorri.
if ! readlink "''${GIT_WC}/.bazelrc.ll" >/dev/null \
|| [[ $(readlink "''${GIT_WC}/.bazelrc.ll") != ${configFile} ]]; then
if ! readlink "''${GIT_WC}/ll.bazelrc" >/dev/null \
|| [[ $(readlink "''${GIT_WC}/ll.bazelrc") != ${configFile} ]]; then
echo 1>&2 "rules_ll: updating $PWD repository"
[ -L .bazelrc.ll ] && unlink .bazelrc.ll
[ -L ll.bazelrc ] && unlink ll.bazelrc
if [ -e "''${GIT_WC}/.bazelrc.ll" ]; then
echo 1>&2 "rules_ll: WARNING: Refusing to install because of pre-existing .bazelrc.ll"
echo 1>&2 " Remove the .bazelrc.ll file and add .bazelrc.ll to .gitignore."
if [ -e "''${GIT_WC}/ll.bazelrc" ]; then
echo 1>&2 "rules_ll: WARNING: Refusing to install because of pre-existing ll.bazelrc"
echo 1>&2 " Remove the ll.bazelrc file and add ll.bazelrc to .gitignore."
else
ln -fs ${configFile} "''${GIT_WC}/.bazelrc.ll"
ln -fs ${configFile} "''${GIT_WC}/ll.bazelrc"
fi
fi
fi
Expand Down

0 comments on commit f3d2c7a

Please sign in to comment.