Skip to content

Commit

Permalink
Merge develop to next/kelvin/410 (#721)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkova authored Sep 27, 2024
2 parents 5f47598 + 736cb64 commit d7acc69
Show file tree
Hide file tree
Showing 19 changed files with 393 additions and 29 deletions.
29 changes: 28 additions & 1 deletion .github/workflows/shared.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,33 @@ jobs:
#
- uses: actions/checkout@v3

- name: Set swap space
if: ${{ matrix.target == 'linux-x86_64' || matrix.target == 'linux-aarch64'}}
run: |
echo "Memory and swap:"
free -h
echo
swapon --show
echo
export SWAP_FILE=$(swapon --show=NAME | tail -n 1)
if test -z "${SWAP_FILE}"; then
export SWAP_FILE=/swapfile
else
sudo swapoff -a
sudo rm "${SWAP_FILE}"
fi
sudo fallocate -l 10G "${SWAP_FILE}"
sudo chmod 600 "${SWAP_FILE}"
sudo mkswap "${SWAP_FILE}"
sudo swapon "${SWAP_FILE}"
echo "Memory and swap:"
free -h
echo
swapon --show
echo
- name: chown /usr/local
if: ${{ matrix.target == 'linux-x86_64' || matrix.target == 'linux-aarch64'}}
run: |
Expand All @@ -64,7 +91,7 @@ jobs:
- name: Set up build cache
uses: actions/cache@v3
with:
key: ${{ matrix.target }}-cache
key: ${{ matrix.target }}-cache-1
path: |
# # Cache bazel path on Linux.
~/.cache/bazel/_bazel_$(whoami)
Expand Down
4 changes: 2 additions & 2 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ string_flag(
# Version flag for gcc.
string_flag(
name = "gcc_version",
# musl-cross-make uses `gcc-9.4.0` by default.
build_setting_default = "9.4.0",
# musl-cross-make uses `gcc-11.4.0` by default.
build_setting_default = "11.4.0",
visibility = ["//visibility:public"],
)

Expand Down
18 changes: 18 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,21 @@ jump to definition, cross-references, hovering, symbol renaming, etc.):
```console
bazel run //bazel:refresh_compile_commands
```

### Debugging

Prefer GDB for interactive debugging. You need to compile with the symbol table:

```bash
bazel build :urbit --compilation_mode=dbg
gdb --args ./bazel-bin/pkg/vere/urbit zod
```

In GDB, set the following, and any breakpoints (e.g. `break u3m_bail`):

```gdb
set follow-fork-mode child
handle SIGSEGV nostop noprint
```

Then run the Urbit program as usual with `r`.
18 changes: 18 additions & 0 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,24 @@ versioned_http_file(
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",
Expand Down
25 changes: 8 additions & 17 deletions bazel/common_settings.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,14 @@ string_flag = rule(

def vere_library(copts = [], linkopts = [], **kwargs):
native.cc_library(
copts = copts + select({
copts = copts + [
"-fno-omit-frame-pointer",
] + select({
"//:debug": ["-O0", "-g3", "-DC3DBG", "-fdebug-compilation-dir=."],
"//conditions:default": ["-O3"]
"//conditions:default": ["-O3", "-g"]
}) + select({
"//:lto": ['-flto'],
"//:thinlto": ['-flto=thin'],
"//conditions:default": []
}) + select({
# 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.
"//:debug": [],
"@platforms//os:linux": ["-g"],
"//conditions:default": [],
}),
linkopts = linkopts + ['-g'] + select({
"//:lto": ['-flto'],
Expand All @@ -38,17 +32,14 @@ def vere_library(copts = [], linkopts = [], **kwargs):

def vere_binary(copts = [], linkopts = [], **kwargs):
native.cc_binary(
copts = copts + select({
copts = copts + [
"-fno-omit-frame-pointer",
] + select({
"//:debug": ["-O0", "-g3", "-DC3DBG", "-fdebug-compilation-dir=."],
"//conditions:default": ["-O3"]
"//conditions:default": ["-O3", "-g"]
}) + select({
"//:lto": ['-flto'],
"//:thinlto": ['-flto=thin'],
"//conditions:default": []
}) + select({
"//:debug": [],
"@platforms//os:linux": ["-g"],
"//conditions:default": [],
}),
linkopts = linkopts + ['-g'] + select({
"//:lto": ['-flto'],
Expand Down
6 changes: 6 additions & 0 deletions bazel/third_party/expat/expat.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ configure_make(
"@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"],
Expand Down
Empty file.
25 changes: 25 additions & 0 deletions bazel/third_party/libbacktrace/libbacktrace.BUILD
Original file line number Diff line number Diff line change
@@ -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"],
)
Empty file.
25 changes: 25 additions & 0 deletions bazel/third_party/libunwind/libunwind.BUILD
Original file line number Diff line number Diff line change
@@ -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"],
)
2 changes: 1 addition & 1 deletion bazel/third_party/urcrypt/urcrypt.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ configure_make(
copts = [
"-Wall",
"-g",
"-O3",
"-O2",
],
deps = [
"@aes_siv",
Expand Down
8 changes: 6 additions & 2 deletions bazel/toolchain/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,9 @@ toolchain(
# 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 = "fe915821b652a7fa37b34a596f47d8e20bc72338"
_musl_cross_make_version = "99f2cbc7e230f72bde3394be3ebd50497cb53e89"

_musl_cross_make_archive = "https://github.com/richfelker/musl-cross-make/archive/{}.tar.gz".format(_musl_cross_make_version)
_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",
Expand All @@ -349,6 +349,8 @@ genrule(
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' >> $@
Expand Down Expand Up @@ -382,6 +384,8 @@ genrule(
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' >> $@
Expand Down
7 changes: 6 additions & 1 deletion pkg/noun/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,22 @@ vere_library(
"//pkg/ent",
"//pkg/ur",
"@gmp",
"@libbacktrace",
"@murmur3",
"@openssl",
"@pdjson",
"@sigsegv",
"@softblas",
"@softfloat",
"@urcrypt",
"@whereami",
"@zlib",
] + select({
"@platforms//os:macos": ["//pkg/noun/platform/darwin"],
"@platforms//os:linux": ["//pkg/noun/platform/linux"],
"@platforms//os:linux": [
"//pkg/noun/platform/linux",
"@libunwind",
],
"//conditions:default": [],
}),
)
Expand Down
69 changes: 69 additions & 0 deletions pkg/noun/jets/c/aor.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/// @file

#include "jets/q.h"
#include "jets/w.h"

#include "noun.h"

u3_noun
u3qc_aor(u3_noun a,
u3_noun b)
{
while ( 1 ) {
if ( c3y == u3r_sing(a, b) ) return c3y;
if ( c3n == u3ud(a) ) {
if ( c3y == u3ud(b) ) return c3n;
if ( c3y == u3r_sing(u3h(a), u3h(b)) ) {
a = u3t(a);
b = u3t(b);
}
else {
a = u3h(a);
b = u3h(b);
}
}
else {
if ( c3n == u3ud(b) ) return c3y;
{
c3_w len_a_w = u3r_met(3, a);
c3_w len_b_w = u3r_met(3, b);;
c3_y *buf_a_y, *buf_b_y;
c3_y cut_a_y, cut_b_y;
if ( c3y == u3a_is_cat(a) ) {
buf_a_y = (c3_y*)&a;
}
else {
u3a_atom* a_u = u3a_to_ptr(a);
buf_a_y = (c3_y*)(a_u->buf_w);
}
if ( c3y == u3a_is_cat(b) ) {
buf_b_y = (c3_y*)&b;
}
else {
u3a_atom* b_u = u3a_to_ptr(b);
buf_b_y = (c3_y*)(b_u->buf_w);
}
c3_w len_min_w = c3_min(len_a_w, len_b_w);
for (c3_w i_w = 0; i_w < len_min_w; i_w++) {
cut_a_y = buf_a_y[i_w];
cut_b_y = buf_b_y[i_w];
if ( cut_a_y != cut_b_y ) return __(cut_a_y < cut_b_y);
}
return __(len_a_w < len_b_w);
}
}
}
}

u3_noun
u3wc_aor(u3_noun cor)
{
u3_noun a, b;

if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) ) {
return u3m_bail(c3__exit);
} else {
return u3qc_aor(a, b);
}
}

1 change: 1 addition & 0 deletions pkg/noun/jets/q.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

/** Tier 3.
**/
u3_noun u3qc_aor(u3_atom, u3_atom);
u3_noun u3qc_bex(u3_atom);
u3_noun u3qc_xeb(u3_atom);
u3_noun u3qc_can(u3_atom, u3_noun);
Expand Down
3 changes: 3 additions & 0 deletions pkg/noun/jets/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -2541,6 +2541,8 @@ static u3j_core _138_two__by_d[] =

static u3j_harm _138_two_mate_a[] = {{".2", u3wb_mate, c3y}, {}};

static u3j_harm _138_two_aor_a[] = {{".2", u3wc_aor, c3y}, {}};

static u3j_core _138_two_d[] =
{ { "tri", 3, 0, _138_tri_d, no_hashes, _140_tri_ho },

Expand All @@ -2567,6 +2569,7 @@ static u3j_core _138_two_d[] =
{ "welp", 7, _140_two_welp_a, 0, no_hashes },
{ "zing", 7, _140_two_zing_a, 0, no_hashes },

{ "aor", 7, _138_two_aor_a, 0, no_hashes },
{ "bex", 7, _140_two_bex_a, 0, no_hashes },
{ "cat", 7, _140_two_cat_a, 0, no_hashes },
{ "can", 7, _140_two_can_a, 0, no_hashes },
Expand Down
1 change: 1 addition & 0 deletions pkg/noun/jets/w.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@

/** Tier 3.
**/
u3_noun u3wc_aor(u3_noun);
u3_noun u3wc_bex(u3_noun);
u3_noun u3wc_xeb(u3_noun);
u3_noun u3wc_can(u3_noun);
Expand Down
Loading

0 comments on commit d7acc69

Please sign in to comment.