Skip to content

Commit e961dfc

Browse files
authored
Update crate universe to use musl binaries on Linux (#3401)
This change makes `musl` binaries available for all supported linux platforms.
1 parent 6287146 commit e961dfc

File tree

3 files changed

+25
-17
lines changed

3 files changed

+25
-17
lines changed

.github/workflows/release.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
name: Release
33
on:
44
workflow_dispatch:
5-
merge_group:
65
pull_request:
76
branches:
87
- main
@@ -28,7 +27,7 @@ jobs:
2827
steps:
2928
- uses: actions/checkout@v4
3029
- name: Ensure release does not already exist
31-
if: startsWith(github.ref, 'refs/heads/main') == false
30+
if: startsWith(github.ref, 'refs/heads/main')
3231
run: |
3332
git fetch origin &> /dev/null
3433
version="$(grep 'VERSION =' ${{ github.workspace }}/version.bzl | sed 's/VERSION = "//' | sed 's/"//')"
@@ -46,12 +45,15 @@ jobs:
4645
matrix:
4746
# Create a job for each target triple
4847
include:
49-
- os: macOS-13
48+
- os: macOS-14
5049
env:
5150
TARGET: "aarch64-apple-darwin"
5251
- os: ubuntu-22.04
5352
env:
5453
TARGET: "aarch64-unknown-linux-gnu"
54+
- os: ubuntu-22.04
55+
env:
56+
TARGET: "aarch64-unknown-linux-musl"
5557
- os: windows-2022
5658
env:
5759
TARGET: "aarch64-pc-windows-msvc"

crate_universe/extensions.bzl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -779,19 +779,19 @@ def _package_to_json(p):
779779
if v or k == "default_features"
780780
})
781781

782-
def _get_generator(module_ctx):
782+
def _get_generator(module_ctx, host_triple):
783783
"""Query Network Resources to local a `cargo-bazel` binary.
784784
785785
Based off get_generator in crates_universe/private/generate_utils.bzl
786786
787787
Args:
788-
module_ctx (module_ctx): The rules context object
788+
module_ctx (module_ctx): The rules context object
789+
host_triple (struct): A triple struct that represents the host.
789790
790791
Returns:
791792
tuple(path, dict) The path to a 'cargo-bazel' binary. The pairing (dict)
792793
may be `None` if there is not need to update the attribute
793794
"""
794-
host_triple = get_host_triple(module_ctx)
795795
use_environ = False
796796
for var in GENERATOR_ENV_VARS:
797797
if var in module_ctx.os.environ:
@@ -858,8 +858,11 @@ def _get_host_cargo_rustc(module_ctx, host_triple, host_tools_repo):
858858

859859
def _crate_impl(module_ctx):
860860
reproducible = True
861-
generator = _get_generator(module_ctx)
862-
host_triple = get_host_triple(module_ctx)
861+
host_triple = get_host_triple(module_ctx, abi = {
862+
"aarch64-unknown-linux": "musl",
863+
"x86_64-unknown-linux": "musl",
864+
})
865+
generator = _get_generator(module_ctx, host_triple)
863866

864867
all_repos = []
865868

rust/platform/triple.bzl

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def _validate_cpu_architecture(arch, expected_archs):
8686
expected_archs,
8787
))
8888

89-
def get_host_triple(repository_ctx, abi = None):
89+
def get_host_triple(repository_ctx, abi = {}):
9090
"""Query host information for the appropriate triple to use with load_arbitrary_tool or the crate_universe resolver
9191
9292
Example:
@@ -110,8 +110,9 @@ def get_host_triple(repository_ctx, abi = None):
110110
111111
Args:
112112
repository_ctx (repository_ctx): The repository_rule's context object
113-
abi (str): Since there's no consistent way to check for ABI, this info
114-
may be explicitly provided
113+
abi (dict): A mapping of platform triple prefixes to desired abi. This
114+
is useful since there's no consistent way to check for ABI, this info
115+
may be explicitly provided.
115116
116117
Returns:
117118
struct: A triple struct; see the `triple` function in this module
@@ -134,9 +135,10 @@ def get_host_triple(repository_ctx, abi = None):
134135

135136
if "linux" in repository_ctx.os.name:
136137
_validate_cpu_architecture(arch, supported_architectures["linux"])
137-
return triple("{}-unknown-linux-{}".format(
138-
arch,
139-
abi or "gnu",
138+
prefix = "{}-unknown-linux".format(arch)
139+
return triple("{}-{}".format(
140+
prefix,
141+
abi.get(prefix, "gnu"),
140142
))
141143

142144
if "mac" in repository_ctx.os.name:
@@ -145,9 +147,10 @@ def get_host_triple(repository_ctx, abi = None):
145147

146148
if "win" in repository_ctx.os.name:
147149
_validate_cpu_architecture(arch, supported_architectures["windows"])
148-
return triple("{}-pc-windows-{}".format(
149-
arch,
150-
abi or "msvc",
150+
prefix = "{}-pc-windows".format(arch)
151+
return triple("{}-{}".format(
152+
prefix,
153+
abi.get(prefix, "msvc"),
151154
))
152155

153156
fail("Unhandled host os: {}", repository_ctx.os.name)

0 commit comments

Comments
 (0)