diff --git a/.bazelrc b/.bazelrc index ea706d87c9..8aaeb9f3ad 100644 --- a/.bazelrc +++ b/.bazelrc @@ -9,5 +9,10 @@ build --action_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 # https://github.com/bazelbuild/bazel/issues/7260. build --incompatible_enable_cc_toolchain_resolution +# Add aliases for compiler version build settings. +build --flag_alias=aarch64_linux_gnu_gcc_version=//:aarch64_linux_gnu_gcc_version +build --flag_alias=clang_version=//:clang_version +build --flag_alias=gcc_version=//:gcc_version + # Any personal configuration should go in .user.bazelrc. try-import %workspace%/.user.bazelrc diff --git a/BUILD.bazel b/BUILD.bazel index ffcb60391c..d1b31e2332 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,9 +1,11 @@ +load("//bazel:common_settings.bzl", "string_flag") + # # OS-CPU CONFIG SETTINGS # config_setting( - name = "linux-arm64", + name = "linux_arm64", constraint_values = [ "@platforms//os:linux", "@platforms//cpu:arm64", @@ -11,7 +13,7 @@ config_setting( ) config_setting( - name = "linux-x86_64", + name = "linux_x86_64", constraint_values = [ "@platforms//os:linux", "@platforms//cpu:x86_64", @@ -19,7 +21,7 @@ config_setting( ) config_setting( - name = "macos-arm64", + name = "macos_arm64", constraint_values = [ "@platforms//os:macos", "@platforms//cpu:arm64", @@ -27,7 +29,7 @@ config_setting( ) config_setting( - name = "macos-x86_64", + name = "macos_x86_64", constraint_values = [ "@platforms//os:macos", "@platforms//cpu:x86_64", @@ -35,7 +37,7 @@ config_setting( ) config_setting( - name = "openbsd-x86_64", + name = "openbsd_x86_64", constraint_values = [ "@platforms//os:openbsd", "@platforms//cpu:x86_64", @@ -43,7 +45,7 @@ config_setting( ) config_setting( - name = "windows-x86_64", + name = "windows_x86_64", constraint_values = [ "@platforms//os:windows", "@platforms//cpu:x86_64", @@ -51,27 +53,90 @@ config_setting( ) # -# COMPILER CONSTRAINT SETTINGS +# 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. +string_flag( + name = "clang_version", + build_setting_default = "14.0.6", + visibility = ["//visibility:public"], +) + +# Version flag for gcc. +string_flag( + name = "gcc_version", + build_setting_default = "12.2.0", + visibility = ["//visibility:public"], +) + # # PLATFORMS # +# A platform takes one of two formats: `--` or `-` +# if the compiler is unspecified. + +# Linux arm64 platform with unspecified compiler. +platform( + name = "linux-arm64", + constraint_values = [ + "@platforms//os:linux", + "@platforms//cpu:arm64", + ], +) + +# Linux x86_64 platform with unspecified compiler. +platform( + name = "linux-x86_64", + constraint_values = [ + "@platforms//os:linux", + "@platforms//cpu:x86_64", + ], +) + +# 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 = [ @@ -82,6 +147,7 @@ platform( visibility = ["//visibility:public"], ) +# Linux x86_64 platform with gcc. platform( name = "gcc-linux-x86_64", constraint_values = [ diff --git a/README.md b/README.md index 1f9ef9e1c1..f6bf007987 100644 --- a/README.md +++ b/README.md @@ -31,31 +31,63 @@ defined in its own package: ## Build -We use [`bazel`][bazel] to build Urbit's runtime. We support the following -platforms: +We use [`bazel`][bazel] to build Urbit's runtime, which is packaged as a single +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: -- `darwin-arm64` (macOS running Apple Silicon) -- `darwin-x86_64` (macOS running Intel silicon) -- `linux-arm64` -- `linux-x86_64` -- `openbsd-x86_64` -- `mingw-x86_64` +-------------------------------------------------------------------------------- + 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` -To build the `urbit` binary, the primary artifact of this repository, ensure -that you're on a supported platform and that you have an up-to-date version of -[`bazel`][bazel], and then run: +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 :urbit +$ bazel build --_version="" \ + --host_platform=//: \ + --platforms=//: :urbit ``` -The build will take a while since `bazel` has to download and build from source -all of `urbit`'s third-party dependencies. +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 `--_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=//:' >> .user.bazelrc +$ echo 'build --platforms=//:' >> .user.bazelrc +$ bazel build :urbit +``` To run the just-built `urbit` binary, run: ```console -$ bazel-bin/pkg/vere/urbit ... +$ bazel-bin/pkg/vere/urbit ``` Or, to save yourself a few keystrokes, create a symlink to the `urbit` binary in @@ -63,9 +95,13 @@ the root of the repository: ```console $ ln -s bazel-bin/pkg/vere/urbit urbit -$ ./urbit ... +$ ./urbit ``` +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 diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel index 45c41f64e5..f1bb027023 100644 --- a/WORKSPACE.bazel +++ b/WORKSPACE.bazel @@ -73,13 +73,20 @@ versioned_http_archive( # Use the toolchains we've configured. register_toolchains( + "//bazel/toolchain:aarch64_linux_gnu_gcc-linux-x86_64-toolchain", "//bazel/toolchain:clang-linux-x86_64-toolchain", "//bazel/toolchain:gcc-linux-x86_64-toolchain", ) load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies") -rules_foreign_cc_dependencies() +# See +# https://bazelbuild.github.io/rules_foreign_cc/0.9.0/flatten.html#rules_foreign_cc_dependencies. +rules_foreign_cc_dependencies( + register_built_tools = False, + register_default_tools = False, + register_preinstalled_tools = True, +) # # THIRD PARTY DEPENDENCIES @@ -141,6 +148,8 @@ versioned_http_archive( versioned_http_archive( name = "h2o", build_file = "//bazel/third_party/h2o:h2o.BUILD", + patch_args = ["-p1"], + patches = ["//bazel/third_party/h2o:{version}.patch"], sha256 = "f8cbc1b530d85ff098f6efc2c3fdbc5e29baffb30614caac59d5c710f7bda201", strip_prefix = "h2o-{version}", url = "https://github.com/h2o/h2o/archive/refs/tags/v{version}.tar.gz", @@ -244,6 +253,15 @@ versioned_http_archive( version = "5c06db33fc1e2130f67c045327b0ec949032df1d", ) +versioned_http_archive( + name = "sse2neon", + build_file = "//bazel/third_party/sse2neon:sse2neon.BUILD", + sha256 = "4001e2dfb14fcf3831211581ed83bcc83cf6a3a69f638dcbaa899044a351bb2a", + strip_prefix = "sse2neon-{version}", + url = "https://github.com/DLTcollab/sse2neon/archive/refs/tags/v{version}.tar.gz", + version = "1.5.1", +) + versioned_http_archive( name = "uv", build_file = "//bazel/third_party/uv:uv.BUILD", diff --git a/bazel/common_settings.bzl b/bazel/common_settings.bzl new file mode 100644 index 0000000000..945447d3c5 --- /dev/null +++ b/bazel/common_settings.bzl @@ -0,0 +1,12 @@ +# For more, see https://bazel.build/extending/config and +# https://github.com/bazelbuild/bazel-skylib/blob/main/rules/common_settings.bzl. +load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo") + +def _impl(ctx): + return BuildSettingInfo(value = ctx.build_setting_value) + +string_flag = rule( + implementation = _impl, + build_setting = config.string(flag = True), + doc = "A string-typed build setting that can be set on the command line", +) diff --git a/bazel/third_party/curl/curl.BUILD b/bazel/third_party/curl/curl.BUILD index 234eb4079e..aa07d6f24e 100644 --- a/bazel/third_party/curl/curl.BUILD +++ b/bazel/third_party/curl/curl.BUILD @@ -47,12 +47,15 @@ configure_make( "--without-librtmp", "--without-nghttp2", "--without-ngtcp2", - "--without-ssl", "--without-zlib", "--without-zstd", - ], + ] + select({ + # Native compilation on linux-arm64 isn't supported. + "@//:linux_arm64": ["--host=aarch64-linux-gnu"], + "//conditions:default": [], + }), env = { - "URBIT_RUNTIME_OPENSSL": "$(GENDIR)/external/openssl/openssl", + "URBIT_RUNTIME_OPENSSL": "$$PWD/$(GENDIR)/external/openssl/openssl", }, lib_source = ":all", out_static_libs = ["libcurl.a"], diff --git a/bazel/third_party/gmp/gmp.BUILD b/bazel/third_party/gmp/gmp.BUILD index 549912447d..1ae0327b73 100644 --- a/bazel/third_party/gmp/gmp.BUILD +++ b/bazel/third_party/gmp/gmp.BUILD @@ -9,7 +9,13 @@ filegroup( configure_make( name = "gmp", args = ["--jobs=`nproc`"], - configure_options = ["--disable-shared"], + configure_options = [ + "--disable-shared", + ] + select({ + # Native compilation on linux-arm64 isn't supported. + "@//:linux_arm64": ["--host=aarch64-linux-gnu"], + "//conditions:default": [], + }), lib_source = ":all", out_static_libs = ["libgmp.a"], visibility = ["//visibility:public"], diff --git a/bazel/third_party/h2o/2.2.6.patch b/bazel/third_party/h2o/2.2.6.patch new file mode 100644 index 0000000000..e6564124a2 --- /dev/null +++ b/bazel/third_party/h2o/2.2.6.patch @@ -0,0 +1,47 @@ +diff --git a/deps/klib/ksw.c b/deps/klib/ksw.c +index 742fec90b..9a11a21bd 100644 +--- a/deps/klib/ksw.c ++++ b/deps/klib/ksw.c +@@ -25,7 +25,11 @@ + + #include + #include ++#if defined(URBIT_RUNTIME_ARCH_ARM64) ++#include "sse2neon.h" ++#else + #include ++#endif + #include "ksw.h" + + #ifdef __GNUC__ +diff --git a/deps/klib/test/kbit_test.c b/deps/klib/test/kbit_test.c +index 3ae3bd309..7db05a186 100644 +--- a/deps/klib/test/kbit_test.c ++++ b/deps/klib/test/kbit_test.c +@@ -1,7 +1,11 @@ + #include + #include + #include ++#if defined(URBIT_RUNTIME_ARCH_ARM64) ++#include "sse2neon.h" ++#else + #include ++#endif + #include "kbit.h" + + // from bowtie-0.9.8.1 +diff --git a/deps/picohttpparser/picohttpparser.c b/deps/picohttpparser/picohttpparser.c +index a707070d1..714850f64 100644 +--- a/deps/picohttpparser/picohttpparser.c ++++ b/deps/picohttpparser/picohttpparser.c +@@ -28,7 +28,9 @@ + #include + #include + #ifdef __SSE4_2__ +-#ifdef _MSC_VER ++#if defined(URBIT_RUNTIME_ARCH_ARM64) ++#include "sse2neon.h" ++#elif defined(_MSC_VER) + #include + #else + #include diff --git a/bazel/third_party/h2o/h2o.BUILD b/bazel/third_party/h2o/h2o.BUILD index defbea4cab..491a8540df 100644 --- a/bazel/third_party/h2o/h2o.BUILD +++ b/bazel/third_party/h2o/h2o.BUILD @@ -42,8 +42,18 @@ cc_library( hdrs = glob(["deps/klib/*.h"]), includes = ["deps/klib"], linkstatic = True, + local_defines = select({ + "@platforms//cpu:arm64": ["URBIT_RUNTIME_ARCH_ARM64"], + "//conditions:default": [], + }), visibility = ["//visibility:private"], - deps = ["@curl"], + deps = [ + "@curl", + "@zlib", + ] + select({ + "@platforms//cpu:arm64": ["@sse2neon"], + "//conditions:default": [], + }), ) # See `deps/libgkc` in the `h2o` repo. @@ -132,9 +142,7 @@ cc_library( # See `deps/yoml` in the `h2o` repo. cc_library( name = "yoml", - hdrs = glob( - ["deps/yoml/*.h"], - ), + hdrs = glob(["deps/yoml/*.h"]), includes = ["deps/yoml"], linkstatic = True, visibility = ["//visibility:private"], @@ -305,9 +313,8 @@ cc_library( hdrs = ["include/h2o.h"] + glob( [ "include/h2o/*.h", + "include/h2o/socket/*.h", ], - ) + glob( - ["include/h2o/socket/*.h"], ), copts = [ "-std=c99", diff --git a/bazel/third_party/openssl/openssl.BUILD b/bazel/third_party/openssl/openssl.BUILD index 6d1d07acd0..1e4a9b1db1 100644 --- a/bazel/third_party/openssl/openssl.BUILD +++ b/bazel/third_party/openssl/openssl.BUILD @@ -11,12 +11,22 @@ configure_make( args = ["--jobs=`nproc`"], configure_command = select({ "@platforms//os:windows": "Configure", + "@//:linux_arm64": "Configure", "//conditions:default": "config", }), configure_options = [ "no-shared", ] + select({ "@platforms//os:windows": ["mingw64"], + "@//:linux_arm64": [ + "linux-aarch64", + # Native compilation on linux-arm64 isn't supported. The prefix is + # empty because the configure script detects an absolute path to the + # aarch64-linux-gnu-gcc instead of just the binary name. This is + # presumably because of the Bazel toolchain configuration but is not + # an issue. + "--cross-compile-prefix=", + ], "//conditions:default": [], }), configure_prefix = select({ diff --git a/bazel/third_party/secp256k1/secp256k1.BUILD b/bazel/third_party/secp256k1/secp256k1.BUILD index 25ff78c94c..da554ee4e8 100644 --- a/bazel/third_party/secp256k1/secp256k1.BUILD +++ b/bazel/third_party/secp256k1/secp256k1.BUILD @@ -15,7 +15,11 @@ configure_make( "--enable-module-recovery", "--enable-module-schnorrsig", "--enable-static", - ], + ] + select({ + # Native compilation on linux-arm64 isn't supported. + "@//:linux_arm64": ["--host=aarch64-linux-gnu"], + "//conditions:default": [], + }), lib_source = ":all", out_static_libs = ["libsecp256k1.a"], visibility = ["//visibility:public"], diff --git a/bazel/third_party/sigsegv/sigsegv.BUILD b/bazel/third_party/sigsegv/sigsegv.BUILD index f14887e058..31dfa32346 100644 --- a/bazel/third_party/sigsegv/sigsegv.BUILD +++ b/bazel/third_party/sigsegv/sigsegv.BUILD @@ -16,6 +16,10 @@ configure_make( # slowdowns. "@platforms//os:linux": ["--disable-stackvma"], "//conditions:default": [], + }) + select({ + # Native compilation on linux-arm64 isn't supported. + "@//:linux_arm64": ["--host=aarch64-linux-gnu"], + "//conditions:default": [], }), lib_source = ":all", out_static_libs = ["libsigsegv.a"], diff --git a/bazel/third_party/softfloat/softfloat.BUILD b/bazel/third_party/softfloat/softfloat.BUILD index aa34c9180e..12bed214a4 100644 --- a/bazel/third_party/softfloat/softfloat.BUILD +++ b/bazel/third_party/softfloat/softfloat.BUILD @@ -7,6 +7,280 @@ load("@rules_foreign_cc//foreign_cc:defs.bzl", "make") # repo, was useful in deriving this build file: # http://www.jhauser.us/arithmetic/SoftFloat-3/doc/SoftFloat-source.html +cc_library( + name = "softfloat_linux_arm64", + srcs = [ + # See `OBJS_PRIMITIVES` in `build/Linux-ARM-VFPv2-GCC/Makefile` in the + # `softfloat` repo. + "source/s_compare96M.c", + "source/s_compare128M.c", + "source/s_shortShiftLeft64To96M.c", + "source/s_shortShiftLeftM.c", + "source/s_shiftLeftM.c", + "source/s_shortShiftRightM.c", + "source/s_shortShiftRightJam64.c", + "source/s_shortShiftRightJamM.c", + "source/s_shiftRightJam32.c", + "source/s_shiftRightJam64.c", + "source/s_shiftRightJamM.c", + "source/s_shiftRightM.c", + "source/s_countLeadingZeros8.c", + "source/s_countLeadingZeros16.c", + "source/s_countLeadingZeros32.c", + "source/s_countLeadingZeros64.c", + "source/s_addM.c", + "source/s_addCarryM.c", + "source/s_addComplCarryM.c", + "source/s_negXM.c", + "source/s_sub1XM.c", + "source/s_subM.c", + "source/s_mul64To128M.c", + "source/s_mul128MTo256M.c", + "source/s_approxRecip_1Ks.c", + "source/s_approxRecip32_1.c", + "source/s_approxRecipSqrt_1Ks.c", + "source/s_approxRecipSqrt32_1.c", + "source/s_remStepMBy32.c", + # See `OBJS_SPECIALIZE` in `build/Linux-ARM-VFPv2-GCC/Makefile` in the + # `softfloat` repo. + "source/ARM-VFPv2/softfloat_raiseFlags.c", + "source/ARM-VFPv2/s_f16UIToCommonNaN.c", + "source/ARM-VFPv2/s_commonNaNToF16UI.c", + "source/ARM-VFPv2/s_propagateNaNF16UI.c", + "source/ARM-VFPv2/s_f32UIToCommonNaN.c", + "source/ARM-VFPv2/s_commonNaNToF32UI.c", + "source/ARM-VFPv2/s_propagateNaNF32UI.c", + "source/ARM-VFPv2/s_f64UIToCommonNaN.c", + "source/ARM-VFPv2/s_commonNaNToF64UI.c", + "source/ARM-VFPv2/s_propagateNaNF64UI.c", + "source/ARM-VFPv2/extF80M_isSignalingNaN.c", + "source/ARM-VFPv2/s_extF80MToCommonNaN.c", + "source/ARM-VFPv2/s_commonNaNToExtF80M.c", + "source/ARM-VFPv2/s_propagateNaNExtF80M.c", + "source/ARM-VFPv2/f128M_isSignalingNaN.c", + "source/ARM-VFPv2/s_f128MToCommonNaN.c", + "source/ARM-VFPv2/s_commonNaNToF128M.c", + "source/ARM-VFPv2/s_propagateNaNF128M.c", + # See `OBJS_OTHERS` in `build/Linux-ARM-VFPv2-GCC/Makefile` in the + # `softfloat` repo. + "source/s_roundToUI32.c", + "source/s_roundMToUI64.c", + "source/s_roundToI32.c", + "source/s_roundMToI64.c", + "source/s_normSubnormalF16Sig.c", + "source/s_roundPackToF16.c", + "source/s_normRoundPackToF16.c", + "source/s_addMagsF16.c", + "source/s_subMagsF16.c", + "source/s_mulAddF16.c", + "source/s_normSubnormalF32Sig.c", + "source/s_roundPackToF32.c", + "source/s_normRoundPackToF32.c", + "source/s_addMagsF32.c", + "source/s_subMagsF32.c", + "source/s_mulAddF32.c", + "source/s_normSubnormalF64Sig.c", + "source/s_roundPackToF64.c", + "source/s_normRoundPackToF64.c", + "source/s_addMagsF64.c", + "source/s_subMagsF64.c", + "source/s_mulAddF64.c", + "source/s_tryPropagateNaNExtF80M.c", + "source/s_invalidExtF80M.c", + "source/s_normExtF80SigM.c", + "source/s_roundPackMToExtF80M.c", + "source/s_normRoundPackMToExtF80M.c", + "source/s_addExtF80M.c", + "source/s_compareNonnormExtF80M.c", + "source/s_isNaNF128M.c", + "source/s_tryPropagateNaNF128M.c", + "source/s_invalidF128M.c", + "source/s_shiftNormSigF128M.c", + "source/s_roundPackMToF128M.c", + "source/s_normRoundPackMToF128M.c", + "source/s_addF128M.c", + "source/s_mulAddF128M.c", + "source/softfloat_state.c", + "source/ui32_to_f16.c", + "source/ui32_to_f32.c", + "source/ui32_to_f64.c", + "source/ui32_to_extF80M.c", + "source/ui32_to_f128M.c", + "source/ui64_to_f16.c", + "source/ui64_to_f32.c", + "source/ui64_to_f64.c", + "source/ui64_to_extF80M.c", + "source/ui64_to_f128M.c", + "source/i32_to_f16.c", + "source/i32_to_f32.c", + "source/i32_to_f64.c", + "source/i32_to_extF80M.c", + "source/i32_to_f128M.c", + "source/i64_to_f16.c", + "source/i64_to_f32.c", + "source/i64_to_f64.c", + "source/i64_to_extF80M.c", + "source/i64_to_f128M.c", + "source/f16_to_ui32.c", + "source/f16_to_ui64.c", + "source/f16_to_i32.c", + "source/f16_to_i64.c", + "source/f16_to_ui32_r_minMag.c", + "source/f16_to_ui64_r_minMag.c", + "source/f16_to_i32_r_minMag.c", + "source/f16_to_i64_r_minMag.c", + "source/f16_to_f32.c", + "source/f16_to_f64.c", + "source/f16_to_extF80M.c", + "source/f16_to_f128M.c", + "source/f16_roundToInt.c", + "source/f16_add.c", + "source/f16_sub.c", + "source/f16_mul.c", + "source/f16_mulAdd.c", + "source/f16_div.c", + "source/f16_rem.c", + "source/f16_sqrt.c", + "source/f16_eq.c", + "source/f16_le.c", + "source/f16_lt.c", + "source/f16_eq_signaling.c", + "source/f16_le_quiet.c", + "source/f16_lt_quiet.c", + "source/f16_isSignalingNaN.c", + "source/f32_to_ui32.c", + "source/f32_to_ui64.c", + "source/f32_to_i32.c", + "source/f32_to_i64.c", + "source/f32_to_ui32_r_minMag.c", + "source/f32_to_ui64_r_minMag.c", + "source/f32_to_i32_r_minMag.c", + "source/f32_to_i64_r_minMag.c", + "source/f32_to_f16.c", + "source/f32_to_f64.c", + "source/f32_to_extF80M.c", + "source/f32_to_f128M.c", + "source/f32_roundToInt.c", + "source/f32_add.c", + "source/f32_sub.c", + "source/f32_mul.c", + "source/f32_mulAdd.c", + "source/f32_div.c", + "source/f32_rem.c", + "source/f32_sqrt.c", + "source/f32_eq.c", + "source/f32_le.c", + "source/f32_lt.c", + "source/f32_eq_signaling.c", + "source/f32_le_quiet.c", + "source/f32_lt_quiet.c", + "source/f32_isSignalingNaN.c", + "source/f64_to_ui32.c", + "source/f64_to_ui64.c", + "source/f64_to_i32.c", + "source/f64_to_i64.c", + "source/f64_to_ui32_r_minMag.c", + "source/f64_to_ui64_r_minMag.c", + "source/f64_to_i32_r_minMag.c", + "source/f64_to_i64_r_minMag.c", + "source/f64_to_f16.c", + "source/f64_to_f32.c", + "source/f64_to_extF80M.c", + "source/f64_to_f128M.c", + "source/f64_roundToInt.c", + "source/f64_add.c", + "source/f64_sub.c", + "source/f64_mul.c", + "source/f64_mulAdd.c", + "source/f64_div.c", + "source/f64_rem.c", + "source/f64_sqrt.c", + "source/f64_eq.c", + "source/f64_le.c", + "source/f64_lt.c", + "source/f64_eq_signaling.c", + "source/f64_le_quiet.c", + "source/f64_lt_quiet.c", + "source/f64_isSignalingNaN.c", + "source/extF80M_to_ui32.c", + "source/extF80M_to_ui64.c", + "source/extF80M_to_i32.c", + "source/extF80M_to_i64.c", + "source/extF80M_to_ui32_r_minMag.c", + "source/extF80M_to_ui64_r_minMag.c", + "source/extF80M_to_i32_r_minMag.c", + "source/extF80M_to_i64_r_minMag.c", + "source/extF80M_to_f16.c", + "source/extF80M_to_f32.c", + "source/extF80M_to_f64.c", + "source/extF80M_to_f128M.c", + "source/extF80M_roundToInt.c", + "source/extF80M_add.c", + "source/extF80M_sub.c", + "source/extF80M_mul.c", + "source/extF80M_div.c", + "source/extF80M_rem.c", + "source/extF80M_sqrt.c", + "source/extF80M_eq.c", + "source/extF80M_le.c", + "source/extF80M_lt.c", + "source/extF80M_eq_signaling.c", + "source/extF80M_le_quiet.c", + "source/extF80M_lt_quiet.c", + "source/f128M_to_ui32.c", + "source/f128M_to_ui64.c", + "source/f128M_to_i32.c", + "source/f128M_to_i64.c", + "source/f128M_to_ui32_r_minMag.c", + "source/f128M_to_ui64_r_minMag.c", + "source/f128M_to_i32_r_minMag.c", + "source/f128M_to_i64_r_minMag.c", + "source/f128M_to_f16.c", + "source/f128M_to_f32.c", + "source/f128M_to_f64.c", + "source/f128M_to_extF80M.c", + "source/f128M_roundToInt.c", + "source/f128M_add.c", + "source/f128M_sub.c", + "source/f128M_mul.c", + "source/f128M_mulAdd.c", + "source/f128M_div.c", + "source/f128M_rem.c", + "source/f128M_sqrt.c", + "source/f128M_eq.c", + "source/f128M_le.c", + "source/f128M_lt.c", + "source/f128M_eq_signaling.c", + "source/f128M_le_quiet.c", + "source/f128M_lt_quiet.c", + # See `$(OBJS_ALL)` target in `build/Linux-ARM-VFPv2-GCC/Makefile` in the + # `softfloat` repo. + "build/Linux-ARM-VFPv2-GCC/platform.h", + "source/include/primitiveTypes.h", + "source/include/primitives.h", + # See `$(OBJS_SPECIALIZE) $(OBJS_OTHERS)` target in + # `build/Linux-ARM-VFPv2-GCC/Makefile` in the `softfloat` repo. + "source/include/softfloat_types.h", + "source/include/internals.h", + "source/ARM-VFPv2/specialize.h", + # `platform.h` includes `opts-GCC.h`. + "source/include/opts-GCC.h", + ], + hdrs = ["source/include/softfloat.h"], + copts = [ + "-Iexternal/softfloat/build/Linux-ARM-VFPv2-GCC", + "-Iexternal/softfloat/source/ARM-VFPv2", + "-Werror-implicit-function-declaration", + "-O2", + ], + includes = ["source/include"], + local_defines = [ + "SOFTFLOAT_ROUND_ODD", + "INLINE_LEVEL=5", + ], + visibility = ["//visibility:private"], +) + cc_library( name = "softfloat_linux_x86_64", srcs = [ @@ -358,6 +632,7 @@ cc_library( name = "softfloat", visibility = ["//visibility:public"], deps = select({ - "@//:linux-x86_64": [":softfloat_linux_x86_64"], + "@//:linux_arm64": [":softfloat_linux_arm64"], + "@//:linux_x86_64": [":softfloat_linux_x86_64"], }), ) diff --git a/bazel/third_party/sse2neon/BUILD.bazel b/bazel/third_party/sse2neon/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/bazel/third_party/sse2neon/sse2neon.BUILD b/bazel/third_party/sse2neon/sse2neon.BUILD new file mode 100644 index 0000000000..c4ef879b52 --- /dev/null +++ b/bazel/third_party/sse2neon/sse2neon.BUILD @@ -0,0 +1,6 @@ +cc_library( + name = "sse2neon", + hdrs = ["sse2neon.h"], + linkstatic = True, + visibility = ["//visibility:public"], +) diff --git a/bazel/third_party/uv/uv.BUILD b/bazel/third_party/uv/uv.BUILD index e50dc8328d..07063afd2d 100644 --- a/bazel/third_party/uv/uv.BUILD +++ b/bazel/third_party/uv/uv.BUILD @@ -13,7 +13,11 @@ configure_make( configure_in_place = True, configure_options = [ "--disable-shared", - ], + ] + select({ + # Native compilation on linux-arm64 isn't supported. + "@//:linux_arm64": ["--host=aarch64-linux-gnu"], + "//conditions:default": [], + }), lib_source = ":all", out_static_libs = ["libuv.a"], targets = ["install"], diff --git a/bazel/toolchain/BUILD.bazel b/bazel/toolchain/BUILD.bazel index 59002c5236..88e7205a15 100644 --- a/bazel/toolchain/BUILD.bazel +++ b/bazel/toolchain/BUILD.bazel @@ -1,3 +1,30 @@ +# ADDING A NEW TOOLCHAIN +# +# The general process for adding a new toolchain is as follows: +# +# (1) Define a `cc_toolchaing_config()` rule target with a `name` attribute of +# the form `---config` and a `toolchain_identifier` of +# the form `toolchain---`. The `cc_toolchain_config()` +# definition in `//bazel/toolchain:cfg.bzl` lists the mandatory attributes +# for the `cc_toolchain_config()` rule. If any of the toolchain's include +# paths require a compiler version number, simply replace the version number +# with `{compiler_version}`, which is replaced with the value of the label +# indicated by the `compiler_version` attribute when the rule is resolved. +# (2) Define a `cc_toolchain()` rule target with a `name` attribute of the form +# `--` and a `toolchain_config` attribute that references +# the `cc_toolchain_config()` target from (1). +# (3) Define a `toolchain()` rule target with a `name` attribute of the form +# `---toolchain` and specify the platform the toolchain +# runs on via the `exec_compatible_with` attribute and the platform the +# toolchain targets (i.e. compiles for) via the `target_compatible_with` +# attribute. Use the `cc_toolchain()` target from (2) as the value of the +# `toolchain` attribute and `:toolchain_type` for the `toolchain_type` +# attribute. +# (4) Register the new toolchain in `//:WORKSPACE.bazel` by adding the +# toolchain's label (i.e. +# `//bazel/toolchain:---toolchain`) to the +# `register_toolchains()` function. +# # For more information on configuring toolchains, see # https://bazel.build/tutorials/ccp-toolchain-config # and https://bazel.build/extending/toolchains. @@ -11,6 +38,56 @@ alias( actual = "@bazel_tools//tools/cpp:toolchain_type", ) +# +# aarch64_linux_gnu_gcc-linux-x86_64 +# + +# Toolchain identifier. +_aarch64_linux_gnu_gcc = "toolchain-aarch64_linux_gnu_gcc-linux-x86_64" + +cc_toolchain_config( + name = "aarch64_linux_gnu_gcc-linux-x86_64-config", + ar = "/usr/bin/aarch64-linux-gnu-ar", + cc = "/usr/bin/aarch64-linux-gnu-gcc", + compiler = "aarch64-linux-gnu-gcc", + compiler_version = "//:aarch64_linux_gnu_gcc_version", + ld = "/usr/bin/aarch64-linux-gnu-ld", + sys_includes = [ + "/usr/aarch64-linux-gnu/include", + "/usr/lib/gcc/aarch64-linux-gnu/{compiler_version}/include", + "/usr/lib/gcc/aarch64-linux-gnu/{compiler_version}/include-fixed", + ], + target_cpu = "arm64", + toolchain_identifier = _aarch64_linux_gnu_gcc, +) + +cc_toolchain( + name = "aarch64_linux_gnu_gcc-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 = ":aarch64_linux_gnu_gcc-linux-x86_64-config", + toolchain_identifier = _aarch64_linux_gnu_gcc, +) + +toolchain( + name = "aarch64_linux_gnu_gcc-linux-x86_64-toolchain", + exec_compatible_with = [ + "@platforms//os:linux", + "@platforms//cpu:x86_64", + ], + target_compatible_with = [ + "@platforms//os:linux", + "@platforms//cpu:arm64", + ], + toolchain = ":aarch64_linux_gnu_gcc-linux-x86_64", + toolchain_type = ":toolchain_type", +) + # # clang-linux-x86_64 # @@ -23,9 +100,10 @@ cc_toolchain_config( ar = "/usr/bin/ar", cc = "/usr/bin/clang", compiler = "clang", + compiler_version = "//:clang_version", ld = "/usr/bin/ld", sys_includes = [ - "/usr/lib/clang/14.0.6", + "/usr/lib/clang/{compiler_version}", "/usr/include", ], target_cpu = "x86_64", @@ -48,7 +126,6 @@ cc_toolchain( toolchain( name = "clang-linux-x86_64-toolchain", exec_compatible_with = [ - "//:clang", "@platforms//os:linux", "@platforms//cpu:x86_64", ], @@ -72,11 +149,11 @@ cc_toolchain_config( ar = "/usr/bin/ar", cc = "/usr/bin/gcc", compiler = "gcc", + compiler_version = "//:gcc_version", ld = "/usr/bin/ld", sys_includes = [ - # TODO: remove hard-coded version number. - "/usr/lib/gcc/x86_64-pc-linux-gnu/12.2.0/include", - "/usr/lib/gcc/x86_64-pc-linux-gnu/12.2.0/include-fixed", + "/usr/lib/gcc/x86_64-pc-linux-gnu/{compiler_version}/include", + "/usr/lib/gcc/x86_64-pc-linux-gnu/{compiler_version}/include-fixed", "/usr/include", ], target_cpu = "x86_64", diff --git a/bazel/toolchain/cfg.bzl b/bazel/toolchain/cfg.bzl index 988812cf3a..e93f787a97 100644 --- a/bazel/toolchain/cfg.bzl +++ b/bazel/toolchain/cfg.bzl @@ -1,3 +1,4 @@ +load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo") load("@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", "tool_path") def _cc_toolchain_config_impl(ctx): @@ -7,7 +8,12 @@ def _cc_toolchain_config_impl(ctx): ctx = ctx, # See https://bazel.build/docs/cc-toolchain-config-reference#features. features = [], - cxx_builtin_include_directories = ctx.attr.sys_includes, + # Replace `{compiler_version}` in all include paths with the value of + # the `compiler_version` label. + cxx_builtin_include_directories = [ + path.format(compiler_version = ctx.attr.compiler_version[BuildSettingInfo].value) + for path in ctx.attr.sys_includes + ], toolchain_identifier = ctx.attr.toolchain_identifier, target_system_name = ctx.attr.target_system_name, target_cpu = ctx.attr.target_cpu, @@ -58,6 +64,7 @@ cc_toolchain_config = rule( "ar": attr.string(mandatory = True), "cc": attr.string(mandatory = True), "compiler": attr.string(mandatory = True), + "compiler_version": attr.label(mandatory = True), "ld": attr.string(mandatory = True), "target_cpu": attr.string(mandatory = True), "toolchain_identifier": attr.string(mandatory = True), diff --git a/pkg/c3/portable.h b/pkg/c3/portable.h index f420b9a83a..56d099b680 100644 --- a/pkg/c3/portable.h +++ b/pkg/c3/portable.h @@ -180,14 +180,6 @@ # endif - /** External, OS-independent library dependencies. - **/ - /* The GMP (GNU arbitrary-precision arithmetic) library. - ** (Tested with version 4.0.1.) - */ -# include - - /** Private C "extensions." *** *** Except for these and main(), any function, macro, or structure diff --git a/pkg/noun/imprison.h b/pkg/noun/imprison.h index d3f34b6d0c..be8b6040e0 100644 --- a/pkg/noun/imprison.h +++ b/pkg/noun/imprison.h @@ -5,6 +5,7 @@ #include "allocate.h" #include "c3.h" +#include "gmp.h" #include "types.h" /** Structures. diff --git a/pkg/noun/retrieve.h b/pkg/noun/retrieve.h index dccbf8ee06..a98a5e4697 100644 --- a/pkg/noun/retrieve.h +++ b/pkg/noun/retrieve.h @@ -4,6 +4,7 @@ #define U3_RETRIEVE_H #include "c3.h" +#include "gmp.h" #include "types.h" /** u3r_*: read without ever crashing.