mirror of
https://github.com/urbit/vere.git
synced 2024-09-11 03:45:31 +03:00
Build with musl instead of glibc on Linux (#27)
This commit is contained in:
parent
cb47df5e54
commit
7b3870d67e
59
BUILD.bazel
59
BUILD.bazel
@ -56,54 +56,25 @@ config_setting(
|
|||||||
# COMPILERS
|
# COMPILERS
|
||||||
#
|
#
|
||||||
|
|
||||||
constraint_setting(name = "compiler")
|
|
||||||
|
|
||||||
# Cross compiler from x86_64 to arm64.
|
|
||||||
constraint_value(
|
|
||||||
name = "aarch64_linux_gnu_gcc",
|
|
||||||
constraint_setting = ":compiler",
|
|
||||||
visibility = ["//visibility:public"],
|
|
||||||
)
|
|
||||||
|
|
||||||
# Compiler for x86_64.
|
|
||||||
constraint_value(
|
|
||||||
name = "clang",
|
|
||||||
constraint_setting = ":compiler",
|
|
||||||
visibility = ["//visibility:public"],
|
|
||||||
)
|
|
||||||
|
|
||||||
# Compiler for x86_64.
|
|
||||||
constraint_value(
|
|
||||||
name = "gcc",
|
|
||||||
constraint_setting = ":compiler",
|
|
||||||
visibility = ["//visibility:public"],
|
|
||||||
)
|
|
||||||
|
|
||||||
# Version flag for aarch64-linux-gnu-gcc.
|
|
||||||
string_flag(
|
|
||||||
name = "aarch64_linux_gnu_gcc_version",
|
|
||||||
build_setting_default = "12.2.0",
|
|
||||||
visibility = ["//visibility:public"],
|
|
||||||
)
|
|
||||||
|
|
||||||
# Version flag for clang.
|
# Version flag for clang.
|
||||||
string_flag(
|
string_flag(
|
||||||
name = "clang_version",
|
name = "clang_version",
|
||||||
build_setting_default = "14.0.6",
|
# macOS uses `clang-14.0.0` by default.
|
||||||
|
build_setting_default = "14.0.0",
|
||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
)
|
)
|
||||||
|
|
||||||
# Version flag for gcc.
|
# Version flag for gcc.
|
||||||
string_flag(
|
string_flag(
|
||||||
name = "gcc_version",
|
name = "gcc_version",
|
||||||
build_setting_default = "12.2.0",
|
# musl-cross-make uses `gcc-9.4.0` by default.
|
||||||
|
build_setting_default = "9.4.0",
|
||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
)
|
)
|
||||||
|
|
||||||
#
|
#
|
||||||
# PLATFORMS
|
# PLATFORMS
|
||||||
#
|
#
|
||||||
|
|
||||||
# A platform takes one of two formats: `<compiler>-<os>-<cpu>` or `<os>-<cpu>`
|
# A platform takes one of two formats: `<compiler>-<os>-<cpu>` or `<os>-<cpu>`
|
||||||
# if the compiler is unspecified.
|
# if the compiler is unspecified.
|
||||||
|
|
||||||
@ -125,28 +96,6 @@ platform(
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
# Linux x86_64 platform with aarch64-linux-gnu-gcc.
|
|
||||||
platform(
|
|
||||||
name = "aarch64_linux_gnu_gcc-linux-x86_64",
|
|
||||||
constraint_values = [
|
|
||||||
":aarch64_linux_gnu_gcc",
|
|
||||||
"@platforms//os:linux",
|
|
||||||
"@platforms//cpu:x86_64",
|
|
||||||
],
|
|
||||||
visibility = ["//visibility:public"],
|
|
||||||
)
|
|
||||||
|
|
||||||
# Linux x86_64 platform with clang.
|
|
||||||
platform(
|
|
||||||
name = "clang-linux-x86_64",
|
|
||||||
constraint_values = [
|
|
||||||
":clang",
|
|
||||||
"@platforms//os:linux",
|
|
||||||
"@platforms//cpu:x86_64",
|
|
||||||
],
|
|
||||||
visibility = ["//visibility:public"],
|
|
||||||
)
|
|
||||||
|
|
||||||
# Linux x86_64 platform with gcc.
|
# Linux x86_64 platform with gcc.
|
||||||
platform(
|
platform(
|
||||||
name = "gcc-linux-x86_64",
|
name = "gcc-linux-x86_64",
|
||||||
|
94
INSTALL.md
Normal file
94
INSTALL.md
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
# Building Vere
|
||||||
|
|
||||||
|
We use [`bazel`][bazel][^1] to built Vere, which is packaged as a single binary,
|
||||||
|
`urbit`. We spport the following `(host, target)` pairs, where the host platform
|
||||||
|
is where [`bazel`][bazel] runs and the target platform is where `urbit` will
|
||||||
|
run:
|
||||||
|
|
||||||
|
----------------------------------
|
||||||
|
Host Platform | Target Platform
|
||||||
|
----------------------------------
|
||||||
|
`linux-x86_64` | `linux-arm64`
|
||||||
|
`linux-x86_64` | `linux-x86_64`
|
||||||
|
`macos-arm64` | `macos-arm64`
|
||||||
|
`macos-x86_64` | `macos-x86_64`
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
### Linux
|
||||||
|
|
||||||
|
We use [musl libc][musl libc] instead [glibc][glibc] on Linux, which enables us
|
||||||
|
to generate statically linked binaries. As a prerequisite, you need to install
|
||||||
|
the [musl libc][musl libc] toolchain appropriate for your target platform.
|
||||||
|
|
||||||
|
#### x86_64
|
||||||
|
|
||||||
|
To install the `x86_64-linux-musl-gcc` toolchain at
|
||||||
|
`/usr/local/x86_64-linux-musl-gcc`, run:
|
||||||
|
```console
|
||||||
|
$ bazel run //bazel/toolchain:x86_64-linux-musl-gcc
|
||||||
|
```
|
||||||
|
|
||||||
|
This will take a few minutes.
|
||||||
|
|
||||||
|
#### aarch64
|
||||||
|
|
||||||
|
To install the `aarch64-linux-musl-gcc` toolchain at
|
||||||
|
`/usr/local/aarch64-linux-musl-gcc`, run:
|
||||||
|
```console
|
||||||
|
$ bazel run //bazel/toolchain:aarch64-linux-musl-gcc
|
||||||
|
```
|
||||||
|
|
||||||
|
This will take a few minutes.
|
||||||
|
|
||||||
|
### macOS
|
||||||
|
|
||||||
|
Ensure you have up-to-date versions of `bazelisk`, `automake`, and `libtool`:
|
||||||
|
```console
|
||||||
|
$ brew install bazelisk automake libtool
|
||||||
|
```
|
||||||
|
|
||||||
|
## Build Commands
|
||||||
|
|
||||||
|
Once you install the prerequisites, you're ready to build. If you're performing
|
||||||
|
a native build (i.e. one in which the host platform and target platform are the
|
||||||
|
same), run:
|
||||||
|
```console
|
||||||
|
$ bazel build //pkg/...
|
||||||
|
```
|
||||||
|
|
||||||
|
If you're performing a cross-platform build, you need to specify the target
|
||||||
|
platform in the build command:
|
||||||
|
```console
|
||||||
|
$ bazel build --platforms=//:<target-platform> //pkg/...
|
||||||
|
```
|
||||||
|
|
||||||
|
## Test Commands
|
||||||
|
|
||||||
|
You can build and run unit tests only on native builds. If you have a native
|
||||||
|
build and want to run all unit tests, run:
|
||||||
|
```console
|
||||||
|
$ bazel test //pkg/...
|
||||||
|
```
|
||||||
|
|
||||||
|
If you want to run a specific test, say
|
||||||
|
[`pkg/noun/hashtable_tests.c`](pkg/noun/hashtable_tests.c), run:
|
||||||
|
```console
|
||||||
|
$ bazel test //pkg/noun:hashtable_tests
|
||||||
|
```
|
||||||
|
|
||||||
|
## Common Issues
|
||||||
|
|
||||||
|
If `bazel build` or `bazel test` generates an `undeclared inclusion(s) in rule`
|
||||||
|
error on macOS, the version of `clang` expected by the build system likely
|
||||||
|
doesn't match the version of `clang` installed on your system. To address this,
|
||||||
|
pass `--clang_version="<version_string>"` to the failing command.
|
||||||
|
|
||||||
|
[^1]: If you're interested in digging into the details of the build system,
|
||||||
|
check out [`WORKSPACE.bazel`](WORKSPACE.bazel),
|
||||||
|
[`BUILD.bazel`](BUILD.bazel), [`bazel/`](bazel), and the multiple
|
||||||
|
`BUILD.bazel` files in [`pkg/`](pkg).
|
||||||
|
|
||||||
|
[bazel]: https://bazel.build
|
||||||
|
[glibc]: https://www.gnu.org/software/libc
|
||||||
|
[musl libc]: https://musl.libc.org
|
98
README.md
98
README.md
@ -26,105 +26,9 @@ defined in its own package:
|
|||||||
- [`pkg/noun`](pkg/noun): The Nock virtual machine and snapshotting system.
|
- [`pkg/noun`](pkg/noun): The Nock virtual machine and snapshotting system.
|
||||||
- [`pkg/vere`](pkg/vere): The I/O drivers, event log, and main event loop.
|
- [`pkg/vere`](pkg/vere): The I/O drivers, event log, and main event loop.
|
||||||
|
|
||||||
## Pre-requisites
|
|
||||||
|
|
||||||
### macOS
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ brew install bazelisk automake libtool
|
|
||||||
```
|
|
||||||
|
|
||||||
## Build
|
## Build
|
||||||
|
|
||||||
We use [`bazel`][bazel] to build Urbit's runtime, which is packaged as a single
|
See [INSTALL.md](INSTALL.md).
|
||||||
binary, `urbit`. We support the following `(host, target)` pairs, where the host
|
|
||||||
platform is where [`bazel`][bazel] runs and the target platform is where `urbit`
|
|
||||||
will run:
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
Host Platform | Target Platform | Required Toolchain
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
`aarch64_linux_gnu_gcc-linux-x86_64` | `linux-arm64` | `aarch64-linux_gnu_gcc`
|
|
||||||
`gcc-linux-x86_64` | `linux-x86_64` | `gcc`
|
|
||||||
`clang-linux-x86_64` | `linux-x86_64` | `clang`
|
|
||||||
`clang-macos-arm64` | `macos-arm64` | `clang`
|
|
||||||
`clang-macos-x86_64` | `macos-x86_64` | `clang`
|
|
||||||
|
|
||||||
Once you've identified your `(host, target)` pair, determine the version of the
|
|
||||||
pair's required toolchain and ensure you have an up-to-date version of
|
|
||||||
[`bazel`][bazel]. Then, run:
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ bazel build --<toolchain>_version="<toolchain_version>" \
|
|
||||||
--host_platform=//:<host_platform> \
|
|
||||||
--platforms=//:<target_platform> :urbit
|
|
||||||
```
|
|
||||||
|
|
||||||
For example, to build a `linux-x86_64` `urbit` binary on a `linux-x86_64`
|
|
||||||
machine using version `14.0.6` of the `clang` toolchain, run:
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ bazel build --clang_version="14.0.6" \
|
|
||||||
--host_platform=//:gcc-linux-x86_64 \
|
|
||||||
--platforms=//:linux-x86_64
|
|
||||||
```
|
|
||||||
|
|
||||||
And to build a `linux-arm64` `urbit` binary on a `linux-x86_64` machine using
|
|
||||||
version `12.2.0` of the `aarch64-linux-gnu-gcc` toolchain (which you'll have to
|
|
||||||
install), run:
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ bazel build --aarch64_linux_gnu_gcc_version="12.2.0" \
|
|
||||||
--host_platform=//:aarch64_linux_gnu_gcc-linux-x86_64 \
|
|
||||||
--platforms=//:linux-arm64
|
|
||||||
```
|
|
||||||
|
|
||||||
Specifying `--<toolchain>_version`, `--host_platform`, and `--platforms` for
|
|
||||||
each build is tedious and can be avoided by writing to `.user.bazelrc`:
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ echo 'build --aarch64_linux_gnu_gcc_version="12.2.0"' >> .user.bazelrc
|
|
||||||
$ echo 'build --clang_version="14.0.6"' >> .user.bazelrc
|
|
||||||
$ echo 'build --gcc_version="12.2.0"' >> .user.bazelrc
|
|
||||||
$ echo 'build --host_platform=//:<host_platform>' >> .user.bazelrc
|
|
||||||
$ echo 'build --platforms=//:<target_platform>' >> .user.bazelrc
|
|
||||||
$ bazel build :urbit
|
|
||||||
```
|
|
||||||
|
|
||||||
To run the just-built `urbit` binary, run:
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ bazel-bin/pkg/vere/urbit <snip>
|
|
||||||
```
|
|
||||||
|
|
||||||
Or, to save yourself a few keystrokes, create a symlink to the `urbit` binary in
|
|
||||||
the root of the repository:
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ ln -s bazel-bin/pkg/vere/urbit urbit
|
|
||||||
$ ./urbit <snip>
|
|
||||||
```
|
|
||||||
|
|
||||||
The remaining commands in this section assume that `.user.bazlerc` specifies
|
|
||||||
`--host_platform` and `--platforms`. If not, `--host_platform` and `--platforms`
|
|
||||||
must be provided at the command line as in the build commands above.
|
|
||||||
|
|
||||||
To run all runtime tests, run:
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ bazel test //...
|
|
||||||
```
|
|
||||||
|
|
||||||
or, to run a specific test, say
|
|
||||||
[`pkg/noun/hashtable_tests.c`](pkg/noun/hashtable_tests.c), run:
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ bazel test //pkg/noun:hashtable_tests
|
|
||||||
```
|
|
||||||
|
|
||||||
If you're interested in digging into the details of the build system, check out
|
|
||||||
[`WORKSPACE.bazel`](WORKSPACE.bazel), [`BUILD.bazel`](BUILD.bazel),
|
|
||||||
[`bazel/`](bazel), and the multiple `BUILD.bazel` files in [`pkg/`](pkg).
|
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
|
@ -93,8 +93,7 @@ versioned_http_archive(
|
|||||||
|
|
||||||
# Use the toolchains we've configured.
|
# Use the toolchains we've configured.
|
||||||
register_toolchains(
|
register_toolchains(
|
||||||
"//bazel/toolchain:aarch64_linux_gnu_gcc-linux-x86_64-toolchain",
|
"//bazel/toolchain:gcc-linux-arm64-toolchain",
|
||||||
"//bazel/toolchain:clang-linux-x86_64-toolchain",
|
|
||||||
"//bazel/toolchain:clang-macos-arm64-toolchain",
|
"//bazel/toolchain:clang-macos-arm64-toolchain",
|
||||||
"//bazel/toolchain:clang-macos-x86_64-toolchain",
|
"//bazel/toolchain:clang-macos-x86_64-toolchain",
|
||||||
"//bazel/toolchain:gcc-linux-x86_64-toolchain",
|
"//bazel/toolchain:gcc-linux-x86_64-toolchain",
|
||||||
|
4
bazel/third_party/curl/curl.BUILD
vendored
4
bazel/third_party/curl/curl.BUILD
vendored
@ -53,8 +53,8 @@ configure_make(
|
|||||||
"--without-zlib",
|
"--without-zlib",
|
||||||
"--without-zstd",
|
"--without-zstd",
|
||||||
] + select({
|
] + select({
|
||||||
# Native compilation on linux-arm64 isn't supported.
|
"@//:linux_arm64": ["--host=aarch64-linux-musl"],
|
||||||
"@//:linux_arm64": ["--host=aarch64-linux-gnu"],
|
"@//:linux_x86_64": ["--host=x86_64-linux-musl"],
|
||||||
"//conditions:default": [],
|
"//conditions:default": [],
|
||||||
}),
|
}),
|
||||||
env = {
|
env = {
|
||||||
|
4
bazel/third_party/gmp/gmp.BUILD
vendored
4
bazel/third_party/gmp/gmp.BUILD
vendored
@ -18,8 +18,8 @@ configure_make(
|
|||||||
# but we leave it in for all builds as a precaution.
|
# but we leave it in for all builds as a precaution.
|
||||||
"--with-pic",
|
"--with-pic",
|
||||||
] + select({
|
] + select({
|
||||||
# Native compilation on linux-arm64 isn't supported.
|
"@//:linux_arm64": ["--host=aarch64-linux-musl"],
|
||||||
"@//:linux_arm64": ["--host=aarch64-linux-gnu"],
|
"@//:linux_x86_64": ["--host=x86_64-linux-musl"],
|
||||||
"//conditions:default": [],
|
"//conditions:default": [],
|
||||||
}),
|
}),
|
||||||
lib_source = ":all",
|
lib_source = ":all",
|
||||||
|
4
bazel/third_party/secp256k1/secp256k1.BUILD
vendored
4
bazel/third_party/secp256k1/secp256k1.BUILD
vendored
@ -19,8 +19,8 @@ configure_make(
|
|||||||
"--enable-module-schnorrsig",
|
"--enable-module-schnorrsig",
|
||||||
"--enable-static",
|
"--enable-static",
|
||||||
] + select({
|
] + select({
|
||||||
# Native compilation on linux-arm64 isn't supported.
|
"@//:linux_arm64": ["--host=aarch64-linux-musl"],
|
||||||
"@//:linux_arm64": ["--host=aarch64-linux-gnu"],
|
"@//:linux_x86_64": ["--host=x86_64-linux-musl"],
|
||||||
"//conditions:default": [],
|
"//conditions:default": [],
|
||||||
}),
|
}),
|
||||||
lib_source = ":all",
|
lib_source = ":all",
|
||||||
|
4
bazel/third_party/sigsegv/sigsegv.BUILD
vendored
4
bazel/third_party/sigsegv/sigsegv.BUILD
vendored
@ -20,8 +20,8 @@ configure_make(
|
|||||||
"@platforms//os:linux": ["--disable-stackvma"],
|
"@platforms//os:linux": ["--disable-stackvma"],
|
||||||
"//conditions:default": [],
|
"//conditions:default": [],
|
||||||
}) + select({
|
}) + select({
|
||||||
# Native compilation on linux-arm64 isn't supported.
|
"@//:linux_arm64": ["--host=aarch64-linux-musl"],
|
||||||
"@//:linux_arm64": ["--host=aarch64-linux-gnu"],
|
"@//:linux_x86_64": ["--host=x86_64-linux-musl"],
|
||||||
"//conditions:default": [],
|
"//conditions:default": [],
|
||||||
}),
|
}),
|
||||||
lib_source = ":all",
|
lib_source = ":all",
|
||||||
|
4
bazel/third_party/uv/uv.BUILD
vendored
4
bazel/third_party/uv/uv.BUILD
vendored
@ -17,8 +17,8 @@ configure_make(
|
|||||||
configure_options = [
|
configure_options = [
|
||||||
"--disable-shared",
|
"--disable-shared",
|
||||||
] + select({
|
] + select({
|
||||||
# Native compilation on linux-arm64 isn't supported.
|
"@//:linux_arm64": ["--host=aarch64-linux-musl"],
|
||||||
"@//:linux_arm64": ["--host=aarch64-linux-gnu"],
|
"@//:linux_x86_64": ["--host=x86_64-linux-musl"],
|
||||||
"//conditions:default": [],
|
"//conditions:default": [],
|
||||||
}),
|
}),
|
||||||
lib_source = ":all",
|
lib_source = ":all",
|
||||||
|
@ -39,30 +39,34 @@ alias(
|
|||||||
)
|
)
|
||||||
|
|
||||||
#
|
#
|
||||||
# aarch64_linux_gnu_gcc-linux-x86_64
|
# gcc-linux-aarch64
|
||||||
#
|
#
|
||||||
|
|
||||||
# Toolchain identifier.
|
# Toolchain identifier.
|
||||||
_aarch64_linux_gnu_gcc = "toolchain-aarch64_linux_gnu_gcc-linux-x86_64"
|
_arm64_gcc = "toolchain-gcc-linux-arm64"
|
||||||
|
|
||||||
cc_toolchain_config(
|
cc_toolchain_config(
|
||||||
name = "aarch64_linux_gnu_gcc-linux-x86_64-config",
|
name = "gcc-linux-arm64-config",
|
||||||
ar = "/usr/bin/aarch64-linux-gnu-ar",
|
ar = "/usr/local/aarch64-linux-musl/bin/aarch64-linux-musl-ar",
|
||||||
cc = "/usr/bin/aarch64-linux-gnu-gcc",
|
cc = "/usr/local/aarch64-linux-musl/bin/aarch64-linux-musl-gcc",
|
||||||
compiler = "aarch64-linux-gnu-gcc",
|
cc_flags = [
|
||||||
compiler_version = "//:aarch64_linux_gnu_gcc_version",
|
"-static",
|
||||||
ld = "/usr/bin/aarch64-linux-gnu-ld",
|
"--sysroot=/usr/local/aarch64-linux-musl",
|
||||||
|
],
|
||||||
|
compiler = "aarch64-linux-musl-gcc",
|
||||||
|
compiler_version = "//:gcc_version",
|
||||||
|
ld = "/usr/local/aarch64-linux-musl/bin/aarch64-linux-musl-ld",
|
||||||
|
ld_flags = ["--sysroot=/usr/local/aarch64-linux-musl"],
|
||||||
sys_includes = [
|
sys_includes = [
|
||||||
"/usr/aarch64-linux-gnu/include",
|
"/usr/local/aarch64-linux-musl/aarch64-linux-musl/include",
|
||||||
"/usr/lib/gcc/aarch64-linux-gnu/{compiler_version}/include",
|
"/usr/local/aarch64-linux-musl/lib/gcc/aarch64-linux-musl/{compiler_version}/include",
|
||||||
"/usr/lib/gcc/aarch64-linux-gnu/{compiler_version}/include-fixed",
|
|
||||||
],
|
],
|
||||||
target_cpu = "arm64",
|
target_cpu = "arm64",
|
||||||
toolchain_identifier = _aarch64_linux_gnu_gcc,
|
toolchain_identifier = _arm64_gcc,
|
||||||
)
|
)
|
||||||
|
|
||||||
cc_toolchain(
|
cc_toolchain(
|
||||||
name = "aarch64_linux_gnu_gcc-linux-x86_64",
|
name = "gcc-linux-arm64",
|
||||||
all_files = ":empty",
|
all_files = ":empty",
|
||||||
compiler_files = ":empty",
|
compiler_files = ":empty",
|
||||||
dwp_files = ":empty",
|
dwp_files = ":empty",
|
||||||
@ -70,12 +74,12 @@ cc_toolchain(
|
|||||||
objcopy_files = ":empty",
|
objcopy_files = ":empty",
|
||||||
strip_files = ":empty",
|
strip_files = ":empty",
|
||||||
supports_param_files = 0,
|
supports_param_files = 0,
|
||||||
toolchain_config = ":aarch64_linux_gnu_gcc-linux-x86_64-config",
|
toolchain_config = ":gcc-linux-arm64-config",
|
||||||
toolchain_identifier = _aarch64_linux_gnu_gcc,
|
toolchain_identifier = _arm64_gcc,
|
||||||
)
|
)
|
||||||
|
|
||||||
toolchain(
|
toolchain(
|
||||||
name = "aarch64_linux_gnu_gcc-linux-x86_64-toolchain",
|
name = "gcc-linux-arm64-toolchain",
|
||||||
exec_compatible_with = [
|
exec_compatible_with = [
|
||||||
"@platforms//os:linux",
|
"@platforms//os:linux",
|
||||||
"@platforms//cpu:x86_64",
|
"@platforms//cpu:x86_64",
|
||||||
@ -84,56 +88,7 @@ toolchain(
|
|||||||
"@platforms//os:linux",
|
"@platforms//os:linux",
|
||||||
"@platforms//cpu:arm64",
|
"@platforms//cpu:arm64",
|
||||||
],
|
],
|
||||||
toolchain = ":aarch64_linux_gnu_gcc-linux-x86_64",
|
toolchain = ":gcc-linux-arm64",
|
||||||
toolchain_type = ":toolchain_type",
|
|
||||||
)
|
|
||||||
|
|
||||||
#
|
|
||||||
# clang-linux-x86_64
|
|
||||||
#
|
|
||||||
|
|
||||||
# Toolchain identifier.
|
|
||||||
_x86_64_clang = "toolchain-clang-linux-x86_64"
|
|
||||||
|
|
||||||
cc_toolchain_config(
|
|
||||||
name = "clang-linux-x86_64-config",
|
|
||||||
ar = "/usr/bin/ar",
|
|
||||||
cc = "/usr/bin/clang",
|
|
||||||
compiler = "clang",
|
|
||||||
compiler_version = "//:clang_version",
|
|
||||||
ld = "/usr/bin/ld",
|
|
||||||
sys_includes = [
|
|
||||||
"/usr/lib/clang/{compiler_version}",
|
|
||||||
"/usr/include",
|
|
||||||
],
|
|
||||||
target_cpu = "x86_64",
|
|
||||||
toolchain_identifier = _x86_64_clang,
|
|
||||||
)
|
|
||||||
|
|
||||||
cc_toolchain(
|
|
||||||
name = "clang-linux-x86_64",
|
|
||||||
all_files = ":empty",
|
|
||||||
compiler_files = ":empty",
|
|
||||||
dwp_files = ":empty",
|
|
||||||
linker_files = ":empty",
|
|
||||||
objcopy_files = ":empty",
|
|
||||||
strip_files = ":empty",
|
|
||||||
supports_param_files = 0,
|
|
||||||
toolchain_config = ":clang-linux-x86_64-config",
|
|
||||||
toolchain_identifier = _x86_64_clang,
|
|
||||||
)
|
|
||||||
|
|
||||||
toolchain(
|
|
||||||
name = "clang-linux-x86_64-toolchain",
|
|
||||||
exec_compatible_with = [
|
|
||||||
"@platforms//os:linux",
|
|
||||||
"@platforms//cpu:x86_64",
|
|
||||||
],
|
|
||||||
target_compatible_with = [
|
|
||||||
"@platforms//os:linux",
|
|
||||||
"@platforms//cpu:x86_64",
|
|
||||||
],
|
|
||||||
toolchain = ":clang-linux-x86_64",
|
|
||||||
toolchain_type = ":toolchain_type",
|
toolchain_type = ":toolchain_type",
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -146,15 +101,19 @@ _x86_64_gcc = "toolchain-gcc-linux-x86_64"
|
|||||||
|
|
||||||
cc_toolchain_config(
|
cc_toolchain_config(
|
||||||
name = "gcc-linux-x86_64-config",
|
name = "gcc-linux-x86_64-config",
|
||||||
ar = "/usr/bin/ar",
|
ar = "/usr/local/x86_64-linux-musl/bin/x86_64-linux-musl-ar",
|
||||||
cc = "/usr/bin/gcc",
|
cc = "/usr/local/x86_64-linux-musl/bin/x86_64-linux-musl-gcc",
|
||||||
compiler = "gcc",
|
cc_flags = [
|
||||||
|
"-static",
|
||||||
|
"--sysroot=/usr/local/x86_64-linux-musl",
|
||||||
|
],
|
||||||
|
compiler = "x86_64-linux-musl-gcc",
|
||||||
compiler_version = "//:gcc_version",
|
compiler_version = "//:gcc_version",
|
||||||
ld = "/usr/bin/ld",
|
ld = "/usr/local/x86_64-linux-musl/bin/x86_64-linux-musl-ld",
|
||||||
|
ld_flags = ["--sysroot=/usr/local/x86_64-linux-musl"],
|
||||||
sys_includes = [
|
sys_includes = [
|
||||||
"/usr/lib/gcc/x86_64-pc-linux-gnu/{compiler_version}/include",
|
"/usr/local/x86_64-linux-musl/x86_64-linux-musl/include",
|
||||||
"/usr/lib/gcc/x86_64-pc-linux-gnu/{compiler_version}/include-fixed",
|
"/usr/local/x86_64-linux-musl/lib/gcc/x86_64-linux-musl/{compiler_version}/include",
|
||||||
"/usr/include",
|
|
||||||
],
|
],
|
||||||
target_cpu = "x86_64",
|
target_cpu = "x86_64",
|
||||||
toolchain_identifier = _x86_64_gcc,
|
toolchain_identifier = _x86_64_gcc,
|
||||||
@ -290,7 +249,6 @@ cc_toolchain(
|
|||||||
toolchain(
|
toolchain(
|
||||||
name = "clang-macos-x86_64-toolchain",
|
name = "clang-macos-x86_64-toolchain",
|
||||||
exec_compatible_with = [
|
exec_compatible_with = [
|
||||||
"//:clang",
|
|
||||||
"@platforms//os:macos",
|
"@platforms//os:macos",
|
||||||
"@platforms//cpu:x86_64",
|
"@platforms//cpu:x86_64",
|
||||||
],
|
],
|
||||||
@ -301,3 +259,80 @@ toolchain(
|
|||||||
toolchain = ":clang-macos-x86_64",
|
toolchain = ":clang-macos-x86_64",
|
||||||
toolchain_type = ":toolchain_type",
|
toolchain_type = ":toolchain_type",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
#
|
||||||
|
# BOOTSTRAPPING
|
||||||
|
#
|
||||||
|
|
||||||
|
# We can't build some artifcacts, like musl libc and its toolchain, in Bazel
|
||||||
|
# itself (i.e. by adding a remote repository to `WORKSPACE.bazel` and a
|
||||||
|
# corresponding `BUILD` file in `bazel/third_party/<dependency>`) because doing
|
||||||
|
# so introduces a circular dependency during Bazel C/C++ toolchain resolution.
|
||||||
|
|
||||||
|
# The prefix for installed external toolchains.
|
||||||
|
_install_prefix = "/usr/local"
|
||||||
|
|
||||||
|
# musl-cross-make builds musl-libc-compatible gcc toolchains from source.
|
||||||
|
_musl_cross_make_version = "fe915821b652a7fa37b34a596f47d8e20bc72338"
|
||||||
|
|
||||||
|
_musl_cross_make_archive = "https://github.com/richfelker/musl-cross-make/archive/{}.tar.gz".format(_musl_cross_make_version)
|
||||||
|
|
||||||
|
genrule(
|
||||||
|
name = "install-aarch64-linux-musl-gcc",
|
||||||
|
outs = ["install-aarch64-linux-musl-gcc.sh"],
|
||||||
|
cmd = """
|
||||||
|
echo 'aarch64_linux_musl_install={}/aarch64-linux-musl' > $@
|
||||||
|
echo 'if [ ! -d $$aarch64_linux_musl_install ]; then' >> $@
|
||||||
|
echo ' wget -c {}' >> $@
|
||||||
|
echo ' tar -xf {}.tar.gz' >> $@
|
||||||
|
echo ' archive=musl-cross-make-{}' >> $@
|
||||||
|
echo ' echo OUTPUT=$$aarch64_linux_musl_install > $$archive/config.mak' >> $@
|
||||||
|
echo ' TARGET=aarch64-linux-musl make -C$$archive -j`nproc`' >> $@
|
||||||
|
echo ' sudo TARGET=aarch64-linux-musl make -C$$archive -j`nproc` install' >> $@
|
||||||
|
echo 'fi' >> $@
|
||||||
|
""".format(
|
||||||
|
_install_prefix,
|
||||||
|
_musl_cross_make_archive,
|
||||||
|
_musl_cross_make_version,
|
||||||
|
_musl_cross_make_version,
|
||||||
|
),
|
||||||
|
exec_compatible_with = ["@platforms//os:linux"],
|
||||||
|
visibility = ["//visibility:private"],
|
||||||
|
)
|
||||||
|
|
||||||
|
sh_binary(
|
||||||
|
name = "aarch64-linux-musl-gcc",
|
||||||
|
srcs = ["install-aarch64-linux-musl-gcc"],
|
||||||
|
exec_compatible_with = ["@platforms//os:linux"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
genrule(
|
||||||
|
name = "install-x86_64-linux-musl-gcc",
|
||||||
|
outs = ["install-x86_64-linux-musl-gcc.sh"],
|
||||||
|
cmd = """
|
||||||
|
echo 'x86_64_linux_musl_install={}/x86_64-linux-musl' > $@
|
||||||
|
echo 'if [ ! -d $$x86_64_linux_musl_install ]; then' >> $@
|
||||||
|
echo ' wget -c {}' >> $@
|
||||||
|
echo ' tar -xf {}.tar.gz' >> $@
|
||||||
|
echo ' archive=musl-cross-make-{}' >> $@
|
||||||
|
echo ' echo OUTPUT=$$x86_64_linux_musl_install > $$archive/config.mak' >> $@
|
||||||
|
echo ' TARGET=x86_64-linux-musl make -C$$archive -j`nproc`' >> $@
|
||||||
|
echo ' sudo TARGET=x86_64-linux-musl make -C$$archive -j`nproc` install' >> $@
|
||||||
|
echo 'fi' >> $@
|
||||||
|
""".format(
|
||||||
|
_install_prefix,
|
||||||
|
_musl_cross_make_archive,
|
||||||
|
_musl_cross_make_version,
|
||||||
|
_musl_cross_make_version,
|
||||||
|
),
|
||||||
|
exec_compatible_with = ["@platforms//os:linux"],
|
||||||
|
visibility = ["//visibility:private"],
|
||||||
|
)
|
||||||
|
|
||||||
|
sh_binary(
|
||||||
|
name = "x86_64-linux-musl-gcc",
|
||||||
|
srcs = ["install-x86_64-linux-musl-gcc"],
|
||||||
|
exec_compatible_with = ["@platforms//os:linux"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
@ -10,7 +10,7 @@ load(
|
|||||||
)
|
)
|
||||||
|
|
||||||
def _cc_toolchain_config_impl(ctx):
|
def _cc_toolchain_config_impl(ctx):
|
||||||
ar_flags_feature = feature(
|
ar_flags = feature(
|
||||||
name = "archiver_flags",
|
name = "archiver_flags",
|
||||||
flag_sets = [
|
flag_sets = [
|
||||||
flag_set(
|
flag_set(
|
||||||
@ -51,6 +51,38 @@ def _cc_toolchain_config_impl(ctx):
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
features = [ar_flags]
|
||||||
|
|
||||||
|
if len(ctx.attr.cc_flags) > 0:
|
||||||
|
cc_flags = feature(
|
||||||
|
name = "cc_flags",
|
||||||
|
enabled = True,
|
||||||
|
flag_sets = [
|
||||||
|
flag_set(
|
||||||
|
actions = [ACTION_NAMES.c_compile],
|
||||||
|
flag_groups = [flag_group(flags = ctx.attr.cc_flags)],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
features.append(cc_flags)
|
||||||
|
|
||||||
|
|
||||||
|
if len(ctx.attr.ld_flags) > 0:
|
||||||
|
ld_flags = feature(
|
||||||
|
name = "ld_flags",
|
||||||
|
enabled = True,
|
||||||
|
flag_sets = [
|
||||||
|
flag_set(
|
||||||
|
actions = [
|
||||||
|
ACTION_NAMES.cpp_link_dynamic_library,
|
||||||
|
ACTION_NAMES.cpp_link_executable,
|
||||||
|
ACTION_NAMES.cpp_link_nodeps_dynamic_library,
|
||||||
|
],
|
||||||
|
flag_groups = [flag_group(flags = ctx.attr.ld_flags)],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
features.append(ld_flags)
|
||||||
|
|
||||||
# See
|
# See
|
||||||
# https://bazel.build/rules/lib/cc_common#create_cc_toolchain_config_info.
|
# https://bazel.build/rules/lib/cc_common#create_cc_toolchain_config_info.
|
||||||
@ -62,7 +94,7 @@ def _cc_toolchain_config_impl(ctx):
|
|||||||
path.format(compiler_version = ctx.attr.compiler_version[BuildSettingInfo].value)
|
path.format(compiler_version = ctx.attr.compiler_version[BuildSettingInfo].value)
|
||||||
for path in ctx.attr.sys_includes
|
for path in ctx.attr.sys_includes
|
||||||
],
|
],
|
||||||
features = [ar_flags_feature],
|
features = features,
|
||||||
toolchain_identifier = ctx.attr.toolchain_identifier,
|
toolchain_identifier = ctx.attr.toolchain_identifier,
|
||||||
target_system_name = ctx.attr.target_system_name,
|
target_system_name = ctx.attr.target_system_name,
|
||||||
target_cpu = ctx.attr.target_cpu,
|
target_cpu = ctx.attr.target_cpu,
|
||||||
@ -121,8 +153,10 @@ cc_toolchain_config = rule(
|
|||||||
"abi_libc_version": attr.string(default = "unknown"),
|
"abi_libc_version": attr.string(default = "unknown"),
|
||||||
"abi_version": attr.string(default = "unknown"),
|
"abi_version": attr.string(default = "unknown"),
|
||||||
"ar_flags": attr.string(default = "rcsD"),
|
"ar_flags": attr.string(default = "rcsD"),
|
||||||
|
"cc_flags": attr.string_list(default = []),
|
||||||
"cpp": attr.string(default = "/bin/false"),
|
"cpp": attr.string(default = "/bin/false"),
|
||||||
"gcov": attr.string(default = "/bin/false"),
|
"gcov": attr.string(default = "/bin/false"),
|
||||||
|
"ld_flags": attr.string_list(default = []),
|
||||||
"nm": attr.string(default = "/bin/false"),
|
"nm": attr.string(default = "/bin/false"),
|
||||||
"objdump": attr.string(default = "/bin/false"),
|
"objdump": attr.string(default = "/bin/false"),
|
||||||
"strip": attr.string(default = "/bin/false"),
|
"strip": attr.string(default = "/bin/false"),
|
||||||
|
@ -39,7 +39,10 @@ cc_test(
|
|||||||
name = "tests",
|
name = "tests",
|
||||||
timeout = "short",
|
timeout = "short",
|
||||||
srcs = ["tests.c"],
|
srcs = ["tests.c"],
|
||||||
linkstatic = True,
|
features = select({
|
||||||
|
"@platforms//os:linux": ["fully_static_link"],
|
||||||
|
"//conditions:default": [],
|
||||||
|
}),
|
||||||
visibility = ["//visibility:private"],
|
visibility = ["//visibility:private"],
|
||||||
deps = [":ent"],
|
deps = [":ent"],
|
||||||
)
|
)
|
||||||
|
@ -57,6 +57,10 @@ cc_test(
|
|||||||
name = "hashtable_tests",
|
name = "hashtable_tests",
|
||||||
timeout = "short",
|
timeout = "short",
|
||||||
srcs = ["hashtable_tests.c"],
|
srcs = ["hashtable_tests.c"],
|
||||||
|
features = select({
|
||||||
|
"@platforms//os:linux": ["fully_static_link"],
|
||||||
|
"//conditions:default": [],
|
||||||
|
}),
|
||||||
visibility = ["//visibility:private"],
|
visibility = ["//visibility:private"],
|
||||||
deps = [":noun"],
|
deps = [":noun"],
|
||||||
)
|
)
|
||||||
@ -65,6 +69,10 @@ cc_test(
|
|||||||
name = "jets_tests",
|
name = "jets_tests",
|
||||||
timeout = "short",
|
timeout = "short",
|
||||||
srcs = ["jets_tests.c"],
|
srcs = ["jets_tests.c"],
|
||||||
|
features = select({
|
||||||
|
"@platforms//os:linux": ["fully_static_link"],
|
||||||
|
"//conditions:default": [],
|
||||||
|
}),
|
||||||
visibility = ["//visibility:private"],
|
visibility = ["//visibility:private"],
|
||||||
deps = [":noun"],
|
deps = [":noun"],
|
||||||
)
|
)
|
||||||
@ -73,6 +81,10 @@ cc_test(
|
|||||||
name = "nock_tests",
|
name = "nock_tests",
|
||||||
timeout = "short",
|
timeout = "short",
|
||||||
srcs = ["nock_tests.c"],
|
srcs = ["nock_tests.c"],
|
||||||
|
features = select({
|
||||||
|
"@platforms//os:linux": ["fully_static_link"],
|
||||||
|
"//conditions:default": [],
|
||||||
|
}),
|
||||||
visibility = ["//visibility:private"],
|
visibility = ["//visibility:private"],
|
||||||
deps = [":noun"],
|
deps = [":noun"],
|
||||||
)
|
)
|
||||||
@ -81,6 +93,10 @@ cc_test(
|
|||||||
name = "retrieve_tests",
|
name = "retrieve_tests",
|
||||||
timeout = "short",
|
timeout = "short",
|
||||||
srcs = ["retrieve_tests.c"],
|
srcs = ["retrieve_tests.c"],
|
||||||
|
features = select({
|
||||||
|
"@platforms//os:linux": ["fully_static_link"],
|
||||||
|
"//conditions:default": [],
|
||||||
|
}),
|
||||||
visibility = ["//visibility:private"],
|
visibility = ["//visibility:private"],
|
||||||
deps = [":noun"],
|
deps = [":noun"],
|
||||||
)
|
)
|
||||||
@ -89,6 +105,10 @@ cc_test(
|
|||||||
name = "serial_tests",
|
name = "serial_tests",
|
||||||
timeout = "short",
|
timeout = "short",
|
||||||
srcs = ["serial_tests.c"],
|
srcs = ["serial_tests.c"],
|
||||||
|
features = select({
|
||||||
|
"@platforms//os:linux": ["fully_static_link"],
|
||||||
|
"//conditions:default": [],
|
||||||
|
}),
|
||||||
visibility = ["//visibility:private"],
|
visibility = ["//visibility:private"],
|
||||||
deps = [":noun"],
|
deps = [":noun"],
|
||||||
)
|
)
|
||||||
|
@ -28,7 +28,10 @@ cc_test(
|
|||||||
name = "tests",
|
name = "tests",
|
||||||
timeout = "short",
|
timeout = "short",
|
||||||
srcs = ["tests.c"],
|
srcs = ["tests.c"],
|
||||||
linkstatic = True,
|
features = select({
|
||||||
|
"@platforms//os:linux": ["fully_static_link"],
|
||||||
|
"//conditions:default": [],
|
||||||
|
}),
|
||||||
visibility = ["//visibility:private"],
|
visibility = ["//visibility:private"],
|
||||||
deps = [":ur"],
|
deps = [":ur"],
|
||||||
)
|
)
|
||||||
|
@ -177,7 +177,10 @@ cc_binary(
|
|||||||
":pace",
|
":pace",
|
||||||
":version",
|
":version",
|
||||||
],
|
],
|
||||||
linkstatic = True,
|
features = select({
|
||||||
|
"@platforms//os:linux": ["fully_static_link"],
|
||||||
|
"//conditions:default": [],
|
||||||
|
}),
|
||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
deps = [
|
deps = [
|
||||||
"//pkg/c3",
|
"//pkg/c3",
|
||||||
@ -201,6 +204,10 @@ cc_test(
|
|||||||
name = "ames_tests",
|
name = "ames_tests",
|
||||||
timeout = "short",
|
timeout = "short",
|
||||||
srcs = ["ames_tests.c"],
|
srcs = ["ames_tests.c"],
|
||||||
|
features = select({
|
||||||
|
"@platforms//os:linux": ["fully_static_link"],
|
||||||
|
"//conditions:default": [],
|
||||||
|
}),
|
||||||
visibility = ["//visibility:private"],
|
visibility = ["//visibility:private"],
|
||||||
deps = [":vere"],
|
deps = [":vere"],
|
||||||
)
|
)
|
||||||
@ -209,6 +216,10 @@ cc_test(
|
|||||||
name = "newt_tests",
|
name = "newt_tests",
|
||||||
timeout = "short",
|
timeout = "short",
|
||||||
srcs = ["newt_tests.c"],
|
srcs = ["newt_tests.c"],
|
||||||
|
features = select({
|
||||||
|
"@platforms//os:linux": ["fully_static_link"],
|
||||||
|
"//conditions:default": [],
|
||||||
|
}),
|
||||||
visibility = ["//visibility:private"],
|
visibility = ["//visibility:private"],
|
||||||
deps = [":vere"],
|
deps = [":vere"],
|
||||||
)
|
)
|
||||||
@ -217,6 +228,10 @@ cc_test(
|
|||||||
name = "noun_tests",
|
name = "noun_tests",
|
||||||
timeout = "short",
|
timeout = "short",
|
||||||
srcs = ["noun_tests.c"],
|
srcs = ["noun_tests.c"],
|
||||||
|
features = select({
|
||||||
|
"@platforms//os:linux": ["fully_static_link"],
|
||||||
|
"//conditions:default": [],
|
||||||
|
}),
|
||||||
visibility = ["//visibility:private"],
|
visibility = ["//visibility:private"],
|
||||||
deps = [":vere"],
|
deps = [":vere"],
|
||||||
)
|
)
|
||||||
@ -225,6 +240,10 @@ cc_test(
|
|||||||
name = "unix_tests",
|
name = "unix_tests",
|
||||||
timeout = "short",
|
timeout = "short",
|
||||||
srcs = ["unix_tests.c"],
|
srcs = ["unix_tests.c"],
|
||||||
|
features = select({
|
||||||
|
"@platforms//os:linux": ["fully_static_link"],
|
||||||
|
"//conditions:default": [],
|
||||||
|
}),
|
||||||
visibility = ["//visibility:private"],
|
visibility = ["//visibility:private"],
|
||||||
deps = [":vere"],
|
deps = [":vere"],
|
||||||
)
|
)
|
||||||
@ -233,6 +252,10 @@ cc_test(
|
|||||||
name = "benchmarks",
|
name = "benchmarks",
|
||||||
timeout = "short",
|
timeout = "short",
|
||||||
srcs = ["benchmarks.c"],
|
srcs = ["benchmarks.c"],
|
||||||
|
features = select({
|
||||||
|
"@platforms//os:linux": ["fully_static_link"],
|
||||||
|
"//conditions:default": [],
|
||||||
|
}),
|
||||||
visibility = ["//visibility:private"],
|
visibility = ["//visibility:private"],
|
||||||
deps = [
|
deps = [
|
||||||
":vere",
|
":vere",
|
||||||
|
Loading…
Reference in New Issue
Block a user