From 99a491caeb2ecce5e746966f15d84d8a7a288bef Mon Sep 17 00:00:00 2001 From: helly25 Date: Sat, 8 Nov 2025 18:42:24 +0100 Subject: [PATCH 1/3] Explain how version/requirement ccan be used from env vars. --- README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/README.md b/README.md index c0e55246..a3f7a7c8 100644 --- a/README.md +++ b/README.md @@ -142,6 +142,34 @@ supporting `<`, `<=`, `>`, `>=`, `==`, `!=`. Examples: - `latest:>17.0.4,!=19.1.7,<=20.1.0` - `first:>=15.0.6,<16` +It is further possible to provide the version or requirement from an environment +variable with a fallback version or requirement. In this case it is important to +also use the bazel flag `--repo_env=LLVM_VERSION=version_or_requirement`. It is +important to use both correctly because otherwise the resulting builds are not +reproducible. The main purpose of using an environment variable to encode the +version is for integration or batch testing on multiple platforms where multiple +LLVM version should be tested. + +- `getenv(ENVIRONMENT_VARIABLE_NAME,fallback)` + +Example `MODULE.bazel` + +``` +llvm.toolchain( + name = "llvm_toolchain", + llvm_versions = { + "": "getenv(LLVM_VERSION,latest:>=17.0.0,<20)", + "darwin-x86_64": "15.0.7", # Verify this works as opposed to using one version. + }, +) +``` + +In this example, MacOS x86 machines have their LLVM version hard-coded to +`15.0.7`. For all other targets the LLVM version is read from the environment +variable `LLVM_VERSION` which must be referenced on the Bazel command line as +explained above. If the variabel is not present, then the LLVM version defaults +to the requirement expression `latest:>=17.0.0,<20`. + ### Selecting Toolchains If toolchains are registered (see Quickstart section above), you do not need to From 21b85a3138683448e2cc46f6262f4cf44dccbff4 Mon Sep 17 00:00:00 2001 From: helly25 Date: Sat, 8 Nov 2025 18:44:48 +0100 Subject: [PATCH 2/3] Make trunk check happy. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a3f7a7c8..0f17811a 100644 --- a/README.md +++ b/README.md @@ -154,7 +154,7 @@ LLVM version should be tested. Example `MODULE.bazel` -``` +```starlark llvm.toolchain( name = "llvm_toolchain", llvm_versions = { From 161171e619a2048d9d9d4cf403e746041ce0f4a5 Mon Sep 17 00:00:00 2001 From: helly25 Date: Sat, 8 Nov 2025 18:51:59 +0100 Subject: [PATCH 3/3] Apply suggestions --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0f17811a..3e84becf 100644 --- a/README.md +++ b/README.md @@ -147,8 +147,8 @@ variable with a fallback version or requirement. In this case it is important to also use the bazel flag `--repo_env=LLVM_VERSION=version_or_requirement`. It is important to use both correctly because otherwise the resulting builds are not reproducible. The main purpose of using an environment variable to encode the -version is for integration or batch testing on multiple platforms where multiple -LLVM version should be tested. +version for integration or batch testing on multiple platforms where multiple +LLVM versions should be tested. - `getenv(ENVIRONMENT_VARIABLE_NAME,fallback)` @@ -167,7 +167,7 @@ llvm.toolchain( In this example, MacOS x86 machines have their LLVM version hard-coded to `15.0.7`. For all other targets the LLVM version is read from the environment variable `LLVM_VERSION` which must be referenced on the Bazel command line as -explained above. If the variabel is not present, then the LLVM version defaults +explained above. If the variable is not present, then the LLVM version defaults to the requirement expression `latest:>=17.0.0,<20`. ### Selecting Toolchains