From c4ba180e1d49f8ecbffcba260cb2c213eb65ddc6 Mon Sep 17 00:00:00 2001 From: yosoyubik Date: Mon, 14 Oct 2024 13:54:01 +0200 Subject: [PATCH] Revert "bazel: delete bazel build system" This reverts commit 6d3f9b2e1ce648583e733a6cc9fa4eac9ec5c9fe. --- .bazelrc | 51 ++ BUILD.bazel | 214 ++++++ PACE | 1 + VERSION | 1 + WORKSPACE.bazel | 448 ++++++++++++ bazel/BUILD.bazel | 21 + bazel/common_settings.bzl | 50 ++ bazel/repo.bzl | 34 + bazel/third_party/aes_siv/BUILD.bazel | 0 bazel/third_party/aes_siv/aes_siv.BUILD | 21 + bazel/third_party/argon2/BUILD.bazel | 0 bazel/third_party/argon2/argon2.BUILD | 42 ++ bazel/third_party/avahi/BUILD.bazel | 0 bazel/third_party/avahi/avahi.BUILD | 30 + bazel/third_party/curl/BUILD.bazel | 0 bazel/third_party/curl/curl.BUILD | 67 ++ bazel/third_party/dbus/BUILD.bazel | 0 bazel/third_party/dbus/dbus.BUILD | 21 + bazel/third_party/ed25519/BUILD.bazel | 0 bazel/third_party/ed25519/ed25519.BUILD | 14 + bazel/third_party/expat/BUILD.bazel | 0 bazel/third_party/expat/expat.BUILD | 24 + bazel/third_party/gmp/BUILD.bazel | 0 bazel/third_party/gmp/gmp.BUILD | 30 + bazel/third_party/h2o/2.2.6.patch | 47 ++ bazel/third_party/h2o/BUILD.bazel | 0 bazel/third_party/h2o/h2o.BUILD | 375 +++++++++++ ...647514212b76ae7bca0dea9b7b197d1d8186.patch | 168 +++++ bazel/third_party/keccak_tiny/BUILD.bazel | 0 .../third_party/keccak_tiny/keccak_tiny.BUILD | 16 + bazel/third_party/libbacktrace/BUILD.bazel | 0 .../libbacktrace/libbacktrace.BUILD | 25 + bazel/third_party/libunwind/BUILD.bazel | 0 bazel/third_party/libunwind/libunwind.BUILD | 25 + bazel/third_party/lmdb/0.9.29.patch | 16 + bazel/third_party/lmdb/BUILD.bazel | 0 bazel/third_party/lmdb/lmdb.BUILD | 29 + bazel/third_party/murmur3/BUILD.bazel | 0 bazel/third_party/murmur3/murmur3.BUILD | 21 + bazel/third_party/natpmp/BUILD.bazel | 0 bazel/third_party/natpmp/natpmp.BUILD | 8 + bazel/third_party/openssl/BUILD.bazel | 0 bazel/third_party/openssl/openssl.BUILD | 43 ++ bazel/third_party/pdjson/BUILD.bazel | 0 bazel/third_party/pdjson/pdjson.BUILD | 16 + bazel/third_party/scrypt/BUILD.bazel | 0 bazel/third_party/scrypt/scrypt.BUILD | 30 + ...e8fb2d1fd8a3d641d7c33705691d41a2a860.patch | 14 + bazel/third_party/secp256k1/BUILD.bazel | 0 bazel/third_party/secp256k1/secp256k1.BUILD | 30 + bazel/third_party/sigsegv/BUILD.bazel | 0 bazel/third_party/sigsegv/sigsegv.BUILD | 31 + ...db33fc1e2130f67c045327b0ec949032df1d.patch | 27 + bazel/third_party/softfloat/BUILD.bazel | 0 bazel/third_party/softfloat/softfloat.BUILD | 637 ++++++++++++++++++ bazel/third_party/sse2neon/BUILD.bazel | 0 bazel/third_party/sse2neon/sse2neon.BUILD | 7 + bazel/third_party/urcrypt/BUILD.bazel | 0 bazel/third_party/urcrypt/urcrypt.BUILD | 28 + bazel/third_party/uv/BUILD.bazel | 0 bazel/third_party/uv/uv.BUILD | 28 + bazel/third_party/whereami/BUILD.bazel | 0 bazel/third_party/whereami/whereami.BUILD | 8 + bazel/third_party/zlib/BUILD.bazel | 0 bazel/third_party/zlib/zlib.BUILD | 19 + bazel/toolchain/BUILD.bazel | 410 +++++++++++ bazel/toolchain/cfg.bzl | 168 +++++ docker/BUILD.bazel | 116 ++++ pkg/c3/BUILD.bazel | 42 ++ pkg/ent/BUILD.bazel | 49 ++ pkg/noun/BUILD.bazel | 117 ++++ pkg/noun/platform/darwin/BUILD.bazel | 8 + pkg/noun/platform/linux/BUILD.bazel | 8 + pkg/ur/BUILD.bazel | 39 ++ pkg/vere/BUILD.bazel | 522 ++++++++++++++ 75 files changed, 4196 insertions(+) create mode 100644 .bazelrc create mode 100644 BUILD.bazel create mode 100644 PACE create mode 100644 VERSION create mode 100644 WORKSPACE.bazel create mode 100644 bazel/BUILD.bazel create mode 100644 bazel/common_settings.bzl create mode 100644 bazel/repo.bzl create mode 100644 bazel/third_party/aes_siv/BUILD.bazel create mode 100644 bazel/third_party/aes_siv/aes_siv.BUILD create mode 100644 bazel/third_party/argon2/BUILD.bazel create mode 100644 bazel/third_party/argon2/argon2.BUILD create mode 100644 bazel/third_party/avahi/BUILD.bazel create mode 100644 bazel/third_party/avahi/avahi.BUILD create mode 100644 bazel/third_party/curl/BUILD.bazel create mode 100644 bazel/third_party/curl/curl.BUILD create mode 100644 bazel/third_party/dbus/BUILD.bazel create mode 100644 bazel/third_party/dbus/dbus.BUILD create mode 100644 bazel/third_party/ed25519/BUILD.bazel create mode 100644 bazel/third_party/ed25519/ed25519.BUILD create mode 100644 bazel/third_party/expat/BUILD.bazel create mode 100644 bazel/third_party/expat/expat.BUILD create mode 100644 bazel/third_party/gmp/BUILD.bazel create mode 100644 bazel/third_party/gmp/gmp.BUILD create mode 100644 bazel/third_party/h2o/2.2.6.patch create mode 100644 bazel/third_party/h2o/BUILD.bazel create mode 100644 bazel/third_party/h2o/h2o.BUILD create mode 100644 bazel/third_party/keccak_tiny/64b6647514212b76ae7bca0dea9b7b197d1d8186.patch create mode 100644 bazel/third_party/keccak_tiny/BUILD.bazel create mode 100644 bazel/third_party/keccak_tiny/keccak_tiny.BUILD create mode 100644 bazel/third_party/libbacktrace/BUILD.bazel create mode 100644 bazel/third_party/libbacktrace/libbacktrace.BUILD create mode 100644 bazel/third_party/libunwind/BUILD.bazel create mode 100644 bazel/third_party/libunwind/libunwind.BUILD create mode 100644 bazel/third_party/lmdb/0.9.29.patch create mode 100644 bazel/third_party/lmdb/BUILD.bazel create mode 100644 bazel/third_party/lmdb/lmdb.BUILD create mode 100644 bazel/third_party/murmur3/BUILD.bazel create mode 100644 bazel/third_party/murmur3/murmur3.BUILD create mode 100644 bazel/third_party/natpmp/BUILD.bazel create mode 100644 bazel/third_party/natpmp/natpmp.BUILD create mode 100644 bazel/third_party/openssl/BUILD.bazel create mode 100644 bazel/third_party/openssl/openssl.BUILD create mode 100644 bazel/third_party/pdjson/BUILD.bazel create mode 100644 bazel/third_party/pdjson/pdjson.BUILD create mode 100644 bazel/third_party/scrypt/BUILD.bazel create mode 100644 bazel/third_party/scrypt/scrypt.BUILD create mode 100644 bazel/third_party/secp256k1/694ce8fb2d1fd8a3d641d7c33705691d41a2a860.patch create mode 100644 bazel/third_party/secp256k1/BUILD.bazel create mode 100644 bazel/third_party/secp256k1/secp256k1.BUILD create mode 100644 bazel/third_party/sigsegv/BUILD.bazel create mode 100644 bazel/third_party/sigsegv/sigsegv.BUILD create mode 100644 bazel/third_party/softfloat/5c06db33fc1e2130f67c045327b0ec949032df1d.patch create mode 100644 bazel/third_party/softfloat/BUILD.bazel create mode 100644 bazel/third_party/softfloat/softfloat.BUILD create mode 100644 bazel/third_party/sse2neon/BUILD.bazel create mode 100644 bazel/third_party/sse2neon/sse2neon.BUILD create mode 100644 bazel/third_party/urcrypt/BUILD.bazel create mode 100644 bazel/third_party/urcrypt/urcrypt.BUILD create mode 100644 bazel/third_party/uv/BUILD.bazel create mode 100644 bazel/third_party/uv/uv.BUILD create mode 100644 bazel/third_party/whereami/BUILD.bazel create mode 100644 bazel/third_party/whereami/whereami.BUILD create mode 100644 bazel/third_party/zlib/BUILD.bazel create mode 100644 bazel/third_party/zlib/zlib.BUILD create mode 100644 bazel/toolchain/BUILD.bazel create mode 100644 bazel/toolchain/cfg.bzl create mode 100644 docker/BUILD.bazel create mode 100644 pkg/c3/BUILD.bazel create mode 100644 pkg/ent/BUILD.bazel create mode 100644 pkg/noun/BUILD.bazel create mode 100644 pkg/noun/platform/darwin/BUILD.bazel create mode 100644 pkg/noun/platform/linux/BUILD.bazel create mode 100644 pkg/ur/BUILD.bazel create mode 100644 pkg/vere/BUILD.bazel diff --git a/.bazelrc b/.bazelrc new file mode 100644 index 0000000000..2a72ab5654 --- /dev/null +++ b/.bazelrc @@ -0,0 +1,51 @@ +# Enable configurations specific to the host platform. +common --enable_platform_specific_config + +# Disallow empty `glob()`s. +build --incompatible_disallow_empty_glob + +# Don't auto-detect the C/C++ toolchain. +build --action_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 + +# Use platforms to select toolchains. +# See https://bazel.build/concepts/platforms#cxx and +# https://github.com/bazelbuild/bazel/issues/7260. +build --incompatible_enable_cc_toolchain_resolution + +# Disable transitions. +# See https://github.com/bazelbuild/rules_docker/issues/2052. +build --@io_bazel_rules_docker//transitions:enable=false + +# Add aliases for compiler version build settings. +build --flag_alias=clang_version=//:clang_version +build --flag_alias=gcc_version=//:gcc_version + +# Use optimized build by default. According to the bazel documentation, this +# corresponds to -O2 -DNDEBUG, but these are overriden in +# //bazel/common_settings.bzl:vere_library. +# https://bazel.build/docs/user-manual#build-semantics +build --compilation_mode=opt + +# Don't include source level debug info on macOS. See +# https://github.com/urbit/urbit/issues/5561 and +# https://github.com/urbit/vere/issues/131. +build:linux --host_copt='-g' +build --strip=never + +# Turn on optimization, CPU and memory debug for exec config, which we only use +# to run the fake ship tests. Also turn on extra snapshot validation. +build --host_copt='-O3' +build --host_copt='-DU3_CPU_DEBUG' +build --host_copt='-DU3_MEMORY_DEBUG' +build --host_copt='-DC3DBG' +build --host_copt='-DU3_SNAPSHOT_VALIDATION' + +# Set as per-file copts as a plain --copt gets passed to third party +# dependencies which forces recompilation (slow) if you are switching between +# including/excluding a symbol define. +build:mem_dbg --per_file_copt='pkg/.*@-DU3_MEMORY_DEBUG' +build:cpu_dbg --per_file_copt='pkg/.*@-DU3_CPU_DEBUG' +build:snp_dbg --per_file_copt='pkg/.*@-DU3_SNAPSHOT_VALIDATION' + +# Any personal configuration should go in .user.bazelrc. +try-import %workspace%/.user.bazelrc diff --git a/BUILD.bazel b/BUILD.bazel new file mode 100644 index 0000000000..730fe0ec81 --- /dev/null +++ b/BUILD.bazel @@ -0,0 +1,214 @@ +load("//bazel:common_settings.bzl", "string_flag") +exports_files(["PACE"]) + +# +# OS-CPU CONFIG SETTINGS +# + +config_setting( + name = "linux_aarch64", + constraint_values = [ + "@platforms//os:linux", + "@platforms//cpu:aarch64", + ], +) + +config_setting( + name = "linux_x86_64", + constraint_values = [ + "@platforms//os:linux", + "@platforms//cpu:x86_64", + ], +) + +config_setting( + name = "macos_aarch64", + constraint_values = [ + "@platforms//os:macos", + "@platforms//cpu:aarch64", + ], +) + +config_setting( + name = "macos_x86_64", + constraint_values = [ + "@platforms//os:macos", + "@platforms//cpu:x86_64", + ], +) + +# +# CONFIGS DETAILING WHEN TO ENABLE CERTAIN FEATURES BY DEFAULT. +# CHANGES BEHAVIOR OF //bazel/common_settings.bzl:vere_library. +# + +config_setting( + name = "thinlto", + constraint_values = [ + "@platforms//os:macos", + ], + values = { + "compilation_mode": "opt" + } +) + +config_setting( + name = "lto", + constraint_values = [ + "@platforms//os:linux", + ], + values = { + "compilation_mode": "opt" + } +) + +config_setting( + name = "debug", + values = { + "compilation_mode": "dbg" + } +) + +# +# COMPILERS +# + +# Version flag for clang. +string_flag( + name = "clang_version", + # macOS uses `clang-15.0.0` by default. + build_setting_default = "15.0.0", + visibility = ["//visibility:public"], +) + +# Version flag for gcc. +string_flag( + name = "gcc_version", + # musl-cross-make uses `gcc-11.4.0` by default. + build_setting_default = "11.4.0", + visibility = ["//visibility:public"], +) + +# +# PLATFORMS +# +# A platform takes one of two formats: `--` or `-` +# if the compiler is unspecified. + +# Linux aarch64 platform with unspecified compiler. +platform( + name = "linux-aarch64", + constraint_values = [ + "@platforms//os:linux", + "@platforms//cpu:aarch64", + ], +) + +# 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 gcc. +platform( + name = "gcc-linux-x86_64", + constraint_values = [ + ":gcc", + "@platforms//os:linux", + "@platforms//cpu:x86_64", + ], +) + +platform( + name = "macos-aarch64", + constraint_values = [ + "@platforms//os:macos", + "@platforms//cpu:aarch64", + ], +) + +platform( + name = "clang-macos-aarch64", + constraint_values = [ + ":clang", + "@platforms//os:macos", + "@platforms//cpu:aarch64", + ], +) + +platform( + name = "macos-x86_64", + constraint_values = [ + "@platforms//os:macos", + "@platforms//cpu:x86_64", + ], +) + +platform( + name = "clang-macos-x86_64", + constraint_values = [ + ":clang", + "@platforms//os:macos", + "@platforms//cpu:x86_64", + ], +) + +# Produce the `U3_VERE_PACE` macro. +genrule( + name = "pace_hdr", + srcs = ["PACE"], + outs = ["pace.h"], + cmd = """ + echo '#ifndef URBIT_PACE_H' > $@ + echo '#define URBIT_PACE_H' >> $@ + printf '#define U3_VERE_PACE "%s"\n' $$(cat $< | tr -d '\n') >> $@ + echo '#endif' >> $@ + """, + visibility = ["//:__subpackages__"], +) + +genrule( + name = "version_str", + srcs = [ + # Bazel warns dependency checking directories is unsound, but there's no + # apparent way around depending on .git if we want to run git commands. + ".git", + "PACE", + "VERSION", + ], + outs = ["version"], + cmd = """ + version_num=$$(cat $(execpath VERSION) | tr -d '\n') + commit_sha=$$(git rev-parse --short HEAD) + if [ $$(tr -d '\n' < $(execpath PACE)) == "live" ]; then + version="$$version_num" + else + version="$$version_num-$$commit_sha" + fi + echo -n $$version > $@ + """, + visibility = ["//:__subpackages__"], +) + +# Produce the `URBIT_VERSION` macro. +genrule( + name = "version_hdr", + srcs = [":version_str"], + outs = ["version.h"], + cmd = """ + echo '#ifndef URBIT_VERSION_H' > $@ + echo '#define URBIT_VERSION_H' >> $@ + printf '#define URBIT_VERSION "%s"\n' $$(cat $< | tr -d '\n') >> $@ + echo '#endif' >> $@ + """, + visibility = ["//:__subpackages__"], +) + +alias( + name = "urbit", + actual = "//pkg/vere:urbit", +) diff --git a/PACE b/PACE new file mode 100644 index 0000000000..b2d1a7762f --- /dev/null +++ b/PACE @@ -0,0 +1 @@ +once diff --git a/VERSION b/VERSION new file mode 100644 index 0000000000..8c50098d8a --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +3.1 diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel new file mode 100644 index 0000000000..e12aa50f5d --- /dev/null +++ b/WORKSPACE.bazel @@ -0,0 +1,448 @@ +# BUMPING A DEPENDENCY VERSION +# +# The general process for bumping the version of a dependency is as follows: +# +# (1) Update the `version` attribute in the dependency's repository rule (likely +# `versioned_http_archive()` or `versioned_http_file()`. +# (2) Download the source code of the new version of the dependency using +# the specified `url` attribute (substituting `{version}` with the actual +# version you're updating to in the URL). +# (3) Compute the SHA-256 hash of the new version's tarball (or zip archive) +# using `openssl`: +# ``` +# $ openssl dgst -sha256 +# ``` +# (4) Update the `sha256` attribute in the dependency's repository rule with the +# SHA-256 hash from (3). +# (5) Run `bazel clean` to ensure that Bazel removes the old version of the +# dependency. +# +# If a dependency has documention specific to that dependency that conflicts +# with the process described above, adhere to the dependency-specific +# documentation. +# +# UPDATING A DEPENDENCY'S BUILD FILE +# +# It's unlikely that you'll need to update a dependency's build file, but if you +# do, you presumably know what you're doing. Nonetheless, here are a few useful +# bits of non-obvious information: +# +# - Build logic for a dependency resides within its `.BUILD` file. +# `BUILD.bazel` is also present in the dependency's directory in +# `third_party/` to mark the directory as a package. Ideally, the logic in +# `.BUILD` would live in `BUILD.bazel`, but Bazel 5.3.1 cannot +# find the source files of the dependency when `BUILD.bazel` holds the build +# logic (at least on my machine - ThinkPad X1 Carbon Gen 9, Arch Linux). +# - Whenever possible, avoid delegating to foreign build systems. Delegating is +# 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,AARCH64}`. +# (b) OS macros: `URBIT_RUNTIME_OS_{LINUX,DARWIN,BSD,MINGW}`. +# (2) Generate a patch file named .patch and save it in +# `bazel/third_party/`. +# (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/:.patch"]`. + +load("//bazel:repo.bzl", "versioned_http_archive", "versioned_http_file") + +# +# RULES REPOSITORIES +# + +versioned_http_archive( + name = "bazel_skylib", + sha256 = "74d544d96f4a5bb630d465ca8bbcfe231e3594e5aae57e1edbf17a6eb3ca2506", + url = "https://github.com/bazelbuild/bazel-skylib/releases/download/{version}/bazel-skylib-{version}.tar.gz", + version = "1.3.0", +) + +versioned_http_archive( + name = "rules_cc", + sha256 = "af6cc82d87db94585bceeda2561cb8a9d55ad435318ccb4ddfee18a43580fb5d", + strip_prefix = "rules_cc-{version}", + url = "https://github.com/bazelbuild/rules_cc/releases/download/{version}/rules_cc-{version}.tar.gz", + version = "0.0.4", +) + +versioned_http_archive( + name = "rules_foreign_cc", + sha256 = "2a4d07cd64b0719b39a7c12218a3e507672b82a97b98c6a89d38565894cf7c51", + strip_prefix = "rules_foreign_cc-{version}", + url = "https://github.com/bazelbuild/rules_foreign_cc/archive/refs/tags/{version}.tar.gz", + version = "0.9.0", +) + +# +# TOOLCHAINS SETUP +# + +# Use the toolchains we've configured. +register_toolchains( + "//bazel/toolchain:gcc-linux-aarch64-toolchain", + "//bazel/toolchain:clang-macos-aarch64-toolchain", + "//bazel/toolchain:clang-macos-x86_64-toolchain", + "//bazel/toolchain:gcc-linux-x86_64-toolchain", +) + +load("@rules_foreign_cc//foreign_cc:repositories.bzl", "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 +# + +versioned_http_archive( + name = "aes_siv", + build_file = "//bazel/third_party/aes_siv:aes_siv.BUILD", + sha256 = "1916a428dff480e06b09dc0fb1c9d849c048f838dc9b8d141452233b508f6bb1", + strip_prefix = "libaes_siv-{version}", + url = "https://github.com/dfoxfranke/libaes_siv/archive/{version}.tar.gz", + version = "9681279cfaa6e6399bb7ca3afbbc27fc2e19df4b", +) + +versioned_http_archive( + name = "avahi", + build_file = "//bazel/third_party/avahi:avahi.BUILD", + sha256 = "060309d7a333d38d951bc27598c677af1796934dbd98e1024e7ad8de798fedda", + strip_prefix = "avahi-{version}", + url = "https://github.com/lathiat/avahi/releases/download/v{version}/avahi-{version}.tar.gz", + version = "0.8", +) + +versioned_http_archive( + name = "bazel_gazelle", + sha256 = "efbbba6ac1a4fd342d5122cbdfdb82aeb2cf2862e35022c752eaddffada7c3f3", + url = "https://github.com/bazelbuild/bazel-gazelle/releases/download/v{version}/bazel-gazelle-v{version}.tar.gz", + version = "0.27.0", +) + +# See https://curl.se/docs/caextract.html. +versioned_http_file( + name = "ca_bundle", + sha256 = "2cff03f9efdaf52626bd1b451d700605dc1ea000c5da56bd0fc59f8f43071040", + url = "https://curl.se/ca/cacert-{version}.pem", + version = "2022-10-11", +) + +versioned_http_archive( + name = "curl", + build_file = "//bazel/third_party/curl:curl.BUILD", + sha256 = "78a06f918bd5fde3c4573ef4f9806f56372b32ec1829c9ec474799eeee641c27", + strip_prefix = "curl-{version}", + url = "https://curl.se/download/curl-{version}.tar.gz", + version = "7.85.0", +) + +versioned_http_archive( + name = "dbus", + build_file = "//bazel/third_party/dbus:dbus.BUILD", + sha256 = "a6bd5bac5cf19f0c3c594bdae2565a095696980a683a0ef37cb6212e093bde35", + strip_prefix = "dbus-{version}", + url = "https://src.fedoraproject.org/repo/pkgs/dbus/dbus-{version}.tar.xz/sha512/f3dfc73da28cbe20449d15bbe4166c3574f0e551dfd15fca7cce2b8c71e778360ed2dd391ee5c414a7a47ff4b958727b26ef4cabfee70564f8d0a34bf5ad2386/dbus-1.14.8.tar.xz", + version = "1.14.8", +) + +versioned_http_archive( + name = "expat", + build_file = "//bazel/third_party/expat:expat.BUILD", + strip_prefix = "expat-{version}", + sha256 = "ef2420f0232c087801abf705e89ae65f6257df6b7931d37846a193ef2e8cdcbe", + # TODO: fix the R_2_5_0 nonsense + url = "https://github.com/libexpat/libexpat/releases/download/R_2_5_0/expat-{version}.tar.xz", + version = "2.5.0", +) + +versioned_http_archive( + name = "gmp", + build_file = "//bazel/third_party/gmp:gmp.BUILD", + sha256 = "fb776e19e0267053c3d6ffef0dcc001fb441da0e2b5224cfd9656aa2f1b8614d", + strip_prefix = "GMP-{version}", + url = "https://github.com/alisw/GMP/archive/refs/tags/v{version}.tar.gz", + version = "6.2.1", +) + +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", + # When bumping the version, compare `CMakeLists.txt` in the `h2o` repo to + # {build_file} and confirm that {build_file} remains an accurate description + # of the h2o build process. + version = "2.2.6", +) + +versioned_http_archive( + name = "io_bazel_rules_docker", + sha256 = "b1e80761a8a8243d03ebca8845e9cc1ba6c82ce7c5179ce2b295cd36f7e394bf", + url = "https://github.com/bazelbuild/rules_docker/releases/download/v{version}/rules_docker-v{version}.tar.gz", + version = "0.25.0", +) + +versioned_http_archive( + name = "io_bazel_rules_go", + sha256 = "d6ab6b57e48c09523e93050f13698f708428cfd5e619252e369d377af6597707", + url = "https://github.com/bazelbuild/rules_go/releases/download/v{version}/rules_go-v{version}.zip", + version = "0.43.0", +) + +versioned_http_file( + name = "ivory_pill", + sha256 = "26ff86808886beb831e4a135f478e42ce83ef4a09ad24808b3fe97248ce7a6b7", + url = "https://github.com/urbit/urbit/blob/{version}/bin/ivory.pill?raw=true", + version = "721fa05", +) + +versioned_http_archive( + name = "natpmp", + build_file = "//bazel/third_party/natpmp:natpmp.BUILD", + sha256 = "0684ed2c8406437e7519a1bd20ea83780db871b3a3a5d752311ba3e889dbfc70", + strip_prefix = "libnatpmp-{version}", + url = "http://download.openpkg.org/components/cache/libnatpmp/libnatpmp-{version}.tar.gz", + version = "20230423", +) + +versioned_http_file( + name = "solid_pill", + sha256 = "8b658fcee6978e2b19004a54233cab953e77ea0bb6c3a04d1bfda4ddc6be63c5", + url = "https://github.com/urbit/urbit/raw/{version}/bin/solid.pill", + version = "255fb1ca8206072f1d09425f0db61ecfe7ff5b17", +) + +versioned_http_archive( + name = "libbacktrace", + build_file = "//bazel/third_party/libbacktrace:libbacktrace.BUILD", + sha256 = "609c17352ec38eaf5ff6618fcbfb38cd8fa0e94a15a0d9aa259df514bbf47fcd", + url = "https://github.com/ianlancetaylor/libbacktrace/archive/{version}.tar.gz", + strip_prefix = "libbacktrace-{version}", + version = "4ead348bb45f753121ca0bd44170ff8352d4c514", +) + +versioned_http_archive( + name = "libunwind", + build_file = "//bazel/third_party/libunwind:libunwind.BUILD", + sha256 = "ddf0e32dd5fafe5283198d37e4bf9decf7ba1770b6e7e006c33e6df79e6a6157", + url = "https://github.com/libunwind/libunwind/releases/download/v1.8.1/libunwind-1.8.1.tar.gz", + strip_prefix = "libunwind-{version}", + version = "1.8.1", +) + +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", + # When bumping the version, compare `libraries/liblmdb/Makefile` in the + # `lmdb` repo to {build_file} and confirm that {build_file} remains an + # accurate description of the lmdb build process. + version = "0.9.29", +) + +versioned_http_archive( + name = "murmur3", + build_file = "//bazel/third_party/murmur3:murmur3.BUILD", + sha256 = "d81836605204df2db9e0c095423b2856073d1b2ef900463151d0663b7ca3164f", + strip_prefix = "murmur3-{version}", + url = "https://github.com/PeterScott/murmur3/archive/{version}.tar.gz", + # When bumping the version, compare `makefile` in the `murmur3` repo to + # {build_file} and confirm that {build_file} remains an accurate description + # of the murmur3 build process. + version = "dae94be0c0f54a399d23ea6cbe54bca5a4e93ce4", +) + +versioned_http_archive( + name = "openssl", + build_file = "//bazel/third_party/openssl:openssl.BUILD", + sha256 = "cf3098950cb4d853ad95c0841f1f9c6d3dc102dccfcacd521d93925208b76ac8", + strip_prefix = "openssl-{version}", + url = "https://github.com/openssl/openssl/releases/download/OpenSSL_1_1_1w/openssl-{version}.tar.gz", + version = "1.1.1w", +) + +versioned_http_archive( + name = "pdjson", + build_file = "//bazel/third_party/pdjson:pdjson.BUILD", + sha256 = "928913d44d9021d69c0d23a8f59ed67028e5abf1ae7910f79c23a7af4e779b92", + strip_prefix = "pdjson-{version}", + url = "https://github.com/skeeto/pdjson/archive/{version}.tar.gz", + # When bumping the version, compare `Makefile` in the `pdjson` repo to + # {build_file} and confirm that {build_file} remains an accurate description + # of the pdjson build process. + version = "67108d883061043e55d0fb13961ac1b6fc8a485c", +) + +versioned_http_archive( + name = "secp256k1", + build_file = "//bazel/third_party/secp256k1:secp256k1.BUILD", + sha256 = "5f6e4a66bf8f3c318d91eacbf3262d1cd81a3fda6bb9af267b54cf38ffd44b1c", + strip_prefix = "secp256k1-{version}", + url = "https://github.com/bitcoin-core/secp256k1/archive/{version}.tar.gz", + version = "694ce8fb2d1fd8a3d641d7c33705691d41a2a860", + patch_args = ["-p1"], + patches = ["//bazel/third_party/secp256k1:{version}.patch"], +) + +versioned_http_archive( + name = "sigsegv", + build_file = "//bazel/third_party/sigsegv:sigsegv.BUILD", + sha256 = "cdac3941803364cf81a908499beb79c200ead60b6b5b40cad124fd1e06caa295", + strip_prefix = "libsigsegv-{version}", + url = "https://ftp.gnu.org/gnu/libsigsegv/libsigsegv-{version}.tar.gz", + version = "2.14", +) + +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", + # When bumping the version, compare `build//Makefile` in the + # `softfloat` repo to {build_file} and compare that {build_file} remains an + # accurate description of the softfloat process for *all* supported + # ``s. + 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_file( + name = "urbit", + sha256 = "a729d8b3c438fef33f5ae8c4da8d84ebdb5af5ad028d41696a92cddc8bf362a8", + url = "https://github.com/urbit/urbit/archive/{version}.tar.gz", + # We can't use a branch name for the `version` because each new commit + # will change the SHA256 hash. + version = "ea8fee3aa0434d4bdf1bf785e5ec346c7ecba7fd", +) + +versioned_http_archive( + name = "urcrypt", + build_file = "//bazel/third_party/urcrypt:urcrypt.BUILD", + sha256 = "d27ec04d3854da7c479dd815af92ffef986616bc7ff400022e2dfb7971853d86", + strip_prefix = "urcrypt-{version}", + url = "https://github.com/urbit/urcrypt/archive/{version}.tar.gz", + version = "9ae5d604528bc54ae48430f55ebbb17b1ad7956c", +) + +versioned_http_archive( + name = "uv", + build_file = "//bazel/third_party/uv:uv.BUILD", + sha256 = "ccfcdc968c55673c6526d8270a9c8655a806ea92468afcbcabc2b16040f03cb4", + strip_prefix = "libuv-v{version}", + url = "https://dist.libuv.org/dist/v{version}/libuv-v{version}.tar.gz", + version = "1.44.2", +) + +versioned_http_archive( + name = "whereami", + build_file = "//bazel/third_party/whereami:whereami.BUILD", + sha256 = "1d8744177f37e8386ec2f6c5992592399040cb93535ed4fd253e1976f889a744", + strip_prefix = "whereami-{version}", + url = "https://github.com/gpakosz/whereami/archive/{version}.tar.gz", + version = "ba364cd54fd431c76c045393b6522b4bff547f50", +) + +versioned_http_archive( + name = "zlib", + build_file = "//bazel/third_party/zlib:zlib.BUILD", + sha256 = "9a93b2b7dfdac77ceba5a558a580e74667dd6fede4585b91eefb60f03b72df23", + strip_prefix = "zlib-{version}", + url = "https://www.zlib.net/zlib-{version}.tar.gz", + version = "1.3.1", +) + +# +# HEDRON COMPILE COMMANDS SETUP +# + +# Hedron's Compile Commands Extractor for Bazel +# https://github.com/hedronvision/bazel-compile-commands-extractor +versioned_http_archive( + name = "hedron_compile_commands", + strip_prefix = "bazel-compile-commands-extractor-{version}", + sha256 = "d7ba7708816132f86f02864b9dba0c5abf249cc0fb035a34c430e4e538c87867", + url = "https://github.com/hedronvision/bazel-compile-commands-extractor/archive/{version}.tar.gz", + version = "d3afb5dfadd4beca48bb027112d029f2d34ff0a0", +) + +load("@hedron_compile_commands//:workspace_setup.bzl", "hedron_compile_commands_setup") + +hedron_compile_commands_setup() + +# +# DOCKER SETUP +# + +# These must be loaded before the Docker rules. +# See https://github.com/bazelbuild/rules_docker/issues/2075#issuecomment-1115954091. +load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") +load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") + +go_rules_dependencies() + +go_register_toolchains(version = "1.18") + +gazelle_dependencies(go_repository_default_config = "//:WORKSPACE.bazel") + +load( + "@io_bazel_rules_docker//repositories:repositories.bzl", + _container_repositories = "repositories", +) +load("@io_bazel_rules_docker//repositories:deps.bzl", _container_deps = "deps") +load("@io_bazel_rules_docker//cc:image.bzl", _cc_image_repos = "repositories") + +_container_repositories() + +_container_deps( + # See https://github.com/bazelbuild/rules_docker/issues/1902. + go_repository_default_config = "@//:WORKSPACE.bazel", +) + +_cc_image_repos() + +load("@io_bazel_rules_docker//container:container.bzl", "container_pull") + +container_pull( + name = "alpine_linux_x86_64", + timeout = 300, # [seconds] + architecture = "amd64", + digest = "sha256:93d5a28ff72d288d69b5997b8ba47396d2cbb62a72b5d87cd3351094b5d578a0", + registry = "docker.io", + repository = "alpine", +) diff --git a/bazel/BUILD.bazel b/bazel/BUILD.bazel new file mode 100644 index 0000000000..5ac74d0b96 --- /dev/null +++ b/bazel/BUILD.bazel @@ -0,0 +1,21 @@ +load("@hedron_compile_commands//:refresh_compile_commands.bzl", "refresh_compile_commands") + +# gazelle:exclude external + +refresh_compile_commands( + name = "refresh_compile_commands", + + # Specify the targets of interest. + # For example, specify a dict of targets and any flags required to build. + targets = [ + "//pkg/ent", + "//pkg/noun", + "//pkg/ur", + "//pkg/vere:urbit", + ], + # No need to add flags already in .bazelrc. They're automatically picked up. + # If you don't need flags, a list of targets is also okay, as is a single target string. + # Wildcard patterns, like //... for everything, *are* allowed here, just like a build. + # As are additional targets (+) and subtractions (-), like in bazel query https://docs.bazel.build/versions/main/query.html#expressions + # And if you're working on a header-only library, specify a test or binary target that compiles it. +) diff --git a/bazel/common_settings.bzl b/bazel/common_settings.bzl new file mode 100644 index 0000000000..9ec74beda5 --- /dev/null +++ b/bazel/common_settings.bzl @@ -0,0 +1,50 @@ +# 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", +) + +def vere_library(copts = [], linkopts = [], **kwargs): + native.cc_library( + copts = copts + [ + "-fno-omit-frame-pointer", + ] + select({ + "//:debug": ["-O0", "-g3", "-DC3DBG", "-fdebug-compilation-dir=."], + "//conditions:default": ["-O3", "-g"] + }) + select({ + "//:lto": ['-flto'], + "//conditions:default": [] + }), + linkopts = linkopts + ['-g'] + select({ + "//:lto": ['-flto'], + "//:thinlto": ['-flto=thin'], + "//conditions:default": [] + }), + **kwargs, + ) + +def vere_binary(copts = [], linkopts = [], **kwargs): + native.cc_binary( + copts = copts + [ + "-fno-omit-frame-pointer", + ] + select({ + "//:debug": ["-O0", "-g3", "-DC3DBG", "-fdebug-compilation-dir=."], + "//conditions:default": ["-O3", "-g"] + }) + select({ + "//:lto": ['-flto'], + "//conditions:default": [] + }), + linkopts = linkopts + ['-g'] + select({ + "//:lto": ['-flto'], + "//:thinlto": ['-flto=thin'], + "//conditions:default": [] + }), + **kwargs, + ) diff --git a/bazel/repo.bzl b/bazel/repo.bzl new file mode 100644 index 0000000000..2c2eb1bb1f --- /dev/null +++ b/bazel/repo.bzl @@ -0,0 +1,34 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file") +load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") + +# Adds a `version` attribute to `http_archive`. +def versioned_http_archive(name, version, **kwargs): + if kwargs.get("url") != None: + kwargs["url"] = kwargs["url"].format(version = version) + + if kwargs.get("urls") != None: + for index, url in enumerate(kwargs["urls"]): + kwargs["urls"][index] = url.format(version = version) + + if kwargs.get("patches") != None: + for index, patch in enumerate(kwargs["patches"]): + kwargs["patches"][index] = patch.format(version = version) + + if kwargs.get("strip_prefix") != None: + kwargs["strip_prefix"] = kwargs["strip_prefix"].format(version = version) + + maybe(http_archive, name, **kwargs) + +# Adds a `version` attribute to `http_file`. +def versioned_http_file(name, version, **kwargs): + if kwargs.get("url") != None: + kwargs["url"] = kwargs["url"].format(version = version) + + if kwargs.get("urls") != None: + for index, url in enumerate(kwargs["urls"]): + kwargs["urls"][index] = url.format(version = version) + + if kwargs.get("strip_prefix") != None: + kwargs["strip_prefix"] = kwargs["strip_prefix"].format(version = version) + + maybe(http_file, name, **kwargs) diff --git a/bazel/third_party/aes_siv/BUILD.bazel b/bazel/third_party/aes_siv/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/bazel/third_party/aes_siv/aes_siv.BUILD b/bazel/third_party/aes_siv/aes_siv.BUILD new file mode 100644 index 0000000000..1cb6d7469f --- /dev/null +++ b/bazel/third_party/aes_siv/aes_siv.BUILD @@ -0,0 +1,21 @@ +genrule( + name = "config", + srcs = ["config.h.in"], + outs = ["config.h"], + # The options in config.h.in only affect libaes_siv's testing behavior, so + # it's sufficient to generate an empty config.h. + cmd = "touch $@", +) + +cc_library( + name = "aes_siv", + srcs = [ + "aes_siv.c", + "config.h", + ], + hdrs = ["aes_siv.h"], + copts = ["-O3"], + includes = ["."], + visibility = ["//visibility:public"], + deps = ["@openssl"], +) diff --git a/bazel/third_party/argon2/BUILD.bazel b/bazel/third_party/argon2/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/bazel/third_party/argon2/argon2.BUILD b/bazel/third_party/argon2/argon2.BUILD new file mode 100644 index 0000000000..ebfc7d5f3c --- /dev/null +++ b/bazel/third_party/argon2/argon2.BUILD @@ -0,0 +1,42 @@ +cc_library( + name = "argon2", + srcs = [ + "src/argon2.c", + "src/blake2/blake2-impl.h", + "src/blake2/blake2b.c", + "src/core.c", + "src/core.h", + "src/encoding.c", + "src/encoding.h", + "src/thread.c", + "src/thread.h", + ] + select({ + # `opt.c` requires SSE instructions. See `Makefile` in the `argon2` repo + # for the check used to determine whether to use `opt.c` or `ref.c`. + "@platforms//cpu:x86_64": [ + "src/blake2/blamka-round-opt.h", + "src/opt.c", + ], + "//conditions:default": [ + "src/blake2/blamka-round-ref.h", + "src/ref.c", + ], + }), + hdrs = [ + "include/argon2.h", + "src/blake2/blake2.h", + ], + copts = [ + "-std=c89", + "-O3", + "-Wall", + "-g", + "-Isrc", + "-DARGON2_NO_THREADS", + ], + includes = [ + "include", + "src/blake2", + ], + visibility = ["//visibility:public"], +) diff --git a/bazel/third_party/avahi/BUILD.bazel b/bazel/third_party/avahi/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/bazel/third_party/avahi/avahi.BUILD b/bazel/third_party/avahi/avahi.BUILD new file mode 100644 index 0000000000..2c0896f32d --- /dev/null +++ b/bazel/third_party/avahi/avahi.BUILD @@ -0,0 +1,30 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +filegroup( + name = "all", + srcs = glob(["**"]), +) + +cc_library( + name = "dns-sd", + hdrs = ["dns_sd.h"], + visibility = ["//visibility:public"], +) + +configure_make( + name = "avahi", + args = select({ + "@platforms//os:macos": ["--jobs=`sysctl -n hw.logicalcpu`"], + "//conditions:default": ["--jobs=`nproc`"], + }), + configure_options = ["--with-dbus-system-address='unix:path=/var/run/dbus/system_bus_socket' --with-xml=none --disable-libevent --disable-glib --disable-gobject --disable-gdbm --disable-qt3 --disable-qt4 --disable-qt5 --disable-gtk --disable-gtk3 --disable-mono --disable-monodoc --disable-python --disable-libdaemon --enable-compat-libdns_sd --disable-rpath --with-distro=none"], + lib_source = ":all", + # out_include_dir = "avahi-compat-libdns_sd", + deps = ["@dbus"], + configure_in_place = True, + autogen = True, + autoconf = True, + autogen_command = "bootstrap.sh", + out_static_libs = ["libdns_sd.a", "libavahi-client.a", "libavahi-common.a"], + visibility = ["//visibility:public"], +) diff --git a/bazel/third_party/curl/BUILD.bazel b/bazel/third_party/curl/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/bazel/third_party/curl/curl.BUILD b/bazel/third_party/curl/curl.BUILD new file mode 100644 index 0000000000..c66424d52e --- /dev/null +++ b/bazel/third_party/curl/curl.BUILD @@ -0,0 +1,67 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +filegroup( + name = "all", + srcs = glob(["**"]), +) + +configure_make( + name = "curl", + args = select({ + "@platforms//os:macos": ["--jobs=`sysctl -n hw.logicalcpu`"], + "//conditions:default": ["--jobs=`nproc`"], + }), + # We disable unneeded features. + # TODO: double check that all disabled features below are in fact unneeded. + configure_options = [ + "--disable-alt-svc", + "--disable-ares", + "--disable-cookies", + "--disable-crypto-auth", + "--disable-dateparse", + "--disable-dnsshuffle", + "--disable-doh", + "--disable-get-easy-options", + "--disable-hsts", + "--disable-http-auth", + "--disable-ipv6", + "--disable-ldap", + "--disable-libcurl-option", + "--disable-manual", + "--disable-shared", + "--disable-netrc", + "--disable-ntlm-wb", + "--disable-progress-meter", + "--disable-proxy", + "--disable-pthreads", + "--disable-socketpair", + "--disable-threaded-resolver", + "--disable-tls-srp", + "--disable-unix-sockets", + "--disable-verbose", + "--disable-versioned-symbols", + "--enable-static", + # Use our openssl, not the system's openssl. + "--with-openssl=$URBIT_RUNTIME_OPENSSL", + "--without-brotli", + "--without-libidn2", + "--without-libpsl", + "--without-librtmp", + "--without-nghttp2", + "--without-ngtcp2", + "--without-zlib", + "--without-zstd", + ] + select({ + "@//:linux_aarch64": ["--host=aarch64-linux-musl"], + "@//:linux_x86_64": ["--host=x86_64-linux-musl"], + "//conditions:default": [], + }), + copts = ["-O3"], + env = { + "URBIT_RUNTIME_OPENSSL": "$$PWD/$(GENDIR)/external/openssl/openssl", + }, + lib_source = ":all", + out_static_libs = ["libcurl.a"], + visibility = ["//visibility:public"], + deps = ["@openssl"], +) diff --git a/bazel/third_party/dbus/BUILD.bazel b/bazel/third_party/dbus/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/bazel/third_party/dbus/dbus.BUILD b/bazel/third_party/dbus/dbus.BUILD new file mode 100644 index 0000000000..25fd750092 --- /dev/null +++ b/bazel/third_party/dbus/dbus.BUILD @@ -0,0 +1,21 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +filegroup( + name = "all", + srcs = glob(["**"]), +) + +configure_make( + name = "dbus", + lib_name = "libdbus-1", + args = select({ + "@platforms//os:macos": ["--jobs=`sysctl -n hw.logicalcpu`"], + "//conditions:default": ["--jobs=`nproc`"], + }), + copts = ["-O3"], + configure_options = ["--disable-selinux --without-x --disable-tests --disable-systemd --disable-apparmor"], + lib_source = ":all", + configure_in_place = True, + deps = ["@expat"], + visibility = ["//visibility:public"], +) diff --git a/bazel/third_party/ed25519/BUILD.bazel b/bazel/third_party/ed25519/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/bazel/third_party/ed25519/ed25519.BUILD b/bazel/third_party/ed25519/ed25519.BUILD new file mode 100644 index 0000000000..172752ca25 --- /dev/null +++ b/bazel/third_party/ed25519/ed25519.BUILD @@ -0,0 +1,14 @@ +cc_library( + name = "ed25519", + srcs = glob( + [ + "src/*.c", + "src/*.h", + ], + exclude = ["src/ed25519.h"], + ), + hdrs = ["src/ed25519.h"], + copts = ["-O3"], + includes = ["src"], + visibility = ["//visibility:public"], +) diff --git a/bazel/third_party/expat/BUILD.bazel b/bazel/third_party/expat/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/bazel/third_party/expat/expat.BUILD b/bazel/third_party/expat/expat.BUILD new file mode 100644 index 0000000000..1c0a6bc36d --- /dev/null +++ b/bazel/third_party/expat/expat.BUILD @@ -0,0 +1,24 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +filegroup( + name = "all", + srcs = glob(["**"]), +) + +configure_make( + name = "expat", + args = select({ + "@platforms//os:macos": ["--jobs=`sysctl -n hw.logicalcpu`"], + "//conditions:default": ["--jobs=`nproc`"], + }), + configure_options = [ + ] + select({ + "@//:linux_aarch64": ["--host=aarch64-linux-musl"], + "@//:linux_x86_64": ["--host=x86_64-linux-musl"], + "//conditions:default": [], + }), + copts = ["-O3"], + lib_source = ":all", + out_static_libs = ["libexpat.a"], + visibility = ["//visibility:public"], +) diff --git a/bazel/third_party/gmp/BUILD.bazel b/bazel/third_party/gmp/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/bazel/third_party/gmp/gmp.BUILD b/bazel/third_party/gmp/gmp.BUILD new file mode 100644 index 0000000000..25ef1db6a4 --- /dev/null +++ b/bazel/third_party/gmp/gmp.BUILD @@ -0,0 +1,30 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +filegroup( + name = "all", + srcs = glob(["**"]), +) + +configure_make( + name = "gmp", + args = select({ + "@platforms//os:macos": ["--jobs=`sysctl -n hw.logicalcpu`"], + "//conditions:default": ["--jobs=`nproc`"], + }), + configure_options = [ + "--disable-shared", + # NOTE: --with-pic is required to build PIE binaries on macos_x86_64, + # but we leave it in for all builds as a precaution. + "--with-pic", + ] + select({ + "@//:linux_aarch64": ["--host=aarch64-linux-musl"], + "@//:linux_x86_64": ["--host=x86_64-linux-musl"], + # See https://gmplib.org/list-archives/gmp-bugs/2023-January/005228.html. + "@//:macos_aarch64": ["--disable-assembly"], + "//conditions:default": [], + }), + copts = ["-O3"], + 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..c04571f7ad --- /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_CPU_AARCH64) ++#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_CPU_AARCH64) ++#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_CPU_AARCH64) ++#include "sse2neon.h" ++#elif defined(_MSC_VER) + #include + #else + #include diff --git a/bazel/third_party/h2o/BUILD.bazel b/bazel/third_party/h2o/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/bazel/third_party/h2o/h2o.BUILD b/bazel/third_party/h2o/h2o.BUILD new file mode 100644 index 0000000000..84b1f9b738 --- /dev/null +++ b/bazel/third_party/h2o/h2o.BUILD @@ -0,0 +1,375 @@ +# This build file is derived from `CMakeLists.txt` in the `h2o` repo at +# https://github.com/h2o/h2o. + +# See `CC_WARNING_FLAGS` in `CMakeLists.txt` in the `h2o` repo. +CC_WARNING_FLAGS = [ + "-Wall", + "-Wno-unused-value", + "-Wno-unused-function", + "-Wno-nullability-completeness", + "-Wno-expansion-to-defined", + "-Werror=implicit-function-declaration", + "-Werror=incompatible-pointer-types", +] + +# +# H2O DEPENDENCIES +# + +# See `deps/cloxec` in the `h2o` repo. +cc_library( + name = "cloexec", + srcs = ["deps/cloexec/cloexec.c"], + hdrs = ["deps/cloexec/cloexec.h"], + copts = ["-O3"], + includes = ["deps/cloexec"], + linkstatic = True, + visibility = ["//visibility:private"], +) + +# See `deps/golombset` in the `h2o` repo. +cc_library( + name = "golombset", + hdrs = ["deps/golombset/golombset.h"], + copts = ["-O3"], + includes = ["deps/golombset"], + linkstatic = True, + visibility = ["//visibility:private"], +) + +# See `deps/klib` in the `h2o` repo. +cc_library( + name = "klib", + srcs = glob(["deps/klib/*.c"]), + hdrs = glob(["deps/klib/*.h"]), + copts = ["-O3"], + includes = ["deps/klib"], + linkstatic = True, + local_defines = select({ + "@platforms//cpu:aarch64": ["URBIT_RUNTIME_CPU_AARCH64"], + "//conditions:default": [], + }), + visibility = ["//visibility:private"], + deps = [ + "@curl", + "@zlib", + ] + select({ + "@platforms//cpu:aarch64": ["@sse2neon"], + "//conditions:default": [], + }), +) + +# See `deps/libgkc` in the `h2o` repo. +cc_library( + name = "libgkc", + srcs = ["deps/libgkc/gkc.c"], + hdrs = ["deps/libgkc/gkc.h"], + copts = ["-O3"], + includes = ["deps/libgkc"], + linkstatic = True, + visibility = ["//visibility:private"], +) + +# See `deps/libyrmcds` in the `h2o` repo. +cc_library( + name = "libyrmcds", + srcs = glob( + ["deps/libyrmcds/*.c"], + exclude = [ + "deps/libyrmcds/yc.c", + "deps/libyrmcds/yc-cnt.c", + ], + ) + [ + "deps/libyrmcds/yrmcds_portability.h", + "deps/libyrmcds/yrmcds_text.h", + ], + hdrs = ["deps/libyrmcds/yrmcds.h"], + copts = [ + "-Wall", + "-Wconversion", + "-gdwarf-3", + "-O2", + ], + includes = ["deps/libyrmcds"], + linkstatic = True, + visibility = ["//visibility:private"], +) + +# See `deps/picohttpparser` in the `h2o` repo. +cc_library( + name = "picohttpparser", + srcs = ["deps/picohttpparser/picohttpparser.c"], + hdrs = ["deps/picohttpparser/picohttpparser.h"], + copts = ["-O3"], + includes = ["deps/picohttpparser"], + linkstatic = True, + local_defines = select({ + "@platforms//cpu:aarch64": ["URBIT_RUNTIME_CPU_AARCH64"], + "//conditions:default": [], + }), + visibility = ["//visibility:private"], + deps = select({ + "@platforms//cpu:aarch64": ["@sse2neon"], + "//conditions:default": [], + }), +) + +# See `deps/picotls` in the `h2o` repo. +cc_library( + name = "picotls", + srcs = glob( + ["deps/picotls/lib/*.c"], + ), + hdrs = ["deps/picotls/include/picotls.h"] + glob( + ["deps/picotls/include/picotls/*.h"], + ), + copts = [ + "-std=c99", + "-Wall", + "-O2", + "-g", + ], + includes = [ + "deps/picotls/include", + "deps/picotls/include/picotls", + ], + linkstatic = True, + local_defines = select({ + "@platforms//cpu:aarch64": ["URBIT_RUNTIME_CPU_AARCH64"], + "//conditions:default": [], + }), + visibility = ["//visibility:private"], + deps = [ + ":cifra", + ":micro_ecc", + "@openssl", + ] + select({ + "@platforms//cpu:aarch64": ["@sse2neon"], + "//conditions:default": [], + }), +) + +# See `deps/ssl-conservatory` in the `h2o` repo. +cc_library( + name = "ssl_conservatory", + hdrs = ["deps/ssl-conservatory/openssl/openssl_hostname_validation.h"], + copts = ["-O3"], + includes = ["deps/ssl-conservatory/openssl"], + linkstatic = True, + textual_hdrs = ["deps/ssl-conservatory/openssl/openssl_hostname_validation.c"], + visibility = ["//visibility:private"], +) + +# See `deps/yoml` in the `h2o` repo. +cc_library( + name = "yoml", + hdrs = glob(["deps/yoml/*.h"]), + copts = ["-O3"], + includes = ["deps/yoml"], + linkstatic = True, + visibility = ["//visibility:private"], +) + +# +# PICOTLS DEPENDENCIES +# + +# See `deps/picotls/deps/cifra` in the `h2o` repo. +cc_library( + name = "cifra", + srcs = [ + "deps/picotls/deps/cifra/src/aes.c", + "deps/picotls/deps/cifra/src/sha256.c", + "deps/picotls/deps/cifra/src/sha512.c", + "deps/picotls/deps/cifra/src/chash.c", + "deps/picotls/deps/cifra/src/hmac.c", + "deps/picotls/deps/cifra/src/pbkdf2.c", + "deps/picotls/deps/cifra/src/modes.c", + "deps/picotls/deps/cifra/src/eax.c", + "deps/picotls/deps/cifra/src/gf128.c", + "deps/picotls/deps/cifra/src/blockwise.c", + "deps/picotls/deps/cifra/src/cmac.c", + "deps/picotls/deps/cifra/src/salsa20.c", + "deps/picotls/deps/cifra/src/chacha20.c", + "deps/picotls/deps/cifra/src/curve25519.c", + "deps/picotls/deps/cifra/src/gcm.c", + "deps/picotls/deps/cifra/src/cbcmac.c", + "deps/picotls/deps/cifra/src/ccm.c", + "deps/picotls/deps/cifra/src/sha3.c", + "deps/picotls/deps/cifra/src/sha1.c", + "deps/picotls/deps/cifra/src/poly1305.c", + "deps/picotls/deps/cifra/src/norx.c", + "deps/picotls/deps/cifra/src/chacha20poly1305.c", + "deps/picotls/deps/cifra/src/drbg.c", + "deps/picotls/deps/cifra/src/ocb.c", + ] + glob( + [ + "deps/picotls/deps/cifra/src/*.h", + "deps/picotls/deps/cifra/src/ext/*.h", + ], + exclude = ["deps/picotls/deps/cifra/src/ext/handy.h"], + ), + hdrs = glob( + [ + "deps/picotls/deps/cifra/src/*.h", + "deps/picotls/deps/cifra/src/ext/*.h", + ], + ), + copts = ["-O3"], + includes = [ + "deps/picotls/deps/cifra/src", + "deps/picotls/deps/cifra/src/ext", + ], + linkstatic = True, + textual_hdrs = ["deps/picotls/deps/cifra/src/curve25519.tweetnacl.c"], + visibility = ["//visibility:private"], +) + +# See `deps/picotls/deps/micro-ecc` in the `h2o` repo. +cc_library( + name = "micro_ecc", + srcs = [ + "deps/picotls/deps/micro-ecc/types.h", + "deps/picotls/deps/micro-ecc/uECC.c", + "deps/picotls/deps/micro-ecc/uECC_vli.h", + ], + hdrs = ["deps/picotls/deps/micro-ecc/uECC.h"], + copts = ["-O3"], + includes = ["deps/picotls/deps/micro-ecc"], + textual_hdrs = [ + "deps/picotls/deps/micro-ecc/asm_arm.inc", + "deps/picotls/deps/micro-ecc/asm_arm_mult_square.inc", + "deps/picotls/deps/micro-ecc/asm_arm_mult_square_umaal.inc", + "deps/picotls/deps/micro-ecc/asm_avr.inc", + "deps/picotls/deps/micro-ecc/asm_avr_mult_square.inc", + "deps/picotls/deps/micro-ecc/curve-specific.inc", + "deps/picotls/deps/micro-ecc/platform-specific.inc", + ], + visibility = ["//visibility:private"], +) + +cc_library( + name = "h2o", + # The `*.c` files below correspond to the files in `lib/` in + # `LIB_SOURCE_FILES` in `CMakeLists.txt` in the `h2o` repo. + # + # Files in `deps/` in `LIB_SOURCE_FILES` are in their respective library + # targets above. + srcs = [ + "lib/common/cache.c", + "lib/common/file.c", + "lib/common/filecache.c", + "lib/common/hostinfo.c", + "lib/common/http1client.c", + "lib/common/memcached.c", + "lib/common/memory.c", + "lib/common/multithread.c", + "lib/common/serverutil.c", + "lib/common/socket.c", + "lib/common/socketpool.c", + "lib/common/string.c", + "lib/common/time.c", + "lib/common/timeout.c", + "lib/common/url.c", + "lib/core/config.c", + "lib/core/configurator.c", + "lib/core/context.c", + "lib/core/headers.c", + "lib/core/logconf.c", + "lib/core/proxy.c", + "lib/core/request.c", + "lib/core/token.c", + "lib/core/util.c", + "lib/handler/access_log.c", + "lib/handler/chunked.c", + "lib/handler/compress.c", + "lib/handler/compress/gzip.c", + "lib/handler/configurator/access_log.c", + "lib/handler/configurator/compress.c", + "lib/handler/configurator/errordoc.c", + "lib/handler/configurator/expires.c", + "lib/handler/configurator/fastcgi.c", + "lib/handler/configurator/file.c", + "lib/handler/configurator/headers.c", + "lib/handler/configurator/headers_util.c", + "lib/handler/configurator/http2_debug_state.c", + "lib/handler/configurator/proxy.c", + "lib/handler/configurator/redirect.c", + "lib/handler/configurator/reproxy.c", + "lib/handler/configurator/status.c", + "lib/handler/configurator/throttle_resp.c", + "lib/handler/errordoc.c", + "lib/handler/expires.c", + "lib/handler/fastcgi.c", + "lib/handler/file.c", + "lib/handler/headers.c", + "lib/handler/headers_util.c", + "lib/handler/http2_debug_state.c", + "lib/handler/mimemap.c", + "lib/handler/proxy.c", + "lib/handler/redirect.c", + "lib/handler/reproxy.c", + "lib/handler/status.c", + "lib/handler/status/durations.c", + "lib/handler/status/events.c", + "lib/handler/status/requests.c", + "lib/handler/throttle_resp.c", + "lib/http1.c", + "lib/http2/cache_digests.c", + "lib/http2/casper.c", + "lib/http2/connection.c", + "lib/http2/frame.c", + "lib/http2/hpack.c", + "lib/http2/http2_debug_state.c", + "lib/http2/scheduler.c", + "lib/http2/stream.c", + "lib/tunnel.c", + ] + glob( + [ + "lib/core/*.h", + "lib/handler/mimemap/*.h", + "lib/handler/file/*.h", + "lib/http2/*.h", + "lib/common/socket/*.h", + ], + ), + hdrs = ["include/h2o.h"] + glob( + [ + "include/h2o/*.h", + "include/h2o/socket/*.h", + ], + ), + copts = [ + "-std=c99", + "-g3", + "-O2", + "-pthread", + ] + CC_WARNING_FLAGS, + includes = [ + "include", + "include/h2o", + "include/h2o/socket", + ], + local_defines = [ + "H2O_USE_LIBUV", + "H2O_USE_PICOTLS", + ] + select({ + "@platforms//os:linux": ["_GNU_SOURCE"], + "//conditions:default": [], + }), + visibility = ["//visibility:public"], + deps = [ + ":cloexec", + ":golombset", + ":klib", + ":libgkc", + ":libyrmcds", + ":picohttpparser", + ":picotls", + ":ssl_conservatory", + ":yoml", + "@openssl", + "@uv", + "@zlib", + ], +) diff --git a/bazel/third_party/keccak_tiny/64b6647514212b76ae7bca0dea9b7b197d1d8186.patch b/bazel/third_party/keccak_tiny/64b6647514212b76ae7bca0dea9b7b197d1d8186.patch new file mode 100644 index 0000000000..04ba2d2e14 --- /dev/null +++ b/bazel/third_party/keccak_tiny/64b6647514212b76ae7bca0dea9b7b197d1d8186.patch @@ -0,0 +1,168 @@ +diff --git a/define-macros.h b/define-macros.h +new file mode 100644 +index 0000000..79b534c +--- /dev/null ++++ b/define-macros.h +@@ -0,0 +1,44 @@ ++#ifndef DEFINEMACROS_H ++#define DEFINEMACROS_H ++ ++/*** Helper macros to define SHA3 and SHAKE instances. ***/ ++#define defshake(bits) \ ++ int shake##bits(uint8_t* out, size_t outlen, \ ++ const uint8_t* in, size_t inlen) { \ ++ return hash(out, outlen, in, inlen, 200 - (bits / 4), 0x1f); \ ++ } ++#define defsha3(bits) \ ++ int sha3_##bits(uint8_t* out, size_t outlen, \ ++ const uint8_t* in, size_t inlen) { \ ++ if (outlen > (bits/8)) { \ ++ return -1; \ ++ } \ ++ return hash(out, outlen, in, inlen, 200 - (bits / 4), 0x06); \ ++ } ++ ++#define defkeccak(bits) \ ++ int keccak_##bits(uint8_t* out, size_t outlen, \ ++ const uint8_t* in, size_t inlen) { \ ++ if (outlen > (bits/8)) { \ ++ return -1; \ ++ } \ ++ return hash(out, outlen, in, inlen, 200 - (bits / 4), 0x01); \ ++ } ++ ++/*** FIPS202 SHAKE VOFs ***/ ++defshake(128) ++defshake(256) ++ ++/*** FIPS202 SHA3 FOFs ***/ ++defsha3(224) ++defsha3(256) ++defsha3(384) ++defsha3(512) ++ ++/*** Non FIP202 SHA3 (KECCAK) FOFs ***/ ++defkeccak(224) ++defkeccak(256) ++defkeccak(384) ++defkeccak(512) ++ ++#endif // DEFINEMACROS_H +diff --git a/keccak-tiny-unrolled.c b/keccak-tiny-unrolled.c +index c238af4..c1eb2a6 100644 +--- a/keccak-tiny-unrolled.c ++++ b/keccak-tiny-unrolled.c +@@ -133,31 +133,11 @@ static inline int hash(uint8_t* out, size_t outlen, + // Squeeze output. + foldP(out, outlen, setout); + setout(a, out, outlen); +- memset_s(a, 200, 0, 200); ++ //TODO: c11 problem: replaced ++ //memset_s(a, 200, 0, 200); ++ //Reference: http://en.cppreference.com/w/c/string/byte/memset ++ memset(a, 0, 200); + return 0; + } + +-/*** Helper macros to define SHA3 and SHAKE instances. ***/ +-#define defshake(bits) \ +- int shake##bits(uint8_t* out, size_t outlen, \ +- const uint8_t* in, size_t inlen) { \ +- return hash(out, outlen, in, inlen, 200 - (bits / 4), 0x1f); \ +- } +-#define defsha3(bits) \ +- int sha3_##bits(uint8_t* out, size_t outlen, \ +- const uint8_t* in, size_t inlen) { \ +- if (outlen > (bits/8)) { \ +- return -1; \ +- } \ +- return hash(out, outlen, in, inlen, 200 - (bits / 4), 0x06); \ +- } +- +-/*** FIPS202 SHAKE VOFs ***/ +-defshake(128) +-defshake(256) +- +-/*** FIPS202 SHA3 FOFs ***/ +-defsha3(224) +-defsha3(256) +-defsha3(384) +-defsha3(512) ++#include "define-macros.h" +diff --git a/keccak-tiny.c b/keccak-tiny.c +index 76d89fa..fcb3556 100644 +--- a/keccak-tiny.c ++++ b/keccak-tiny.c +@@ -133,31 +133,11 @@ static inline int hash(uint8_t* out, size_t outlen, + // Squeeze output. + foldP(out, outlen, setout); + setout(a, out, outlen); +- memset_s(a, 200, 0, 200); ++ //TODO: c11 problem: replaced ++ //memset_s(a, 200, 0, 200); ++ //Reference: http://en.cppreference.com/w/c/string/byte/memset ++ memset(a, 0, 200); + return 0; + } + +-/*** Helper macros to define SHA3 and SHAKE instances. ***/ +-#define defshake(bits) \ +- int shake##bits(uint8_t* out, size_t outlen, \ +- const uint8_t* in, size_t inlen) { \ +- return hash(out, outlen, in, inlen, 200 - (bits / 4), 0x1f); \ +- } +-#define defsha3(bits) \ +- int sha3_##bits(uint8_t* out, size_t outlen, \ +- const uint8_t* in, size_t inlen) { \ +- if (outlen > (bits/8)) { \ +- return -1; \ +- } \ +- return hash(out, outlen, in, inlen, 200 - (bits / 4), 0x06); \ +- } +- +-/*** FIPS202 SHAKE VOFs ***/ +-defshake(128) +-defshake(256) +- +-/*** FIPS202 SHA3 FOFs ***/ +-defsha3(224) +-defsha3(256) +-defsha3(384) +-defsha3(512) ++#include "define-macros.h" +diff --git a/keccak-tiny.h b/keccak-tiny.h +index c4c678e..5d643be 100644 +--- a/keccak-tiny.h ++++ b/keccak-tiny.h +@@ -4,16 +4,31 @@ + #include + #include + ++#define HASH224_SIZE 28 ++#define HASH256_SIZE 32 ++#define HASH384_SIZE 48 ++#define HASH512_SIZE 64 ++ + #define decshake(bits) \ + int shake##bits(uint8_t*, size_t, const uint8_t*, size_t); + + #define decsha3(bits) \ + int sha3_##bits(uint8_t*, size_t, const uint8_t*, size_t); + ++#define deckeccak(bits) \ ++ int keccak_##bits(uint8_t*, size_t, const uint8_t*, size_t); ++ + decshake(128) + decshake(256) ++ + decsha3(224) + decsha3(256) + decsha3(384) + decsha3(512) ++ ++deckeccak(224) ++deckeccak(256) ++deckeccak(384) ++deckeccak(512) ++ + #endif diff --git a/bazel/third_party/keccak_tiny/BUILD.bazel b/bazel/third_party/keccak_tiny/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/bazel/third_party/keccak_tiny/keccak_tiny.BUILD b/bazel/third_party/keccak_tiny/keccak_tiny.BUILD new file mode 100644 index 0000000000..4c5e6b9d85 --- /dev/null +++ b/bazel/third_party/keccak_tiny/keccak_tiny.BUILD @@ -0,0 +1,16 @@ +cc_library( + name = "keccak_tiny", + srcs = [ + "define-macros.h", + "keccak-tiny.c", + ], + hdrs = ["keccak-tiny.h"], + copts = ["-O3"], + includes = ["."], + local_defines = select({ + # TODO: confirm which platforms have memset_s(). + "@platforms//os:linux": ["memset_s(W,WL,V,OL)=memset(W,V,OL)"], + "//conditions:default": [], + }), + visibility = ["//visibility:public"], +) diff --git a/bazel/third_party/libbacktrace/BUILD.bazel b/bazel/third_party/libbacktrace/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/bazel/third_party/libbacktrace/libbacktrace.BUILD b/bazel/third_party/libbacktrace/libbacktrace.BUILD new file mode 100644 index 0000000000..ecb9ed9036 --- /dev/null +++ b/bazel/third_party/libbacktrace/libbacktrace.BUILD @@ -0,0 +1,25 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +filegroup( + name = "all", + srcs = glob(["**"]), +) + +configure_make( + name = "libbacktrace", + args = [ + ] + select({ + "@platforms//os:macos": ["--jobs=`sysctl -n hw.logicalcpu`"], + "//conditions:default": ["--jobs=`nproc`"], + }), + configure_options = [ + ] + select({ + "@//:linux_aarch64": ["--host=aarch64-linux-musl"], + "@//:linux_x86_64": ["--host=x86_64-linux-musl"], + "//conditions:default": [], + }), + copts = ["-O3"], + lib_source = ":all", + out_static_libs = ["libbacktrace.a"], + visibility = ["//visibility:public"], +) diff --git a/bazel/third_party/libunwind/BUILD.bazel b/bazel/third_party/libunwind/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/bazel/third_party/libunwind/libunwind.BUILD b/bazel/third_party/libunwind/libunwind.BUILD new file mode 100644 index 0000000000..3934b8f8b3 --- /dev/null +++ b/bazel/third_party/libunwind/libunwind.BUILD @@ -0,0 +1,25 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +filegroup( + name = "all", + srcs = glob(["**"]), +) + +configure_make( + name = "libunwind", + args = select({ + "@platforms//os:macos": ["--jobs=`sysctl -n hw.logicalcpu`"], + "//conditions:default": ["--jobs=`nproc`"], + }), + configure_options = [ + "--enable-debug-frame", + ] + select({ + "@//:linux_aarch64": ["--host=aarch64-linux-musl"], + "@//:linux_x86_64": ["--host=x86_64-linux-musl"], + "//conditions:default": [], + }), + copts = ["-O3 -g"], + lib_source = ":all", + out_static_libs = ["libunwind.a"], + visibility = ["//visibility:public"], +) diff --git a/bazel/third_party/lmdb/0.9.29.patch b/bazel/third_party/lmdb/0.9.29.patch new file mode 100644 index 0000000000..cd8416d7cf --- /dev/null +++ b/bazel/third_party/lmdb/0.9.29.patch @@ -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(); + } + } diff --git a/bazel/third_party/lmdb/BUILD.bazel b/bazel/third_party/lmdb/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/bazel/third_party/lmdb/lmdb.BUILD b/bazel/third_party/lmdb/lmdb.BUILD new file mode 100644 index 0000000000..334065c4bb --- /dev/null +++ b/bazel/third_party/lmdb/lmdb.BUILD @@ -0,0 +1,29 @@ +# This build file is derived from `libraries/liblmdb/Makefile` in the `lmdb` +# repo at https://github.com/LMDB/lmdb. + +cc_library( + name = "lmdb", + srcs = [ + "mdb.c", + "midl.c", + "midl.h", + ], + hdrs = ["lmdb.h"], + copts = [ + "-pthread", + "-O2", + "-g", + "-W", + "-Wall", + "-Wno-unused-parameter", + "-Wbad-function-cast", + "-Wuninitialized", + ], + include_prefix = "lmdb", + includes = ["."], + local_defines = select({ + "@platforms//os:macos": ["URBIT_RUNTIME_OS_DARWIN"], + "//conditions:default": [], + }), + visibility = ["//visibility:public"], +) diff --git a/bazel/third_party/murmur3/BUILD.bazel b/bazel/third_party/murmur3/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/bazel/third_party/murmur3/murmur3.BUILD b/bazel/third_party/murmur3/murmur3.BUILD new file mode 100644 index 0000000000..106e7dc878 --- /dev/null +++ b/bazel/third_party/murmur3/murmur3.BUILD @@ -0,0 +1,21 @@ +# This build file is derived from `makefile` in the `murmur3` repo at +# https://github.com/PeterScott/murmur3. + +cc_library( + name = "murmur3", + srcs = ["murmur3.c"], + hdrs = ["murmur3.h"], + copts = [ + "-O3", + "-Wall", + ] + select({ + # TODO: use selects.with_or() from skylib once it's available. + "@platforms//os:macos": [ + "-fPIC", + "-c", + ], + "//conditions:default": [], + }), + includes = ["."], + visibility = ["//visibility:public"], +) diff --git a/bazel/third_party/natpmp/BUILD.bazel b/bazel/third_party/natpmp/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/bazel/third_party/natpmp/natpmp.BUILD b/bazel/third_party/natpmp/natpmp.BUILD new file mode 100644 index 0000000000..b3a7edd7e0 --- /dev/null +++ b/bazel/third_party/natpmp/natpmp.BUILD @@ -0,0 +1,8 @@ +cc_library( + name = "natpmp", + srcs = ["natpmp.c", "getgateway.c"], + hdrs = ["natpmp.h", "getgateway.h", "natpmp_declspec.h"], + copts = ["-O3"], + linkstatic = True, + visibility = ["//visibility:public"], +) diff --git a/bazel/third_party/openssl/BUILD.bazel b/bazel/third_party/openssl/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/bazel/third_party/openssl/openssl.BUILD b/bazel/third_party/openssl/openssl.BUILD new file mode 100644 index 0000000000..bb521c4a98 --- /dev/null +++ b/bazel/third_party/openssl/openssl.BUILD @@ -0,0 +1,43 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +filegroup( + name = "all", + srcs = glob(["**"]), +) + +configure_make( + name = "openssl", + args = select({ + "@platforms//os:macos": ["--jobs=`sysctl -n hw.logicalcpu`"], + "//conditions:default": ["--jobs=`nproc`"], + }), + configure_command = select({ + "@//:linux_aarch64": "Configure", + "//conditions:default": "config", + }), + configure_options = [ + "no-shared", + ] + select({ + "@//:linux_aarch64": [ + "linux-aarch64", + # Native compilation on linux-aarch64 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": [], + }), + copts = ["-O3"], + lib_source = ":all", + out_static_libs = [ + "libssl.a", + "libcrypto.a", + ], + targets = [ + "build_libs", + "install_dev", + ], + visibility = ["//visibility:public"], +) diff --git a/bazel/third_party/pdjson/BUILD.bazel b/bazel/third_party/pdjson/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/bazel/third_party/pdjson/pdjson.BUILD b/bazel/third_party/pdjson/pdjson.BUILD new file mode 100644 index 0000000000..3a6d82d96a --- /dev/null +++ b/bazel/third_party/pdjson/pdjson.BUILD @@ -0,0 +1,16 @@ +# This build file is derived from `Makefile` in the `pdjson` repo at +# https://github.com/skeeto/pdjson. + +cc_library( + name = "pdjson", + srcs = ["pdjson.c"], + hdrs = ["pdjson.h"], + copts = [ + "-std=c99", + "-pedantic", + "-Wall", + "-Wextra", + "-Wno-missing-field-initializers" + ], + visibility = ["//visibility:public"] +) diff --git a/bazel/third_party/scrypt/BUILD.bazel b/bazel/third_party/scrypt/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/bazel/third_party/scrypt/scrypt.BUILD b/bazel/third_party/scrypt/scrypt.BUILD new file mode 100644 index 0000000000..607987d35f --- /dev/null +++ b/bazel/third_party/scrypt/scrypt.BUILD @@ -0,0 +1,30 @@ +# This build file is derived from `Makefile` in the `scrypt` repo at +# https://github.com/technion/libscrypt. + +cc_library( + name = "scrypt", + srcs = [ + "b64.c", + "b64.h", + "crypto-mcf.c", + "crypto-scrypt-saltgen.c", + "crypto_scrypt-check.c", + "crypto_scrypt-hash.c", + "crypto_scrypt-nosse.c", + "sha256.c", + "sha256.h", + "slowequals.c", + "slowequals.h", + "sysendian.h", + ], + hdrs = ["libscrypt.h"], + copts = [ + "-O2", + "-Wall", + "-g", + "-fstack-protector", + ], + includes = ["."], + local_defines = ["_FORTIFY_SOURCE=2"], + visibility = ["//visibility:public"], +) diff --git a/bazel/third_party/secp256k1/694ce8fb2d1fd8a3d641d7c33705691d41a2a860.patch b/bazel/third_party/secp256k1/694ce8fb2d1fd8a3d641d7c33705691d41a2a860.patch new file mode 100644 index 0000000000..f7f7b7c077 --- /dev/null +++ b/bazel/third_party/secp256k1/694ce8fb2d1fd8a3d641d7c33705691d41a2a860.patch @@ -0,0 +1,14 @@ +diff --git i/autogen.sh w/autogen.sh +index 65286b9..edcbeb9 100755 +--- i/autogen.sh ++++ w/autogen.sh +@@ -1,3 +1,9 @@ + #!/bin/sh + set -e ++if [ -r /etc/os-release ]; then ++ . /etc/os-release ++ if [ "$NAME" = NixOS ]; then ++ libtoolize --copy --force ++ fi ++fi + autoreconf -if --warnings=all diff --git a/bazel/third_party/secp256k1/BUILD.bazel b/bazel/third_party/secp256k1/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/bazel/third_party/secp256k1/secp256k1.BUILD b/bazel/third_party/secp256k1/secp256k1.BUILD new file mode 100644 index 0000000000..fb7b939b23 --- /dev/null +++ b/bazel/third_party/secp256k1/secp256k1.BUILD @@ -0,0 +1,30 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +filegroup( + name = "all", + srcs = glob(["**"]), +) + +configure_make( + name = "secp256k1", + args = select({ + "@platforms//os:macos": ["--jobs=`sysctl -n hw.logicalcpu`"], + "//conditions:default": ["--jobs=`nproc`"], + }), + autogen = True, + configure_in_place = True, + configure_options = [ + "--disable-shared", + "--enable-module-recovery", + "--enable-module-schnorrsig", + "--enable-static", + ] + select({ + "@//:linux_aarch64": ["--host=aarch64-linux-musl"], + "@//:linux_x86_64": ["--host=x86_64-linux-musl"], + "//conditions:default": [], + }), + copts = ["-O3"], + lib_source = ":all", + out_static_libs = ["libsecp256k1.a"], + visibility = ["//visibility:public"], +) diff --git a/bazel/third_party/sigsegv/BUILD.bazel b/bazel/third_party/sigsegv/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/bazel/third_party/sigsegv/sigsegv.BUILD b/bazel/third_party/sigsegv/sigsegv.BUILD new file mode 100644 index 0000000000..5b54736c66 --- /dev/null +++ b/bazel/third_party/sigsegv/sigsegv.BUILD @@ -0,0 +1,31 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +filegroup( + name = "all", + srcs = glob(["**"]), +) + +configure_make( + name = "sigsegv", + args = select({ + "@platforms//os:macos": ["--jobs=`sysctl -n hw.logicalcpu`"], + "//conditions:default": ["--jobs=`nproc`"], + }), + configure_options = [ + "--disable-shared", + "--enable-static", + ] + select({ + # Disable stack vma check, which reads from procfs, producing drastic + # slowdowns. + "@platforms//os:linux": ["--disable-stackvma"], + "//conditions:default": [], + }) + select({ + "@//:linux_aarch64": ["--host=aarch64-linux-musl"], + "@//:linux_x86_64": ["--host=x86_64-linux-musl"], + "//conditions:default": [], + }), + copts = ["-O3"], + lib_source = ":all", + out_static_libs = ["libsigsegv.a"], + visibility = ["//visibility:public"], +) diff --git a/bazel/third_party/softfloat/5c06db33fc1e2130f67c045327b0ec949032df1d.patch b/bazel/third_party/softfloat/5c06db33fc1e2130f67c045327b0ec949032df1d.patch new file mode 100644 index 0000000000..b05221ff82 --- /dev/null +++ b/bazel/third_party/softfloat/5c06db33fc1e2130f67c045327b0ec949032df1d.patch @@ -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 + diff --git a/bazel/third_party/softfloat/BUILD.bazel b/bazel/third_party/softfloat/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/bazel/third_party/softfloat/softfloat.BUILD b/bazel/third_party/softfloat/softfloat.BUILD new file mode 100644 index 0000000000..0d57ba5d7f --- /dev/null +++ b/bazel/third_party/softfloat/softfloat.BUILD @@ -0,0 +1,637 @@ +# This build file is derived from the makefiles in `build/` in the `softfloat` +# repo at https://github.com/ucb-bar/berkeley-softfloat-3. +# +# The following link, which is referenced in `README.md` in the `softfloat` +# 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({ + "@platforms//cpu:aarch64": [":softfloat_aarch64"], + "@platforms//cpu:x86_64": [":softfloat_x86_64"], + "//conditions:default": [], + }), +) + +cc_library( + name = "softfloat_aarch64", + 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_x86_64", + srcs = [ + # See `OBJS_PRIMITIVES` in `build/Linux-x86_64-GCC/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/Linux-x86_64-GCC/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/Linux-x86_64-GCC/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/Linux-x86_64-GCC/Makefile` in the + # `softfloat` repo. + "source/include/opts-GCC.h", + # See `$(OBJS_ALL)` target in `build/Linux-x86_64-GCC/Makefile` in the + # `softfloat` repo. + "build/Linux-x86_64-GCC/platform.h", + "source/include/primitiveTypes.h", + "source/include/primitives.h", + # See `$(OBJS_SPECIALIZE) $(OBJS_OTHERS)` target in + # `build/Linux-x86_64-GCC/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/Linux-x86_64-GCC", + "-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 = ["source/include"], + local_defines = [ + "SOFTFLOAT_ROUND_ODD", + "INLINE_LEVEL=5", + "SOFTFLOAT_FAST_DIV32TO16", + "SOFTFLOAT_FAST_DIV64TO32", + ], + visibility = ["//visibility:private"], +) 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..95aee5072d --- /dev/null +++ b/bazel/third_party/sse2neon/sse2neon.BUILD @@ -0,0 +1,7 @@ +cc_library( + name = "sse2neon", + hdrs = ["sse2neon.h"], + copts = ["-O3"], + linkstatic = True, + visibility = ["//visibility:public"], +) diff --git a/bazel/third_party/urcrypt/BUILD.bazel b/bazel/third_party/urcrypt/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/bazel/third_party/urcrypt/urcrypt.BUILD b/bazel/third_party/urcrypt/urcrypt.BUILD new file mode 100644 index 0000000000..c41d78f5b0 --- /dev/null +++ b/bazel/third_party/urcrypt/urcrypt.BUILD @@ -0,0 +1,28 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +filegroup( + name = "all", + srcs = glob(["**"]), +) + +configure_make( + name = "urcrypt", + autogen = True, + configure_in_place = True, + configure_options = [ + "--disable-shared", + ], + copts = [ + "-Wall", + "-g", + "-O2", + ], + deps = [ + "@aes_siv", + "@openssl", + "@secp256k1" + ], + lib_source = ":all", + out_static_libs = ["liburcrypt.a"], + visibility = ["//visibility:public"], +) diff --git a/bazel/third_party/uv/BUILD.bazel b/bazel/third_party/uv/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/bazel/third_party/uv/uv.BUILD b/bazel/third_party/uv/uv.BUILD new file mode 100644 index 0000000000..1fd2352559 --- /dev/null +++ b/bazel/third_party/uv/uv.BUILD @@ -0,0 +1,28 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +filegroup( + name = "all", + srcs = glob(["**"]), +) + +configure_make( + name = "uv", + args = select({ + "@platforms//os:macos": ["--jobs=`sysctl -n hw.logicalcpu`"], + "//conditions:default": ["--jobs=`nproc`"], + }), + autogen = True, + configure_in_place = True, + configure_options = [ + "--disable-shared", + ] + select({ + "@//:linux_aarch64": ["--host=aarch64-linux-musl"], + "@//:linux_x86_64": ["--host=x86_64-linux-musl"], + "//conditions:default": [], + }), + copts = ["-O3"], + lib_source = ":all", + out_static_libs = ["libuv.a"], + targets = ["install"], + visibility = ["//visibility:public"], +) diff --git a/bazel/third_party/whereami/BUILD.bazel b/bazel/third_party/whereami/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/bazel/third_party/whereami/whereami.BUILD b/bazel/third_party/whereami/whereami.BUILD new file mode 100644 index 0000000000..4d314afec4 --- /dev/null +++ b/bazel/third_party/whereami/whereami.BUILD @@ -0,0 +1,8 @@ +cc_library( + name = "whereami", + srcs = ["src/whereami.c"], + hdrs = ["src/whereami.h"], + copts = ["-O3"], + includes = ["src"], + visibility = ["//visibility:public"], +) diff --git a/bazel/third_party/zlib/BUILD.bazel b/bazel/third_party/zlib/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/bazel/third_party/zlib/zlib.BUILD b/bazel/third_party/zlib/zlib.BUILD new file mode 100644 index 0000000000..2b351f2c30 --- /dev/null +++ b/bazel/third_party/zlib/zlib.BUILD @@ -0,0 +1,19 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +filegroup( + name = "all", + srcs = glob(["**"]), +) + +configure_make( + name = "zlib", + args = select({ + "@platforms//os:macos": ["--jobs=`sysctl -n hw.logicalcpu`"], + "//conditions:default": ["--jobs=`nproc`"], + }), + configure_options = ["--static"], + copts = ["-O3"], + lib_source = ":all", + out_static_libs = ["libz.a"], + visibility = ["//visibility:public"], +) diff --git a/bazel/toolchain/BUILD.bazel b/bazel/toolchain/BUILD.bazel new file mode 100644 index 0000000000..38fa379197 --- /dev/null +++ b/bazel/toolchain/BUILD.bazel @@ -0,0 +1,410 @@ +# 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. + +load(":cfg.bzl", "cc_toolchain_config") + +# The prefix for installed external toolchains. +_install_prefix = "/usr/local" + +filegroup(name = "empty") + +alias( + name = "toolchain_type", + actual = "@bazel_tools//tools/cpp:toolchain_type", +) + +# +# gcc-linux-aarch64 +# + +# Toolchain identifier. +_aarch64_gcc = "toolchain-gcc-linux-aarch64" + +cc_toolchain_config( + name = "gcc-linux-aarch64-config", + ar = "{}/aarch64-linux-musl/bin/aarch64-linux-musl-gcc-ar".format(_install_prefix), + cc = "{}/aarch64-linux-musl/bin/aarch64-linux-musl-gcc".format(_install_prefix), + cc_flags = [ + "-static", + "--sysroot={}/aarch64-linux-musl".format(_install_prefix), + ], + compiler = "aarch64-linux-musl-gcc", + compiler_version = "//:gcc_version", + ld = "{}/aarch64-linux-musl/bin/aarch64-linux-musl-ld".format(_install_prefix), + ld_flags = ["--sysroot={}/aarch64-linux-musl".format(_install_prefix)], + sys_includes = [ + "{}/aarch64-linux-musl/aarch64-linux-musl/include".format(_install_prefix), + "{}/aarch64-linux-musl/lib/gcc/aarch64-linux-musl/{{compiler_version}}/include".format(_install_prefix), + ], + target_cpu = "aarch64", + toolchain_identifier = _aarch64_gcc, +) + +cc_toolchain( + name = "gcc-linux-aarch64", + all_files = ":empty", + compiler_files = ":empty", + dwp_files = ":empty", + linker_files = ":empty", + objcopy_files = ":empty", + strip_files = ":empty", + supports_param_files = 0, + toolchain_config = ":gcc-linux-aarch64-config", + toolchain_identifier = _aarch64_gcc, +) + +toolchain( + name = "gcc-linux-aarch64-toolchain", + exec_compatible_with = [ + "@platforms//os:linux", + "@platforms//cpu:aarch64", + ], + target_compatible_with = [ + "@platforms//os:linux", + "@platforms//cpu:aarch64", + ], + toolchain = ":gcc-linux-aarch64", + toolchain_type = ":toolchain_type", +) + +# +# gcc-linux-x86_64 +# + +# Toolchain identifier. +_x86_64_gcc = "toolchain-gcc-linux-x86_64" + +cc_toolchain_config( + name = "gcc-linux-x86_64-config", + ar = "{}/x86_64-linux-musl/bin/x86_64-linux-musl-gcc-ar".format(_install_prefix), + cc = "{}/x86_64-linux-musl/bin/x86_64-linux-musl-gcc".format(_install_prefix), + cc_flags = [ + "-static", + "--sysroot={}/x86_64-linux-musl".format(_install_prefix), + ], + compiler = "x86_64-linux-musl-gcc", + compiler_version = "//:gcc_version", + ld = "{}/x86_64-linux-musl/bin/x86_64-linux-musl-ld".format(_install_prefix), + ld_flags = ["--sysroot={}/x86_64-linux-musl".format(_install_prefix)], + sys_includes = [ + "{}/x86_64-linux-musl/x86_64-linux-musl/include".format(_install_prefix), + "{}/x86_64-linux-musl/lib/gcc/x86_64-linux-musl/{{compiler_version}}/include".format(_install_prefix), + ], + target_cpu = "x86_64", + toolchain_identifier = _x86_64_gcc, +) + +cc_toolchain( + name = "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 = ":gcc-linux-x86_64-config", + toolchain_identifier = _x86_64_gcc, +) + +toolchain( + name = "gcc-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 = ":gcc-linux-x86_64", + toolchain_type = ":toolchain_type", +) + +# +# clang-macos-aarch64 +# + +# Toolchain identifier. +_macos_aarch64_clang = "toolchain-clang-macos-aarch64" + +cc_toolchain_config( + name = "clang-macos-aarch64-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 = [ + "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include", + "/Library/Developer/CommandLineTools/usr/lib/clang/{compiler_version}/include", + "/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 = "aarch64", + toolchain_identifier = _macos_aarch64_clang, +) + +cc_toolchain( + name = "clang-macos-aarch64", + 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-aarch64-config", + toolchain_identifier = _macos_aarch64_clang, +) + +toolchain( + name = "clang-macos-aarch64-toolchain", + exec_compatible_with = [ + "@platforms//os:macos", + "@platforms//cpu:aarch64", + ], + target_compatible_with = [ + "@platforms//os:macos", + "@platforms//cpu:aarch64", + ], + toolchain = ":clang-macos-aarch64", + toolchain_type = ":toolchain_type", +) + +# +# clang-macos-x86_64 +# + +# Toolchain identifier. +_macos_x86_64_clang = "toolchain-clang-macos-x86_64" + +cc_toolchain_config( + name = "clang-macos-x86_64-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 = [ + "/Library/Developer/CommandLineTools/usr/lib/clang/{compiler_version}/include", + "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/", + "/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 = "x86_64", + toolchain_identifier = _macos_x86_64_clang, +) + +cc_toolchain( + name = "clang-macos-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-macos-x86_64-config", + toolchain_identifier = _macos_x86_64_clang, +) + +toolchain( + name = "clang-macos-x86_64-toolchain", + exec_compatible_with = [ + "@platforms//os:macos", + "@platforms//cpu:x86_64", + ], + target_compatible_with = [ + "@platforms//os:macos", + "@platforms//cpu:x86_64", + ], + toolchain = ":clang-macos-x86_64", + toolchain_type = ":toolchain_type", +) + +# +# brew-clang-macos-x86_64 +# + +# Toolchain identifier. +_macos_x86_64_brew_clang = "toolchain-brew-clang-macos-x86_64" + +cc_toolchain_config( + name = "brew-clang-macos-x86_64-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/local/opt/llvm@15/bin/llvm-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/local/opt/llvm@15/bin/clang", + compiler = "clang", + compiler_version = "//:clang_version", + ld = "/usr/local/opt/llvm@15/bin/llvm-lld", + nm = "/usr/local/opt/llvm@15/bin/llvm-nm", + sys_includes = [ + "/usr/local/Cellar/llvm@15/15.0.7/lib/clang/15.0.7/include", + "/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/usr/include", + ], + target_cpu = "x86_64", + toolchain_identifier = _macos_x86_64_brew_clang, +) + +cc_toolchain( + name = "brew-clang-macos-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 = ":brew-clang-macos-x86_64-config", + toolchain_identifier = _macos_x86_64_brew_clang, +) + +toolchain( + name = "brew-clang-macos-x86_64-toolchain", + exec_compatible_with = [ + "@platforms//os:macos", + "@platforms//cpu:x86_64", + ], + target_compatible_with = [ + "@platforms//os:macos", + "@platforms//cpu:x86_64", + ], + toolchain = ":brew-clang-macos-x86_64", + toolchain_type = ":toolchain_type", +) + +# +# BOOTSTRAPPING +# + +# We can't build some artifacts, 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/`) because doing +# so introduces a circular dependency during Bazel C/C++ toolchain resolution. + +# musl-cross-make builds musl-libc-compatible gcc toolchains from source. +_musl_cross_make_version = "99f2cbc7e230f72bde3394be3ebd50497cb53e89" + +_musl_cross_make_archive = "https://github.com/ripperi/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 ' echo GCC_VER=11.4.0 >> $$archive/config.mak' >> $@ + echo ' echo MUSL_VER=1.2.5 >> $$archive/config.mak' >> $@ + echo ' TARGET=aarch64-linux-musl make -s -C$$archive -j`nproc`' >> $@ + echo ' sudo TARGET=aarch64-linux-musl make -s -C$$archive -j`nproc` install' >> $@ + echo ' sudo chown --recursive $$USER $$aarch64_linux_musl_install' >> $@ + echo 'fi' >> $@ + """.format( + _install_prefix, + _musl_cross_make_archive, + _musl_cross_make_version, + _musl_cross_make_version, + ), + exec_compatible_with = ["@platforms//os:linux"], + target_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"], + target_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 ' echo GCC_VER=11.4.0 >> $$archive/config.mak' >> $@ + echo ' echo MUSL_VER=1.2.5 >> $$archive/config.mak' >> $@ + echo ' TARGET=x86_64-linux-musl make -s -C$$archive -j`nproc`' >> $@ + echo ' sudo TARGET=x86_64-linux-musl make -s -C$$archive -j`nproc` install' >> $@ + echo ' sudo chown --recursive $$USER $$x86_64_linux_musl_install' >> $@ + echo 'fi' >> $@ + """.format( + _install_prefix, + _musl_cross_make_archive, + _musl_cross_make_version, + _musl_cross_make_version, + ), + exec_compatible_with = ["@platforms//os:linux"], + target_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"], + target_compatible_with = ["@platforms//os:linux"], + visibility = ["//visibility:public"], +) diff --git a/bazel/toolchain/cfg.bzl b/bazel/toolchain/cfg.bzl new file mode 100644 index 0000000000..aa41e1c2c4 --- /dev/null +++ b/bazel/toolchain/cfg.bzl @@ -0,0 +1,168 @@ +load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo") +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( + 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", + ), + ], + ), + ], + ) + 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 + # https://bazel.build/rules/lib/cc_common#create_cc_toolchain_config_info. + return cc_common.create_cc_toolchain_config_info( + ctx = ctx, + # 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 = features, + toolchain_identifier = ctx.attr.toolchain_identifier, + target_system_name = ctx.attr.target_system_name, + target_cpu = ctx.attr.target_cpu, + target_libc = ctx.attr.target_libc, + compiler = ctx.attr.compiler, + abi_version = ctx.attr.abi_version, + abi_libc_version = ctx.attr.abi_libc_version, + tool_paths = [ + tool_path( + name = "gcc", + path = ctx.attr.cc, + ), + tool_path( + name = "ld", + path = ctx.attr.ld, + ), + tool_path( + name = "ar", + path = ctx.attr.ar, + ), + tool_path( + name = "cpp", + path = ctx.attr.cpp, + ), + tool_path( + name = "gcov", + path = ctx.attr.gcov, + ), + tool_path( + name = "nm", + path = ctx.attr.nm, + ), + tool_path( + name = "objdump", + path = ctx.attr.objdump, + ), + tool_path( + name = "strip", + path = ctx.attr.strip, + ), + ], + ) + +cc_toolchain_config = rule( + implementation = _cc_toolchain_config_impl, + attrs = { + # Required. + "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), + # Optional. + "abi_libc_version": attr.string(default = "unknown"), + "abi_version": attr.string(default = "unknown"), + "ar_flags": attr.string(default = "rcsD"), + "cc_flags": attr.string_list(default = []), + "cpp": attr.string(default = "/bin/false"), + "gcov": attr.string(default = "/bin/false"), + "ld_flags": attr.string_list(default = []), + "nm": attr.string(default = "/bin/false"), + "objdump": attr.string(default = "/bin/false"), + "strip": attr.string(default = "/bin/false"), + "sys_includes": attr.string_list(default = []), + "target_libc": attr.string(default = "unknown"), + "target_system_name": attr.string(default = "unknown"), + }, + provides = [CcToolchainConfigInfo], +) diff --git a/docker/BUILD.bazel b/docker/BUILD.bazel new file mode 100644 index 0000000000..6760b71221 --- /dev/null +++ b/docker/BUILD.bazel @@ -0,0 +1,116 @@ +load("@io_bazel_rules_docker//container:container.bzl", "container_image", "container_push") +load("@io_bazel_rules_docker//docker/util:run.bzl", "container_run_and_commit_layer") + +# +# IMAGE CREATION +# + +sh_binary( + name = "start-urbit", + srcs = ["start_urbit.sh"], + visibility = ["//visibility:private"], +) + +sh_binary( + name = "get-urbit-code", + srcs = ["get_urbit_code.sh"], + visibility = ["//visibility:private"], +) + +sh_binary( + name = "reset-urbit-code", + srcs = ["reset_urbit_code.sh"], + visibility = ["//visibility:private"], +) + +container_run_and_commit_layer( + name = "install_pkgs", + commands = [ + "apk update", + "apk add bash curl", + ], + docker_run_flags = ["--network=host"], + image = "@alpine_linux_x86_64//image", + visibility = ["//visibility:private"], +) + +container_image( + name = "image_x86_64", + base = "@alpine_linux_x86_64//image", + cmd = ["start-urbit"], + directory = "/bin", + # `/bin` is probably on the default path, but append it just to be safe. + env = { + "PATH": "$$PATH:/bin", + }, + files = [ + ":get-urbit-code", + ":reset-urbit-code", + ":start-urbit", + "//pkg/vere:urbit", + ], + layers = [":install_pkgs"], + ports = [ + "80/tcp", + "34343/udp", + ], + volumes = ["/urbit"], + workdir = "/urbit", + visibility = ["//visibility:public"], +) + +# +# IMAGE UPLOAD +# + +_docker_repository = "tloncorp/vere" + +genrule( + name = "version_tag", + srcs = ["//:version"], + outs = ["docker_version_tag"], + cmd = """ + echo -n v$$(cat $<) > $@ + """, + visibility = ["//visibility:private"], +) + +genrule( + name = "pace_tag", + srcs = ["//:PACE"], + outs = ["docker_pace_tag"], + cmd = """ + tr -d '\n' < $< > $@ + """, + visibility = ["//visibility:private"], +) + +container_push( + name = "push_latest_x86_64", + format = "Docker", + image = ":image_x86_64", + registry = "docker.io", + repository = _docker_repository, + tag = "latest", + visibility = ["//visibility:public"], +) + +container_push( + name = "push_version_x86_64", + format = "Docker", + image = ":image_x86_64", + registry = "docker.io", + repository = _docker_repository, + tag_file = ":version_tag", + visibility = ["//visibility:public"], +) + +container_push( + name = "push_pace_x86_64", + format = "Docker", + image = ":image_x86_64", + registry = "docker.io", + repository = _docker_repository, + tag_file = ":pace_tag", + visibility = ["//visibility:public"], +) diff --git a/pkg/c3/BUILD.bazel b/pkg/c3/BUILD.bazel new file mode 100644 index 0000000000..95b790b5ec --- /dev/null +++ b/pkg/c3/BUILD.bazel @@ -0,0 +1,42 @@ +# +# LIBRARIES +# + +load("//bazel:common_settings.bzl", "vere_library") + +vere_library( + name = "c3", + srcs = glob( + [ + "*.h", + "*.c", + ], + exclude = [ + "c3.h", + "*_tests.c", + ], + ), + hdrs = ["c3.h"], + # We define platform-specific macros here to avoid the need for a + # configuration header file. + defines = [ + # We don't build on any big endian CPUs. + "U3_OS_ENDIAN_little=1", + "U3_OS_PROF=1", + ] + select({ + "@platforms//cpu:aarch64": ["U3_CPU_aarch64=1"], + "//conditions:default": [], + }) + select({ + "@platforms//os:linux": ["U3_OS_linux=1"], + "@platforms//os:macos": ["U3_OS_osx=1"], + "//conditions:default": [], + }), + include_prefix = "c3", + includes = ["."], + linkstatic = True, + visibility = ["//pkg:__subpackages__"], +) + +# +# TESTS +# diff --git a/pkg/ent/BUILD.bazel b/pkg/ent/BUILD.bazel new file mode 100644 index 0000000000..ad9894b1e2 --- /dev/null +++ b/pkg/ent/BUILD.bazel @@ -0,0 +1,49 @@ +# +# LIBRARIES +# + +load("//bazel:common_settings.bzl", "vere_library") + +vere_library( + name = "ent", + srcs = ["ent.c"], + hdrs = ["ent.h"], + copts = [ + "-O3", + "-Wall", + "-Werror", + "-pedantic", + "-std=gnu99", + ], + include_prefix = "ent", + includes = ["."], + linkstatic = True, + local_defines = select({ + "@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: + # - ENT_GETENTROPY_UNISTD + # - ENT_GETENTROPY_SYSRANDOM + # - ENT_GETRANDOM_SYSCALL + # - ENT_DEV_URANDOM + "//conditions:default": ["ENT_GETENTROPY_UNISTD"], + }), + visibility = ["//:__subpackages__"], +) + +# +# TESTS +# + +cc_test( + name = "tests", + timeout = "short", + srcs = ["tests.c"], + features = select({ + "@platforms//os:linux": ["fully_static_link"], + "//conditions:default": [], + }), + visibility = ["//visibility:private"], + deps = [":ent"], +) diff --git a/pkg/noun/BUILD.bazel b/pkg/noun/BUILD.bazel new file mode 100644 index 0000000000..1be5825990 --- /dev/null +++ b/pkg/noun/BUILD.bazel @@ -0,0 +1,117 @@ +# +# LIBRARIES +# + +load("//bazel:common_settings.bzl", "vere_library") + +vere_library( + name = "noun", + srcs = glob( + [ + "**/*.c", + "**/*.h", + "jets/*.h", + "jets/**/*.c", + ], + exclude = [ + "noun.h", + "*_tests.c", + ], + ), + 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__"], + deps = [ + "//pkg/c3", + "//pkg/ent", + "//pkg/ur", + "@gmp", + "@libbacktrace", + "@murmur3", + "@openssl", + "@pdjson", + "@sigsegv", + "@softfloat", + "@urcrypt", + "@whereami", + ] + select({ + "@platforms//os:macos": ["//pkg/noun/platform/darwin"], + "@platforms//os:linux": [ + "//pkg/noun/platform/linux", + "@libunwind", + ], + "//conditions:default": [], + }), +) + +# +# TESTS +# + +cc_test( + name = "hashtable_tests", + timeout = "short", + srcs = ["hashtable_tests.c"], + features = select({ + "@platforms//os:linux": ["fully_static_link"], + "//conditions:default": [], + }), + visibility = ["//visibility:private"], + deps = [":noun"], +) + +cc_test( + name = "jets_tests", + timeout = "short", + srcs = ["jets_tests.c"], + features = select({ + "@platforms//os:linux": ["fully_static_link"], + "//conditions:default": [], + }), + visibility = ["//visibility:private"], + deps = [":noun"], +) + +cc_test( + name = "nock_tests", + timeout = "short", + srcs = ["nock_tests.c"], + features = select({ + "@platforms//os:linux": ["fully_static_link"], + "//conditions:default": [], + }), + visibility = ["//visibility:private"], + deps = [":noun"], +) + +cc_test( + name = "retrieve_tests", + timeout = "short", + srcs = ["retrieve_tests.c"], + features = select({ + "@platforms//os:linux": ["fully_static_link"], + "//conditions:default": [], + }), + visibility = ["//visibility:private"], + deps = [":noun"], +) + +cc_test( + name = "serial_tests", + timeout = "short", + srcs = ["serial_tests.c"], + features = select({ + "@platforms//os:linux": ["fully_static_link"], + "//conditions:default": [], + }), + visibility = ["//visibility:private"], + deps = [":noun"], +) diff --git a/pkg/noun/platform/darwin/BUILD.bazel b/pkg/noun/platform/darwin/BUILD.bazel new file mode 100644 index 0000000000..0724009886 --- /dev/null +++ b/pkg/noun/platform/darwin/BUILD.bazel @@ -0,0 +1,8 @@ +cc_library( + name = "darwin", + hdrs = ["rsignal.h"], + include_prefix = "platform", + includes = ["."], + target_compatible_with = ["@platforms//os:macos"], + visibility = ["//pkg:__subpackages__"], +) diff --git a/pkg/noun/platform/linux/BUILD.bazel b/pkg/noun/platform/linux/BUILD.bazel new file mode 100644 index 0000000000..506d64e175 --- /dev/null +++ b/pkg/noun/platform/linux/BUILD.bazel @@ -0,0 +1,8 @@ +cc_library( + name = "linux", + hdrs = ["rsignal.h"], + include_prefix = "platform", + includes = ["."], + target_compatible_with = ["@platforms//os:linux"], + visibility = ["//pkg:__subpackages__"], +) diff --git a/pkg/ur/BUILD.bazel b/pkg/ur/BUILD.bazel new file mode 100644 index 0000000000..4deff1e706 --- /dev/null +++ b/pkg/ur/BUILD.bazel @@ -0,0 +1,39 @@ +# +# LIBRARIES +# + +load("//bazel:common_settings.bzl", "vere_library") + +vere_library( + name = "ur", + srcs = [ + "bitstream.c", + "bitstream.h", + "defs.h", + "hashcons.c", + "hashcons.h", + "serial.c", + "serial.h", + ], + hdrs = ["ur.h"], + includes = ["."], + linkstatic = True, + visibility = ["//pkg:__subpackages__"], + deps = ["@murmur3"], +) + +# +# TESTS +# + +cc_test( + name = "tests", + timeout = "short", + srcs = ["tests.c"], + features = select({ + "@platforms//os:linux": ["fully_static_link"], + "//conditions:default": [], + }), + visibility = ["//visibility:private"], + deps = [":ur"], +) diff --git a/pkg/vere/BUILD.bazel b/pkg/vere/BUILD.bazel new file mode 100644 index 0000000000..33882e9244 --- /dev/null +++ b/pkg/vere/BUILD.bazel @@ -0,0 +1,522 @@ +# +# GENERATED FILES +# + +load("//bazel:common_settings.bzl", "vere_library", "vere_binary") + +# An approximation of `xxd -i` that runs on all platforms where Bash is +# present. Generates a `.h` file that declares the array and array length as +# `extern` global variables and a `.c` file containing the array and array +# length definitions that includes the `.h` file. +# +# Referencing a shell variable requires `$$`, not `$`. See +# https://bazel.build/reference/be/general#general-advice. +XXD_I = """ +function xxd_i() { + var=$$1 + src_file=$$2 + dst_h_file=$$3 + dst_c_file=$$4 + + # Generate `.h` file. + echo "#ifndef $${var}_H" > $$dst_h_file + echo "#define $${var}_H" >> $$dst_h_file + echo "extern unsigned char $$var[];" >> $$dst_h_file + echo "extern unsigned int $${var}_len;" >> $$dst_h_file + echo '#endif' >> $$dst_h_file + + # Generate `.c` file. + printf '#include "%s"\n' $$dst_h_file > $$dst_c_file + echo "unsigned char $$var[] = {" >> $$dst_c_file + cnt=0 + while IFS='' read line + do + for byte in $$line + do + echo -n " 0x$$byte," >> $$dst_c_file + cnt=$$((cnt+1)) + done + # <() is syntax for Bash process substitution. + done < <(od -An -v -tx1 $$src_file) + echo "};" >> $$dst_c_file + echo "unsigned int $${var}_len = $$cnt;" >> $$dst_c_file +} +""" + +# Produce a certificate authority bundle as a byte array. +genrule( + name = "ca_bundle", + srcs = ["@ca_bundle//file"], + outs = [ + "ca_bundle.h", + "ca_bundle.c", + ], + cmd_bash = """ + # Defines the function `xxd_i()`. + {} + + src_file=$(execpath @ca_bundle//file) + dst_h_file=$(execpath ca_bundle.h) + dst_c_file=$(execpath ca_bundle.c) + xxd_i include_ca_bundle_crt $$src_file $$dst_h_file $$dst_c_file + """.format(XXD_I), + visibility = ["//visibility:private"], +) + +# Produce an `ivory.pill` as a byte array. +genrule( + name = "ivory", + srcs = ["@ivory_pill//file"], + outs = [ + "ivory.h", + "ivory.c", + ], + cmd_bash = """ + # Defines the function `xxd_i()`. + {} + + # Create ivory.h. + src_file=$(execpath @ivory_pill//file) + dst_h_file=$(execpath ivory.h) + dst_c_file=$(execpath ivory.c) + xxd_i u3_Ivory_pill $$src_file $$dst_h_file $$dst_c_file + """.format(XXD_I), + visibility = ["//visibility:private"], +) + +# +# LIBRARIES +# + +vere_library( + name = "vere", + srcs = glob( + [ + "*.c", + "*.h", + "db/*.c", + "io/*.c", + "io/*/*.h", + "io/*/*.c", + ], + exclude = [ + "main.c", + "vere.h", + "*_tests.c", + ], + ) + [ + ":ivory", + "//:pace_hdr", + "//:version_hdr", + ] + select({ + "@platforms//os:macos": [ + "platform/darwin/daemon.c", + "platform/darwin/ptty.c", + "platform/darwin/mach.c", + ], + "@platforms//os:linux": [ + "platform/linux/daemon.c", + "platform/linux/ptty.c", + ], + }), + hdrs = [ + "db/lmdb.h", + "vere.h", + "mdns.h", + ] + select({ + "@platforms//os:macos": [], + "@platforms//os:linux": [ + "dns_sd.h", + ], + }), + includes = ["."], + linkstatic = True, + visibility = ["//pkg:__subpackages__"], + deps = [ + "//pkg/c3", + "//pkg/ent", + "//pkg/noun", + "//pkg/ur", + "@curl", + "@h2o", + "@lmdb", + "@openssl", + "@uv", + "@natpmp", + ] + select({ + "@platforms//os:macos": [], + "@platforms//os:linux": [ + "@avahi", + ], + }) +) + +# +# BINARIES +# + +vere_binary( + name = "urbit", + srcs = [ + "main.c", + ":ca_bundle", + ":ivory", + "//:pace_hdr", + "//:version_hdr", + ], + features = select({ + "@platforms//os:linux": ["fully_static_link"], + "//conditions:default": [], + }), + visibility = ["//visibility:public"], + deps = [ + "//pkg/c3", + "//pkg/noun", + "//pkg/ur", + ":vere", + # TODO: remove dependency (only used to report version). + "@h2o", + "@openssl", + # TODO: remove dependency (only used to report version). + "@sigsegv", + "@whereami", + ], +) + +# +# TESTS +# + + +cc_library( + name = "ames_src", + hdrs = ["io/ames.c"], +) + +cc_test( + name = "ames_tests", + timeout = "short", + srcs = ["ames_tests.c"], + features = select({ + "@platforms//os:linux": ["fully_static_link"], + "//conditions:default": [], + }), + visibility = ["//visibility:private"], + deps = [":vere", ":ames_src"] +) + +cc_test( + name = "boot_tests", + timeout = "short", + srcs = ["boot_tests.c"], + features = select({ + "@platforms//os:linux": ["fully_static_link"], + "//conditions:default": [], + }), + visibility = ["//visibility:private"], + deps = [":vere"], +) + +cc_test( + name = "newt_tests", + timeout = "short", + srcs = ["newt_tests.c"], + features = select({ + "@platforms//os:linux": ["fully_static_link"], + "//conditions:default": [], + }), + visibility = ["//visibility:private"], + deps = [":vere"], +) + +cc_test( + name = "noun_tests", + timeout = "short", + srcs = ["noun_tests.c"], + features = select({ + "@platforms//os:linux": ["fully_static_link"], + "//conditions:default": [], + }), + visibility = ["//visibility:private"], + deps = [":vere"], +) + +cc_test( + name = "unix_tests", + timeout = "short", + srcs = ["unix_tests.c"], + features = select({ + "@platforms//os:linux": ["fully_static_link"], + "//conditions:default": [], + }), + visibility = ["//visibility:private"], + deps = [":vere"], +) + +cc_test( + name = "benchmarks", + timeout = "short", + srcs = ["benchmarks.c"], + features = select({ + "@platforms//os:linux": ["fully_static_link"], + "//conditions:default": [], + }), + visibility = ["//visibility:private"], + deps = [ + ":vere", + "//pkg/noun", + "//pkg/ur", + ], +) + +# +# FAKE SHIP TESTS +# + +genrule( + name = "boot-fake-ship", + srcs = [ + "@solid_pill//file", + "@urbit//file", + ], + outs = ["fakebus.zip"], + cmd = """ + set -xeuo pipefail + + mkdir ./urbit + tar xfz $(execpath @urbit//file) -C ./urbit --strip-components=1 + cp -RL ./urbit/tests ./urbit/pkg/arvo/tests + + $(execpath :urbit) --lite-boot --daemon --fake bus \ + --bootstrap $(execpath @solid_pill//file) \ + --arvo ./urbit/pkg/arvo \ + --pier ./pier + + cleanup() { + if [ -f ./pier/.vere.lock ]; then + kill $$(< ./pier/.vere.lock) || true + fi + set +x + } + + trap cleanup EXIT + port=$$(grep loopback ./pier/.http.ports | awk -F ' ' '{print $$1}') + + lensd() { + curl -s \ + --data "{\\"source\\":{\\"dojo\\":\\"$$1\\"},\\"sink\\":{\\"stdout\\":null}}" \ + "http://localhost:$$port" | xargs printf %s | sed 's/\\\\n/\\n/g' + } + + lensa() { + curl -s \ + --data "{\\"source\\":{\\"dojo\\":\\"$$2\\"},\\"sink\\":{\\"app\\":\\"$$1\\"}}" \ + "http://localhost:$$port" | xargs printf %s | sed 's/\\\\n/\\n/g' + } + + check() { + [ 3 -eq $$(lensd 3) ] + } + + lensd '+vat %base' + + if check && sleep 10 && check; then + echo "boot success" + lensa hood '+hood/exit' + while [ -f ./pier/.vere.lock ]; do + echo "waiting for pier to shut down" + sleep 5 + done + else + echo "boot failure" + kill $$(< ./pier/.vere.lock) || true + set +x + exit 1 + fi + + set +x + ls + ls -a ./pier + zip -q -r $@ ./pier + """, + tools = [":urbit"], + visibility = ["//visibility:public"], +) + +genrule( + name = "test-fake-ship", + srcs = [ + ":boot-fake-ship", + "//pkg/vere:VERSION", + ], + outs = ["test-fake-ship-output.zip"], + cmd = """ + cp $(execpath :boot-fake-ship) pier.zip + unzip -qq pier.zip + chmod -R u+rw pier + + set -x + + $(execpath :urbit) --lite-boot --daemon --gc ./pier 2> urbit-output + + port=$$(grep loopback ./pier/.http.ports | awk -F ' ' '{print $$1}') + + lensd() { + curl -s \ + --data "{\\"source\\":{\\"dojo\\":\\"$$1\\"},\\"sink\\":{\\"stdout\\":null}}" \ + "http://localhost:$$port" | xargs printf %s | sed 's/\\\\n/\\n/g' + } + + lensa() { + curl -s \ + --data "{\\"source\\":{\\"dojo\\":\\"$$2\\"},\\"sink\\":{\\"app\\":\\"$$1\\"}}" \ + "http://localhost:$$port" | xargs printf %s | sed 's/\\\\n/\\n/g' + } + + tail -F urbit-output >&2 & + + tailproc=$$! + + cleanup () { + kill $$(cat ./pier/.vere.lock) || true + kill "$$tailproc" 2>/dev/null || true + + set +x + } + + trap cleanup EXIT + + # print the arvo version + # + lensd '+vat %base' + + # measure initial memory usage + # + lensd '~& ~ ~& %init-mass-start ~' + lensa hood '+hood/mass' + lensd '~& ~ ~& %init-mass-end ~' + + # run the unit tests + # + lensd '~& ~ ~& %test-unit-start ~' + lensd '-test %/tests ~' + lensd '~& ~ ~& %test-unit-end ~' + + # use the :test app to build all agents, generators, and marks + # + lensa hood '+hood/start %test' + + lensd '~& ~ ~& %test-agents-start ~' + lensa test '%agents' + lensd '~& ~ ~& %test-agents-end ~' + + lensd '~& ~ ~& %test-generators-start ~' + lensa test '%generators' + lensd '~& ~ ~& %test-generators-end ~' + + lensd '~& ~ ~& %test-marks-start ~' + lensa test '%marks' + lensd '~& ~ ~& %test-marks-end ~' + + # measure memory usage post tests + # + lensd '~& ~ ~& %test-mass-start ~' + lensa hood '+hood/mass' + lensd '~& ~ ~& %test-mass-end ~' + + # defragment the loom + # + lensd '~& ~ ~& %pack-start ~' + lensa hood '+hood/pack' + lensd '~& ~ ~& %pack-end ~' + + # reclaim space within arvo + # + lensd '~& ~ ~& %trim-start ~' + lensa hood '+hood/trim' + lensd '~& ~ ~& %trim-end ~' + + # measure memory usage pre |meld + # + lensd '~& ~ ~& %trim-mass-start ~' + lensa hood '+hood/mass' + lensd '~& ~ ~& %trim-mass-end ~' + + # globally deduplicate + # + lensd '~& ~ ~& %meld-start ~' + lensa hood '+hood/meld' + lensd '~& ~ ~& %meld-end ~' + + # measure memory usage post |meld + # + lensd '~& ~ ~& %meld-mass-start ~' + lensa hood '+hood/mass' + lensd '~& ~ ~& %meld-mass-end ~' + + lensa hood '+hood/exit' + + cleanup + + # Collect output + cp urbit-output test-output-unit + cp urbit-output test-output-agents + cp urbit-output test-output-generators + cp urbit-output test-output-marks + + # TODO: when re-enabling fake ship tests on macOS, use `sed -i ''` + # instead of `sed -i`. + sed -i '0,/test-unit-start/d' test-output-unit + sed -i '/test-unit-end/,$$d' test-output-unit + + sed -i '0,/test-agents-start/d' test-output-agents + sed -i '/test-agents-end/,$$d' test-output-agents + + sed -i '0,/test-generators-start/d' test-output-generators + sed -i '/test-generators-end/,$$d' test-output-generators + + sed -i '0,/test-marks-start/d' test-output-marks + sed -i '/test-marks-end/,$$d' test-output-marks + + OUTDIR="$$(pwd)/test-fake-ship-output" + mkdir -p $$OUTDIR + cp test-output-* $$OUTDIR + + set +x + + hdr () { + echo =====$$(sed 's/./=/g' <<< "$$1")===== + echo ==== $$1 ==== + echo =====$$(sed 's/./=/g' <<< "$$1")===== + } + + for f in $$(find "$$OUTDIR" -type f); do + hdr "$$(basename $$f)" + cat "$$f" + done + + fail=0 + + for f in $$(find "$$OUTDIR" -type f); do + if egrep "((FAILED|CRASHED)|warn:) " $$f >/dev/null; then + if [[ $$fail -eq 0 ]]; then + hdr "Test Failures" + fi + + echo "ERROR Test failure in $$(basename $$f)" + + ((fail++)) + fi + done + + if [[ $$fail -eq 0 ]]; then + hdr "Success" + fi + + zip -q -r $@ $$OUTDIR + + exit "$$fail" + """, + tools = [":urbit"], + visibility = ["//visibility:public"], +)