Build with bazel on darwin-arm64 (#13)

This commit is contained in:
Matthew LeVan 2023-01-09 13:03:58 -05:00 committed by Peter McEvoy
parent 5f838386fb
commit e434d32181
19 changed files with 891 additions and 26 deletions

View File

@ -157,6 +157,23 @@ platform(
],
)
platform(
name = "clang-macos-arm64",
constraint_values = [
":clang",
"@platforms//os:macos",
"@platforms//cpu:arm64",
],
)
platform(
name = "macos-arm64",
constraint_values = [
"@platforms//os:macos",
"@platforms//cpu:arm64",
],
)
alias(
name = "urbit",
actual = "//pkg/vere:urbit",

View File

@ -5,7 +5,6 @@ contains [Urbit's runtime environment][vere], the lowest layer of the Urbit
stack, which includes the Nock virtual machine, I/O drivers, event log, and
snapshotting system.
## Getting Started
For basic Urbit usage instructions, head over to [urbit.org][getting-started].
@ -13,7 +12,6 @@ For a high-level overview of the salient aspects of Urbit's architecture, visit
[developers.urbit.org][technical-reference]. You might also be interested in
joining the [urbit-dev][mailing-list] mailing list.
## Packages
Urbit's runtime is broken down into a few separate layers, each of which is
@ -28,7 +26,6 @@ defined in its own package:
- [`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.
## Build
We use [`bazel`][bazel] to build Urbit's runtime, which is packaged as a single
@ -119,14 +116,12 @@ 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
Contributions of any form are more than welcome. Please take a look at our
[contributing guidelines][contributing] for details on our git practices, coding
styles, how we manage issues, and so on.
[bazel]: https://bazel.build
[contributing]: https://github.com/urbit/urbit/blob/master/CONTRIBUTING.md
[cue]: https://developers.urbit.org/reference/hoon/stdlib/2p#cue

View File

@ -37,6 +37,26 @@
# inevitable when a third party dependency has a particularly complicated
# build system that would be too difficult to replicate in Bazel (i.e.
# OpenSSL). However, delegate only as a last resort.
#
# PATCHING A DEPENDENCY
#
# If a dependency has a bug that prevents it from being used in the project,
# you can patch the dependency to fix it. We recommend the process below:
#
# (1) Make a change to the source of the dependency. If the change is
# platform-specific, wrap it in the appropriate URBIT_RUNTIME_* macro.
# We "gate" source patches with these macros so that we only ever need
# at most one patch per dependency.
# (a) CPU architecture macros: `URBIT_RUNTIME_CPU_{X86_64,ARM64}`.
# (b) OS macros: `URBIT_RUNTIME_OS_{LINUX,DARWIN,BSD,MINGW}`.
# (2) Generate a patch file named <dependency_version>.patch and save it in
# `bazel/third_party/<dependency>`.
# (3) Update the dependency's targets to locally define the platform-specific
# patch macro(s). `select()` statements should be used to define the
# correct macro for the current platform.
# (4) Update the dependency's repository rule in WORKSPACE.bazel to include
# `patch_args = ["-p1"]` (assuming the patch was generated with `git diff`)
# and `patches = ["//bazel/third_party/<dependency>:<version>.patch"]`.
load("//bazel:repo.bzl", "versioned_http_archive", "versioned_http_file")
@ -75,6 +95,7 @@ versioned_http_archive(
register_toolchains(
"//bazel/toolchain:aarch64_linux_gnu_gcc-linux-x86_64-toolchain",
"//bazel/toolchain:clang-linux-x86_64-toolchain",
"//bazel/toolchain:clang-macos-arm64-toolchain",
"//bazel/toolchain:gcc-linux-x86_64-toolchain",
)
@ -180,6 +201,8 @@ versioned_http_archive(
versioned_http_archive(
name = "lmdb",
build_file = "//bazel/third_party/lmdb:lmdb.BUILD",
patch_args = ["-p1"],
patches = ["//bazel/third_party/lmdb:{version}.patch"],
sha256 = "22054926b426c66d8f2bc22071365df6e35f3aacf19ad943bc6167d4cae3bebb",
strip_prefix = "lmdb-LMDB_{version}/libraries/liblmdb",
url = "https://github.com/LMDB/lmdb/archive/refs/tags/LMDB_{version}.tar.gz",
@ -243,6 +266,8 @@ versioned_http_archive(
versioned_http_archive(
name = "softfloat",
build_file = "//bazel/third_party/softfloat:softfloat.BUILD",
patch_args = ["-p1"],
patches = ["//bazel/third_party/softfloat:{version}.patch"],
sha256 = "15ad5841e88fe09422a8e31a0ef3fe126ecf678f52c9a3882f3373d47752aebe",
strip_prefix = "berkeley-softfloat-3-{version}",
url = "https://github.com/ucb-bar/berkeley-softfloat-3/archive/{version}.tar.gz",

View File

@ -40,7 +40,7 @@ configure_make(
"--disable-versioned-symbols",
"--enable-static",
# Use our openssl, not the system's openssl.
"--with-openssl=$(URBIT_RUNTIME_OPENSSL)",
"--with-openssl=$URBIT_RUNTIME_OPENSSL",
"--without-brotli",
"--without-libidn2",
"--without-libpsl",

View File

@ -3,10 +3,10 @@ index 742fec90b..9a11a21bd 100644
--- a/deps/klib/ksw.c
+++ b/deps/klib/ksw.c
@@ -25,7 +25,11 @@
#include <stdlib.h>
#include <stdint.h>
+#if defined(URBIT_RUNTIME_ARCH_ARM64)
+#if defined(URBIT_RUNTIME_CPU_ARM64)
+#include "sse2neon.h"
+#else
#include <emmintrin.h>
@ -22,7 +22,7 @@ index 3ae3bd309..7db05a186 100644
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
+#if defined(URBIT_RUNTIME_ARCH_ARM64)
+#if defined(URBIT_RUNTIME_CPU_ARM64)
+#include "sse2neon.h"
+#else
#include <emmintrin.h>
@ -39,7 +39,7 @@ index a707070d1..714850f64 100644
#include <string.h>
#ifdef __SSE4_2__
-#ifdef _MSC_VER
+#if defined(URBIT_RUNTIME_ARCH_ARM64)
+#if defined(URBIT_RUNTIME_CPU_ARM64)
+#include "sse2neon.h"
+#elif defined(_MSC_VER)
#include <nmmintrin.h>

View File

@ -43,7 +43,7 @@ cc_library(
includes = ["deps/klib"],
linkstatic = True,
local_defines = select({
"@platforms//cpu:arm64": ["URBIT_RUNTIME_ARCH_ARM64"],
"@platforms//cpu:arm64": ["URBIT_RUNTIME_CPU_ARM64"],
"//conditions:default": [],
}),
visibility = ["//visibility:private"],
@ -98,7 +98,15 @@ cc_library(
hdrs = ["deps/picohttpparser/picohttpparser.h"],
includes = ["deps/picohttpparser"],
linkstatic = True,
local_defines = select({
"@platforms//cpu:arm64": ["URBIT_RUNTIME_CPU_ARM64"],
"//conditions:default": [],
}),
visibility = ["//visibility:private"],
deps = select({
"@platforms//cpu:arm64": ["@sse2neon"],
"//conditions:default": [],
}),
)
# See `deps/picotls` in the `h2o` repo.
@ -121,12 +129,19 @@ cc_library(
"deps/picotls/include/picotls",
],
linkstatic = True,
local_defines = select({
"@platforms//cpu:arm64": ["URBIT_RUNTIME_CPU_ARM64"],
"//conditions:default": [],
}),
visibility = ["//visibility:private"],
deps = [
":cifra",
":micro_ecc",
"@openssl",
],
] + select({
"@platforms//cpu:arm64": ["@sse2neon"],
"//conditions:default": [],
}),
)
# See `deps/ssl-conservatory` in the `h2o` repo.

16
bazel/third_party/lmdb/0.9.29.patch vendored Normal file
View File

@ -0,0 +1,16 @@
diff --git a/mdb.c b/mdb.c
index 8cecdb2..b8d0648 100644
--- a/mdb.c
+++ b/mdb.c
@@ -2529,7 +2529,11 @@ mdb_env_sync(MDB_env *env, int force)
rc = ErrCode();
} else
#endif
+#if defined(URBIT_RUNTIME_OS_DARWIN)
+ if (fcntl(env->me_fd, F_FULLFSYNC, 0))
+#else
if (MDB_FDATASYNC(env->me_fd))
+#endif
rc = ErrCode();
}
}

View File

@ -21,5 +21,9 @@ cc_library(
],
include_prefix = "lmdb",
includes = ["."],
local_defines = select({
"@platforms//os:macos": ["URBIT_RUNTIME_OS_DARWIN"],
"//conditions:default": [],
}),
visibility = ["//visibility:public"],
)

View File

@ -8,7 +8,22 @@ cc_library(
copts = [
"-O3",
"-Wall",
],
] + select({
# TODO: use selects.with_or() from skylib once it's available.
"@platforms//os:macos": [
"-fPIC",
"-c",
],
"@platforms//os:openbsd": [
"-fPIC",
"-c",
],
"@platforms//os:windows": [
"-fPIC",
"-c",
],
"//conditions:default": [],
}),
includes = ["."],
visibility = ["//visibility:public"],
)

View File

@ -0,0 +1,27 @@
diff --git a/build/template-FAST_INT64/platform.h b/build/template-FAST_INT64/platform.h
index 2094658..f8147a0 100644
--- a/build/template-FAST_INT64/platform.h
+++ b/build/template-FAST_INT64/platform.h
@@ -38,13 +38,19 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/*----------------------------------------------------------------------------
*----------------------------------------------------------------------------*/
-==> #define LITTLEENDIAN 1
+#if defined(URBIT_RUNTIME_OS_DARWIN) || defined(URBIT_RUNTIME_OS_BSD)
+#define LITTLEENDIAN 1
+#endif
/*----------------------------------------------------------------------------
*----------------------------------------------------------------------------*/
-==> #define INLINE inline
+#if defined(URBIT_RUNTIME_OS_DARWIN) || defined(URBIT_RUNTIME_OS_BSD)
+#define INLINE inline
+#endif
/*----------------------------------------------------------------------------
*----------------------------------------------------------------------------*/
-==> #define THREAD_LOCAL _Thread_local
+#if defined(URBIT_RUNTIME_OS_DARWIN) || defined(URBIT_RUNTIME_OS_BSD)
+#define THREAD_LOCAL _Thread_local
+#endif

View File

@ -1,5 +1,3 @@
load("@rules_foreign_cc//foreign_cc:defs.bzl", "make")
# This build file is derived from the makefiles in `build/` in the `softfloat`
# repo at https://github.com/ucb-bar/berkeley-softfloat-3.
#
@ -7,6 +5,17 @@ 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",
visibility = ["//visibility:public"],
deps = select({
"@//:linux_arm64": [":softfloat_linux_arm64"],
"@//:linux_x86_64": [":softfloat_linux_x86_64"],
"@//:macos_arm64": ["softfloat_macos_arm64"],
"//conditions:default": [],
}),
)
cc_library(
name = "softfloat_linux_arm64",
srcs = [
@ -629,10 +638,353 @@ cc_library(
)
cc_library(
name = "softfloat",
visibility = ["//visibility:public"],
deps = select({
"@//:linux_arm64": [":softfloat_linux_arm64"],
"@//:linux_x86_64": [":softfloat_linux_x86_64"],
}),
name = "softfloat_macos_arm64",
srcs = [
# See `OBJS_PRIMITIVES` in `build/template-FAST_INT64/Makefile` in the
# `softfloat` repo.
"source/s_eq128.c",
"source/s_le128.c",
"source/s_lt128.c",
"source/s_shortShiftLeft128.c",
"source/s_shortShiftRight128.c",
"source/s_shortShiftRightJam64.c",
"source/s_shortShiftRightJam64Extra.c",
"source/s_shortShiftRightJam128.c",
"source/s_shortShiftRightJam128Extra.c",
"source/s_shiftRightJam32.c",
"source/s_shiftRightJam64.c",
"source/s_shiftRightJam64Extra.c",
"source/s_shiftRightJam128.c",
"source/s_shiftRightJam128Extra.c",
"source/s_shiftRightJam256M.c",
"source/s_countLeadingZeros8.c",
"source/s_countLeadingZeros16.c",
"source/s_countLeadingZeros32.c",
"source/s_countLeadingZeros64.c",
"source/s_add128.c",
"source/s_add256M.c",
"source/s_sub128.c",
"source/s_sub256M.c",
"source/s_mul64ByShifted32To128.c",
"source/s_mul64To128.c",
"source/s_mul128By32.c",
"source/s_mul128To256M.c",
"source/s_approxRecip_1Ks.c",
"source/s_approxRecip32_1.c",
"source/s_approxRecipSqrt_1Ks.c",
"source/s_approxRecipSqrt32_1.c",
# See `OBJS_SPECIALIZE` in `build/template-FAST_INT64/Makefile` in the
# `softfloat` repo.
"source/8086-SSE/softfloat_raiseFlags.c",
"source/8086-SSE/s_f16UIToCommonNaN.c",
"source/8086-SSE/s_commonNaNToF16UI.c",
"source/8086-SSE/s_propagateNaNF16UI.c",
"source/8086-SSE/s_f32UIToCommonNaN.c",
"source/8086-SSE/s_commonNaNToF32UI.c",
"source/8086-SSE/s_propagateNaNF32UI.c",
"source/8086-SSE/s_f64UIToCommonNaN.c",
"source/8086-SSE/s_commonNaNToF64UI.c",
"source/8086-SSE/s_propagateNaNF64UI.c",
"source/8086-SSE/extF80M_isSignalingNaN.c",
"source/8086-SSE/s_extF80UIToCommonNaN.c",
"source/8086-SSE/s_commonNaNToExtF80UI.c",
"source/8086-SSE/s_propagateNaNExtF80UI.c",
"source/8086-SSE/f128M_isSignalingNaN.c",
"source/8086-SSE/s_f128UIToCommonNaN.c",
"source/8086-SSE/s_commonNaNToF128UI.c",
"source/8086-SSE/s_propagateNaNF128UI.c",
# See `OBJS_OTHERS` in `build/template-FAST_INT64/Makefile` in the
# `softfloat` repo.
"source/s_roundToUI32.c",
"source/s_roundToUI64.c",
"source/s_roundToI32.c",
"source/s_roundToI64.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_normSubnormalExtF80Sig.c",
"source/s_roundPackToExtF80.c",
"source/s_normRoundPackToExtF80.c",
"source/s_addMagsExtF80.c",
"source/s_subMagsExtF80.c",
"source/s_normSubnormalF128Sig.c",
"source/s_roundPackToF128.c",
"source/s_normRoundPackToF128.c",
"source/s_addMagsF128.c",
"source/s_subMagsF128.c",
"source/s_mulAddF128.c",
"source/softfloat_state.c",
"source/ui32_to_f16.c",
"source/ui32_to_f32.c",
"source/ui32_to_f64.c",
"source/ui32_to_extF80.c",
"source/ui32_to_extF80M.c",
"source/ui32_to_f128.c",
"source/ui32_to_f128M.c",
"source/ui64_to_f16.c",
"source/ui64_to_f32.c",
"source/ui64_to_f64.c",
"source/ui64_to_extF80.c",
"source/ui64_to_extF80M.c",
"source/ui64_to_f128.c",
"source/ui64_to_f128M.c",
"source/i32_to_f16.c",
"source/i32_to_f32.c",
"source/i32_to_f64.c",
"source/i32_to_extF80.c",
"source/i32_to_extF80M.c",
"source/i32_to_f128.c",
"source/i32_to_f128M.c",
"source/i64_to_f16.c",
"source/i64_to_f32.c",
"source/i64_to_f64.c",
"source/i64_to_extF80.c",
"source/i64_to_extF80M.c",
"source/i64_to_f128.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_extF80.c",
"source/f16_to_extF80M.c",
"source/f16_to_f128.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_extF80.c",
"source/f32_to_extF80M.c",
"source/f32_to_f128.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_extF80.c",
"source/f64_to_extF80M.c",
"source/f64_to_f128.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/extF80_to_ui32.c",
"source/extF80_to_ui64.c",
"source/extF80_to_i32.c",
"source/extF80_to_i64.c",
"source/extF80_to_ui32_r_minMag.c",
"source/extF80_to_ui64_r_minMag.c",
"source/extF80_to_i32_r_minMag.c",
"source/extF80_to_i64_r_minMag.c",
"source/extF80_to_f16.c",
"source/extF80_to_f32.c",
"source/extF80_to_f64.c",
"source/extF80_to_f128.c",
"source/extF80_roundToInt.c",
"source/extF80_add.c",
"source/extF80_sub.c",
"source/extF80_mul.c",
"source/extF80_div.c",
"source/extF80_rem.c",
"source/extF80_sqrt.c",
"source/extF80_eq.c",
"source/extF80_le.c",
"source/extF80_lt.c",
"source/extF80_eq_signaling.c",
"source/extF80_le_quiet.c",
"source/extF80_lt_quiet.c",
"source/extF80_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/f128_to_ui32.c",
"source/f128_to_ui64.c",
"source/f128_to_i32.c",
"source/f128_to_i64.c",
"source/f128_to_ui32_r_minMag.c",
"source/f128_to_ui64_r_minMag.c",
"source/f128_to_i32_r_minMag.c",
"source/f128_to_i64_r_minMag.c",
"source/f128_to_f16.c",
"source/f128_to_f32.c",
"source/f128_to_extF80.c",
"source/f128_to_f64.c",
"source/f128_roundToInt.c",
"source/f128_add.c",
"source/f128_sub.c",
"source/f128_mul.c",
"source/f128_mulAdd.c",
"source/f128_div.c",
"source/f128_rem.c",
"source/f128_sqrt.c",
"source/f128_eq.c",
"source/f128_le.c",
"source/f128_lt.c",
"source/f128_eq_signaling.c",
"source/f128_le_quiet.c",
"source/f128_lt_quiet.c",
"source/f128_isSignalingNaN.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_extF80M.c",
"source/f128M_to_f64.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 `$(OTHER_HEADERS)` in `build/template-FAST_INT64/Makefile` in the
# `softfloat` repo.
"source/include/opts-GCC.h",
# See `$(OBJS_ALL)` target in `build/template-FAST_INT64/Makefile` in the
# `softfloat` repo.
"build/template-FAST_INT64/platform.h",
"source/include/primitiveTypes.h",
"source/include/primitives.h",
# See `$(OBJS_SPECIALIZE) $(OBJS_OTHERS)` target in
# `build/template-FAST_INT64/Makefile` in the `softfloat` repo.
"source/include/softfloat_types.h",
"source/include/internals.h",
"source/8086-SSE/specialize.h",
],
hdrs = [
"source/include/softfloat.h",
],
copts = [
"-Iexternal/softfloat/build/template-FAST_INT64",
"-Iexternal/softfloat/source/8086-SSE",
"-Werror-implicit-function-declaration",
"-O2",
],
# `SOFTFLOAT_FAST_INT64` is used in `softfloat.h` and therefore needs to be
# passed to dependencies.
defines = ["SOFTFLOAT_FAST_INT64"],
includes = [
"build/template-FAST_INT64",
"source/8086-SSE",
"source/include",
],
local_defines = [
"URBIT_RUNTIME_OS_DARWIN",
"SOFTFLOAT_ROUND_ODD",
"INLINE_LEVEL=5",
"SOFTFLOAT_FAST_DIV32TO16",
"SOFTFLOAT_FAST_DIV64TO32",
],
visibility = ["//visibility:private"],
)

View File

@ -186,3 +186,60 @@ toolchain(
toolchain = ":gcc-linux-x86_64",
toolchain_type = ":toolchain_type",
)
#
# clang-macos-arm64
#
# Toolchain identifier.
_macos_arm64_clang = "toolchain-clang-macos-arm64"
cc_toolchain_config(
name = "clang-macos-arm64-config",
# NOTE: building with `libtool` does not work on macOS due to lack of
# support in the `configure_make` rule provided by `rules_foreign_cc`.
# Therefore, we require setting `ar` as the archiver tool on macOS.
ar = "/usr/bin/ar",
# By default, Bazel passes the `rcsD` flags to `ar`, but macOS's `ar`
# implementation doesn't support `D`. We remove it with this attribute
# and corresponding `ar_flags_feature` in `cfg.bzl`.
# See https://github.com/bazelbuild/bazel/issues/15875.
ar_flags = "rcs",
cc = "/usr/bin/clang",
compiler = "clang",
compiler_version = "//:clang_version",
ld = "/usr/bin/ld",
sys_includes = [
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include",
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/{compiler_version}/include",
],
target_cpu = "arm64",
toolchain_identifier = _macos_arm64_clang,
)
cc_toolchain(
name = "clang-macos-arm64",
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-macos-arm64-config",
toolchain_identifier = _macos_arm64_clang,
)
toolchain(
name = "clang-macos-arm64-toolchain",
exec_compatible_with = [
"@platforms//os:macos",
"@platforms//cpu:arm64",
],
target_compatible_with = [
"@platforms//os:macos",
"@platforms//cpu:arm64",
],
toolchain = ":clang-macos-arm64",
toolchain_type = ":toolchain_type",
)

View File

@ -1,19 +1,68 @@
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load("@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", "tool_path")
load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")
load(
"@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl",
"feature",
"flag_group",
"flag_set",
"tool_path",
"variable_with_value",
)
def _cc_toolchain_config_impl(ctx):
ar_flags_feature = feature(
name = "archiver_flags",
flag_sets = [
flag_set(
actions = [ACTION_NAMES.cpp_link_static_library],
flag_groups = [
flag_group(flags = [ctx.attr.ar_flags]),
flag_group(
flags = ["%{output_execpath}"],
expand_if_available = "output_execpath",
),
],
),
flag_set(
actions = [ACTION_NAMES.cpp_link_static_library],
flag_groups = [
flag_group(
iterate_over = "libraries_to_link",
flag_groups = [
flag_group(
flags = ["%{libraries_to_link.name}"],
expand_if_equal = variable_with_value(
name = "libraries_to_link.type",
value = "object_file",
),
),
flag_group(
flags = ["%{libraries_to_link.object_files}"],
iterate_over = "libraries_to_link.object_files",
expand_if_equal = variable_with_value(
name = "libraries_to_link.type",
value = "object_file_group",
),
),
],
expand_if_available = "libraries_to_link",
),
],
),
],
)
# See
# https://bazel.build/rules/lib/cc_common#create_cc_toolchain_config_info.
return cc_common.create_cc_toolchain_config_info(
ctx = ctx,
# See https://bazel.build/docs/cc-toolchain-config-reference#features.
features = [],
# 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
],
features = [ar_flags_feature],
toolchain_identifier = ctx.attr.toolchain_identifier,
target_system_name = ctx.attr.target_system_name,
target_cpu = ctx.attr.target_cpu,
@ -71,6 +120,7 @@ cc_toolchain_config = rule(
# Optional.
"abi_libc_version": attr.string(default = "unknown"),
"abi_version": attr.string(default = "unknown"),
"ar_flags": attr.string(default = "rcsD"),
"cpp": attr.string(default = "/bin/false"),
"gcov": attr.string(default = "/bin/false"),
"nm": attr.string(default = "/bin/false"),

View File

@ -18,6 +18,7 @@ cc_library(
linkstatic = True,
local_defines = select({
"@platforms//os:windows": ["ENT_GETENTROPY_BCRYPTGENRANDOM"],
"@platforms//os:macos": ["ENT_GETENTROPY_SYSRANDOM"],
# TODO: support fallback to other options if `getrandom()` isn't
# available in `unistd.h`. Preferred order (from most preferred to least
# preferred) is:

View File

@ -19,6 +19,12 @@ cc_library(
),
hdrs = ["noun.h"],
includes = ["."],
linkopts = select({
# NOTE: macOS builds fail to link the `u3o_Config` symbol (and maybe
# others) without this. We should figure out why, and remove this.
"@platforms//os:macos": ["-force_load $(GENDIR)/pkg/noun/libnoun.a"],
"//conditions:default": [],
}),
linkstatic = True,
local_defines = ["U3_GUARD_PAGE"],
visibility = ["//pkg:__subpackages__"],

View File

@ -1,6 +1,6 @@
#include "urcrypt.h"
#include "util.h"
#include <aes_siv.h>
#include "aes_siv.h"
static AES_SIV_CTX*
urcrypt__aes_siv_init(uint8_t *key,

View File

@ -133,7 +133,10 @@ cc_library(
":pace",
":version",
] + select({
"@platforms//os:macos": [],
"@platforms//os:macos": [
"platform/darwin/daemon.c",
"platform/darwin/ptty.c",
],
"@platforms//os:linux": [
"platform/linux/daemon.c",
"platform/linux/ptty.c",

View File

@ -0,0 +1,93 @@
/// @file
#include "noun.h"
#include "vere.h"
#include <sys/wait.h>
/*
This is set to the the write-end of a pipe when Urbit is started in
daemon mode. It's meant to be used as a signal to the parent process
that the child process has finished booting.
*/
static c3_i _child_process_booted_signal_fd = -1;
/*
This should be called whenever the ship has been booted enough to
handle commands from automation code. Specifically, once the Eyre's
`chis` interface is up and running.
In daemon mode, this signals to the parent process that it can
exit. Otherwise, it does nothing.
Once we've sent a signal with `write`, we close the file descriptor
and overwrite the global to make it impossible to accidentally do
this twice.
*/
static void _on_boot_completed_cb() {
c3_c buf[2] = {0,0};
if ( -1 == _child_process_booted_signal_fd ) {
return;
}
if ( 0 == write(_child_process_booted_signal_fd, buf, 1) ) {
c3_assert(!"_on_boot_completed_cb: Can't write to parent FD");
}
close(_child_process_booted_signal_fd);
_child_process_booted_signal_fd = -1;
}
/* u3_daemon_init(): platform-specific daemon mode initialization.
We use a pipe to communicate between the child and the parent. The
parent waits for the child to write something to the pipe and
then exits. If the pipe is closed with nothing written to it, get
the exit status from the child process and also exit with that status.
We want the child to write to the pipe once it's booted, so we put
`_on_boot_completed_cb` into `u3_Host.bot_f`, which is NULL in
non-daemon mode. That gets called once the `chis` service is
available.
In both processes, we are good fork() citizens, and close all unused
file descriptors. Closing `pipefd[1]` in the parent process is
especially important, since the pipe needs to be closed if the child
process dies. When the pipe is closed, the read fails, and that's
how we know that something went wrong.
There are some edge cases around `WEXITSTATUS` that are not handled
here, but I don't think it matters.
*/
void
u3_daemon_init()
{
c3_i pipefd[2];
if ( 0 != pipe(pipefd) ) {
c3_assert(!"Failed to create pipe");
}
pid_t childpid = fork();
if ( 0 == childpid ) {
close(pipefd[0]);
_child_process_booted_signal_fd = pipefd[1];
u3_Host.bot_f = _on_boot_completed_cb;
return;
}
close(pipefd[1]);
close(0);
close(1);
close(2);
c3_c buf[2] = {0,0};
if ( 1 == read(pipefd[0], buf, 1) ) {
exit(0);
}
c3_i status;
wait(&status);
exit(WEXITSTATUS(status));
}

View File

@ -0,0 +1,189 @@
/// @file
#include "c3.h"
#include "noun.h"
#include "vere.h"
#include <sys/ioctl.h>
#include <termios.h>
/* u3_ptty: POSIX terminal extension to u3_utty.
*/
typedef struct {
u3_utty tty_u; // common tty structure
c3_i cug_i; // blocking fcntl flags
c3_i nob_i; // nonblocking fcntl flags
struct termios bak_u; // cooked terminal state
struct termios raw_u; // raw terminal state
} u3_ptty;
/* _term_tcsetattr(): tcsetattr w/retry on EINTR.
*/
static c3_i
_term_tcsetattr(c3_i fil_i, c3_i act_i, const struct termios* tms_u)
{
c3_i ret_i = 0;
c3_w len_w = 0;
do {
// abort pathological retry loop
//
if ( 100 == ++len_w ) {
fprintf(stderr, "term: tcsetattr loop: %s\r\n", strerror(errno));
return -1;
}
ret_i = tcsetattr(fil_i, act_i, tms_u);
} while ( (-1 == ret_i) && (EINTR == errno) );
return ret_i;
}
/* _ttyf_start_raw_input(): sets the tty to raw input.
*/
static c3_o
_ttyf_start_raw_input(u3_utty* uty_u)
{
u3_ptty* pty_u = (u3_ptty*)uty_u;
if ( 0 != _term_tcsetattr(uty_u->fid_i, TCSADRAIN, &pty_u->raw_u) ) {
return c3n;
}
if ( -1 == fcntl(uty_u->fid_i, F_SETFL, pty_u->nob_i) ) {
c3_assert(!"init-fcntl");
}
return c3y;
}
/* _ttyf_start_raw_input(): ends raw input on the tty.
*/
static c3_o
_ttyf_end_raw_input(u3_utty* uty_u)
{
u3_ptty* pty_u = (u3_ptty*)uty_u;
if ( 0 != _term_tcsetattr(uty_u->fid_i, TCSADRAIN, &pty_u->bak_u) ) {
return c3n;
}
if ( -1 == fcntl(uty_u->fid_i, F_SETFL, pty_u->cug_i) ) {
c3_assert(!"exit-fcntl");
}
return c3y;
}
/* _ttyf_hija(): hijacks the tty for cooked output.
*/
static c3_o
_ttyf_hija(u3_utty* uty_u)
{
u3_ptty* pty_u = (u3_ptty*)uty_u;
if ( 0 != _term_tcsetattr(1, TCSADRAIN, &pty_u->bak_u) ) {
perror("hija-tcsetattr-1");
c3_assert(!"hija-tcsetattr");
}
if ( -1 == fcntl(1, F_SETFL, pty_u->cug_i) ) {
perror("hija-fcntl-1");
c3_assert(!"hija-fcntl");
}
if ( 0 != _term_tcsetattr(0, TCSADRAIN, &pty_u->bak_u) ) {
perror("hija-tcsetattr-0");
c3_assert(!"hija-tcsetattr");
}
if ( -1 == fcntl(0, F_SETFL, pty_u->cug_i) ) {
perror("hija-fcntl-0");
c3_assert(!"hija-fcntl");
}
return c3y;
}
/* _ttyf_loja(): releases the tty from cooked output.
*/
static c3_o
_ttyf_loja(u3_utty* uty_u)
{
u3_ptty* pty_u = (u3_ptty*)uty_u;
if ( 0 != _term_tcsetattr(1, TCSADRAIN, &pty_u->raw_u) ) {
perror("loja-tcsetattr-1");
c3_assert(!"loja-tcsetattr");
}
if ( -1 == fcntl(1, F_SETFL, pty_u->nob_i) ) {
perror("hija-fcntl-1");
c3_assert(!"loja-fcntl");
}
if ( 0 != _term_tcsetattr(0, TCSADRAIN, &pty_u->raw_u) ) {
perror("loja-tcsetattr-0");
c3_assert(!"loja-tcsetattr");
}
if ( -1 == fcntl(0, F_SETFL, pty_u->nob_i) ) {
perror("hija-fcntl-0");
c3_assert(!"loja-fcntl");
}
return c3y;
}
/* _ttyf_get_winsize(): gets the tty window size.
*/
static c3_o
_ttyf_get_winsize(u3_utty* uty_u, c3_l* col_l, c3_l* row_l)
{
struct winsize siz_u;
if ( 0 == ioctl(uty_u->fid_i, TIOCGWINSZ, &siz_u) )
{
*col_l = siz_u.ws_col;
*row_l = siz_u.ws_row;
return c3y;
} else {
return c3n;
}
}
/* u3_ptty_init(): initialize platform-specific tty.
*/
u3_utty*
u3_ptty_init(uv_loop_t* lup_u, const c3_c** err_c)
{
u3_ptty* pty_u = c3_calloc(sizeof(u3_ptty));
u3_utty* uty_u = &pty_u->tty_u;
if ( !isatty(0) || !isatty(1) ) {
*err_c = "not a tty";
c3_free(pty_u);
return NULL;
}
uv_pipe_init(lup_u, &uty_u->pin_u.pip_u, 0);
uv_pipe_init(lup_u, &uty_u->pop_u.pip_u, 0);
uv_pipe_open(&uty_u->pin_u.pip_u, 0);
uv_pipe_open(&uty_u->pop_u.pip_u, 1);
// Load old terminal state to restore.
//
{
if ( 0 != tcgetattr(uty_u->fid_i, &pty_u->bak_u) ) {
c3_assert(!"init-tcgetattr");
}
if ( -1 == fcntl(uty_u->fid_i, F_GETFL, &pty_u->cug_i) ) {
c3_assert(!"init-fcntl");
}
pty_u->cug_i &= ~O_NONBLOCK; // could fix?
pty_u->nob_i = pty_u->cug_i | O_NONBLOCK; // O_NDELAY on older unix
}
// Construct raw termios configuration.
//
{
pty_u->raw_u = pty_u->bak_u;
pty_u->raw_u.c_lflag &= ~(ECHO | ECHONL | ICANON | IEXTEN);
pty_u->raw_u.c_iflag &= ~(ICRNL | INPCK | ISTRIP);
pty_u->raw_u.c_cflag &= ~(CSIZE | PARENB);
pty_u->raw_u.c_cflag |= CS8;
pty_u->raw_u.c_oflag &= ~(OPOST);
pty_u->raw_u.c_cc[VMIN] = 0;
pty_u->raw_u.c_cc[VTIME] = 0;
}
uty_u->fid_i = 1;
uty_u->sta_f = _ttyf_start_raw_input;
uty_u->sto_f = _ttyf_end_raw_input;
uty_u->hij_f = _ttyf_hija;
uty_u->loj_f = _ttyf_loja;
uty_u->wsz_f = _ttyf_get_winsize;
return uty_u;
}