Skip to content

Commit 533f253

Browse files
Merge pull request #10 from buildbuddy-io/musl
Do the simplest thing to build with musl
2 parents 429bf4c + 6680e6a commit 533f253

File tree

4 files changed

+69
-1
lines changed

4 files changed

+69
-1
lines changed

.bazelrc

+5-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ build:java21 --tool_java_runtime_version=remotejdk_21
8989
import %workspace%/tools/javacopts.bazelrc
9090

9191
# For release, stamp binaries, use optimized mode w/ minimum line table debugging.
92-
build:release --stamp -c opt --copt=-gmlt
92+
build:release --stamp -c opt
9393

9494
# Use the RBE instance in the kythe-repo project
9595
build:remote --remote_instance_name=projects/kythe-repo/instances/default_instance --bes_instance_name=kythe-repo
@@ -124,6 +124,10 @@ build:remote --repo_env=KYTHE_DO_NOT_DETECT_BAZEL_TOOLCHAINS=1
124124
build:remote --extra_toolchains=//tools/build_rules/lexyacc:lexyacc_remote_toolchain
125125
build:remote --extra_toolchains=//tools/build_rules/external_tools:external_tools_remote_toolchain
126126

127+
# Build fully static binaries linked against musl on Linux.
128+
common:static --platforms=//platforms:linux_x86_64_musl
129+
common:static-arm64 --platforms=//platforms:linux_arm64_musl
130+
127131
build:remote --action_env=LEIN_JAVA_CMD=
128132

129133
build:prepush --verbose_failures --noshow_loading_progress --noshow_progress

WORKSPACE

+18
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,21 @@ git_repository(
109109
commit = "133d89a6069ce253a92d32a93fdb7db9ef100e9d",
110110
remote = "https://github.com/erenon/bazel_clang_tidy.git",
111111
)
112+
113+
http_archive(
114+
name = "musl_toolchains",
115+
sha256 = "26cacffab74e10f0840c83b0be9193dc6deccfbc8ec1cf6f8362dc61d0057fa1",
116+
url = "https://github.com/bazel-contrib/musl-toolchain/releases/download/v0.1.15/musl_toolchain-v0.1.15.tar.gz",
117+
)
118+
119+
load("@musl_toolchains//:repositories.bzl", "load_musl_toolchains")
120+
121+
load_musl_toolchains(
122+
extra_target_compatible_with = [
123+
"@//toolchains:musl_on",
124+
],
125+
)
126+
127+
load("@musl_toolchains//:toolchains.bzl", "register_musl_toolchains")
128+
129+
register_musl_toolchains()

platforms/BUILD

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
# Target this platforms with --platforms for a static build linked against musl libc.
4+
# Only meant to be used as a target platform.
5+
platform(
6+
name = "linux_x86_64_musl",
7+
constraint_values = [
8+
"@platforms//cpu:x86_64",
9+
"@platforms//os:linux",
10+
"//toolchains:musl_on",
11+
],
12+
)
13+
14+
# Target this platforms with --platforms for a static build linked against musl libc.
15+
# Only meant to be used as a target platform.
16+
platform(
17+
name = "linux_arm64_musl",
18+
constraint_values = [
19+
"@platforms//cpu:arm64",
20+
"@platforms//os:linux",
21+
"//toolchains:musl_on",
22+
],
23+
)

toolchains/BUILD

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
constraint_setting(
2+
name = "use_musl",
3+
default_constraint_value = ":musl_off",
4+
visibility = [
5+
"//visibility:public",
6+
],
7+
)
8+
9+
constraint_value(
10+
name = "musl_on",
11+
constraint_setting = ":use_musl",
12+
visibility = [
13+
"//visibility:public",
14+
],
15+
)
16+
17+
constraint_value(
18+
name = "musl_off",
19+
constraint_setting = ":use_musl",
20+
visibility = [
21+
"//visibility:public",
22+
],
23+
)

0 commit comments

Comments
 (0)