Skip to content

Commit

Permalink
Merge branch 'master' into jb/melt
Browse files Browse the repository at this point in the history
  • Loading branch information
joemfb committed Oct 17, 2024
2 parents f20cfa3 + be3b042 commit a4aa77e
Show file tree
Hide file tree
Showing 35 changed files with 1,925 additions and 1,157 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
/.user.bazelrc
/bazel-*
/urbit
MODULE.bazel
MODULE.bazel.lock

# Swap files.
*.swo
Expand Down
34 changes: 33 additions & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ brew install automake libtool

### Linux

After installing `automake` and `libtool`, you need to install the [musl libc] toolchain. We use [musl libc][musl libc] instead of [glibc][glibc] on Linux, which enables us to generate statically linked binaries. As a prerequisite, you need to install the [musl libc][musl libc] toolchain appropriate for your target platform.
After installing `automake`, `autoconf-archive`, and `libtool`, you need to install the [musl libc] toolchain. We use [musl libc][musl libc] instead of [glibc][glibc] on Linux, which enables us to generate statically linked binaries. As a prerequisite, you need to install the [musl libc][musl libc] toolchain appropriate for your target platform.

#### x86_64

Expand All @@ -52,6 +52,20 @@ This will take a few minutes.

After installing `automake`, `autoconf-archive`, `pkg-config`, and `libtool`, you're ready to build Vere.

#### Debugger

macOS is curious operating system because the kernel is derived from from two codebases, the Mach kernel and the BSD kernel. It inherits two different hardware exception handling facilities, Mach exceptions and POSIX signals. We use `libsigsegv` and utilize the POSIX signals which is usually fine except when it comes to debugging with `lldb`.

`lldb` hijacks the Mach exception ports for the task when it attaches to the process. Mach exceptions get handled before POSIX signals which means that as soon as vere faults (this happens often) `lldb` stop with a `EXC_BAD_ACCESS`. It is impossible to continue debugging from this state without the workaround we implemented in https://github.com/urbit/vere/pull/611.

There are more annoying warts with `lldb` currently. First, if you attach the debugger when booting the ship with `lldb -- your-ship/.run` you have to specify `-t`, otherwise the ship is unable to boot for mysterious reasons. The other option is to start the ship and attach afterwards with `lldb -p PID`. Afterwards you should do this dance:

```
p (void)darwin_register_mach_exception_handler()
pro hand -p true -s false -n false SIGBUS
pro hand -p true -s false -n false SIGSEGV
```

## Build Commands

Once you install the prerequisites, you're ready to build:
Expand Down Expand Up @@ -99,6 +113,17 @@ you can pass them with [`--per_file_copt`][per_file_copt] like so:
bazel build --per_file_copt='pkg/.*@-DMACRO'
```

## LSP Integration

```console
bazel run //bazel:refresh_compile_commands
```

Running this command will generate a `compile_commands.json` file in the root
of the repository, which `clangd` (or other language server processors) will
use automatically to provide modern editor features like syntax highlighting,
go-to definitions, call hierarchies, symbol manipulation, etc.

## Test Commands

You can build and run unit tests only on native builds. If you have a native
Expand Down Expand Up @@ -136,6 +161,13 @@ doesn't match the version of `clang` installed on your system. To address this,
run `clang --version` and pass the version number via
`--clang_version="<version_string>"` to the failing command.

If build fails on nix/NixOS, you should pass `ACLOCAL_PATH` environment
variable to bazel, using `--action_env=ACLOCAL_PATH=$ACLOCAL_PATH`, like so:

```
bazel build :urbit --action_env=ACLOCAL_PATH=$ACLOCAL_PATH
```

[^1]: If you're interested in digging into the details of the build system,
check out [`WORKSPACE.bazel`](WORKSPACE.bazel),
[`BUILD.bazel`](BUILD.bazel), [`bazel/`](bazel), and the multiple
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0
3.1
19 changes: 14 additions & 5 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,15 @@ versioned_http_file(
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",
Expand Down Expand Up @@ -253,10 +262,10 @@ versioned_http_archive(
versioned_http_archive(
name = "openssl",
build_file = "//bazel/third_party/openssl:openssl.BUILD",
sha256 = "8dee9b24bdb1dcbf0c3d1e9b02fb8f6bf22165e807f45adeb7c9677536859d3b",
sha256 = "cf3098950cb4d853ad95c0841f1f9c6d3dc102dccfcacd521d93925208b76ac8",
strip_prefix = "openssl-{version}",
url = "https://www.openssl.org/source/openssl-{version}.tar.gz",
version = "1.1.1t",
url = "https://github.com/openssl/openssl/releases/download/OpenSSL_1_1_1w/openssl-{version}.tar.gz",
version = "1.1.1w",
)

versioned_http_archive(
Expand Down Expand Up @@ -327,10 +336,10 @@ versioned_http_file(
versioned_http_archive(
name = "urcrypt",
build_file = "//bazel/third_party/urcrypt:urcrypt.BUILD",
sha256 = "afc1182e10eeebaeb2a111c2bd889747792d255e26aba7fdcd6751d0d3c2bb35",
sha256 = "d27ec04d3854da7c479dd815af92ffef986616bc7ff400022e2dfb7971853d86",
strip_prefix = "urcrypt-{version}",
url = "https://github.com/urbit/urcrypt/archive/{version}.tar.gz",
version = "43479c3262a11e20da5f6218f3b0b3d63931ceea",
version = "9ae5d604528bc54ae48430f55ebbb17b1ad7956c",
)

versioned_http_archive(
Expand Down
4 changes: 2 additions & 2 deletions bazel/common_settings.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ string_flag = rule(
def vere_library(copts = [], linkopts = [], **kwargs):
native.cc_library(
copts = copts + select({
"//:debug": ["-O0", "-g3", "-DC3DBG"],
"//:debug": ["-O0", "-g3", "-DC3DBG", "-fdebug-compilation-dir=."],
"//conditions:default": ["-O3"]
}) + select({
"//:lto": ['-flto'],
Expand All @@ -39,7 +39,7 @@ def vere_library(copts = [], linkopts = [], **kwargs):
def vere_binary(copts = [], linkopts = [], **kwargs):
native.cc_binary(
copts = copts + select({
"//:debug": ["-O0", "-g3", "-DC3DBG"],
"//:debug": ["-O0", "-g3", "-DC3DBG", "-fdebug-compilation-dir=."],
"//conditions:default": ["-O3"]
}) + select({
"//:lto": ['-flto'],
Expand Down
2 changes: 1 addition & 1 deletion bazel/third_party/avahi/avahi.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ configure_make(
"@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"],
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"],
Expand Down
2 changes: 1 addition & 1 deletion bazel/third_party/dbus/dbus.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ configure_make(
"//conditions:default": ["--jobs=`nproc`"],
}),
copts = ["-O3"],
configure_options = ["--disable-selinux --without-x --disable-tests"],
configure_options = ["--disable-selinux --without-x --disable-tests --disable-systemd --disable-apparmor"],
lib_source = ":all",
configure_in_place = True,
deps = ["@expat"],
Expand Down
Empty file.
8 changes: 8 additions & 0 deletions bazel/third_party/natpmp/natpmp.BUILD
Original file line number Diff line number Diff line change
@@ -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"],
)
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,16 @@
]
++ (with pkgs; [
autoconf
autoconf-archive
automake
bazel_5
bazel_6
binutils # for `nm`
jdk11_headless
libtool
m4
pkg-config
git
perl
]);
extraBuildCommands = ''
chmod +w usr
Expand Down
14 changes: 14 additions & 0 deletions pkg/c3/defs.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
#include "defs.h"

c3_s
c3_sift_short(c3_y buf_y[2]);
c3_w
c3_sift_word(c3_y buf_y[4]);
c3_d
c3_sift_chub(c3_y byt_y[8]);

void
c3_etch_short(c3_y buf_y[2], c3_s sot_s);
void
c3_etch_word(c3_y buf_y[4], c3_w wod_w);
void
c3_etch_chub(c3_y byt_y[8], c3_d num_d);

c3_w c3_align_w(c3_w x, c3_w al, align_dir hilo);
c3_d c3_align_d(c3_d x, c3_d al, align_dir hilo);
void *c3_align_p(void const * p, size_t al, align_dir hilo);
54 changes: 54 additions & 0 deletions pkg/c3/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,60 @@
| (((w) >> 8) & 0xff) << 16 \
| ( (w) & 0xff) << 24 )

inline c3_s
c3_sift_short(c3_y buf_y[2])
{
return (buf_y[1] << 8 | buf_y[0]);
}

inline c3_w
c3_sift_word(c3_y buf_y[4])
{
return (buf_y[3] << 24 | buf_y[2] << 16 | buf_y[1] << 8 | buf_y[0]);
}

inline c3_d
c3_sift_chub(c3_y byt_y[8])
{
return (c3_d)byt_y[0]
| (c3_d)byt_y[1] << 8
| (c3_d)byt_y[2] << 16
| (c3_d)byt_y[3] << 24
| (c3_d)byt_y[4] << 32
| (c3_d)byt_y[5] << 40
| (c3_d)byt_y[6] << 48
| (c3_d)byt_y[7] << 56;
}

inline void
c3_etch_short(c3_y buf_y[2], c3_s sot_s)
{
buf_y[0] = sot_s & 0xff;
buf_y[1] = (sot_s >> 8) & 0xff;
}

inline void
c3_etch_word(c3_y buf_y[4], c3_w wod_w)
{
buf_y[0] = wod_w & 0xff;
buf_y[1] = (wod_w >> 8) & 0xff;
buf_y[2] = (wod_w >> 16) & 0xff;
buf_y[3] = (wod_w >> 24) & 0xff;
}

inline void
c3_etch_chub(c3_y byt_y[8], c3_d num_d)
{
byt_y[0] = num_d & 0xff;
byt_y[1] = (num_d >> 8) & 0xff;
byt_y[2] = (num_d >> 16) & 0xff;
byt_y[3] = (num_d >> 24) & 0xff;
byt_y[4] = (num_d >> 32) & 0xff;
byt_y[5] = (num_d >> 40) & 0xff;
byt_y[6] = (num_d >> 48) & 0xff;
byt_y[7] = (num_d >> 56) & 0xff;
}

/* Asserting allocators.
*/
# define c3_free(s) free(s)
Expand Down
1 change: 1 addition & 0 deletions pkg/c3/motes.h
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,7 @@
# define c3__pril c3_s4('p','r','i','l')
# define c3__pro c3_s3('p','r','o')
# define c3__prod c3_s4('p','r','o','d')
# define c3__prop c3_s4('p','r','o','p')
# define c3__prof c3_s4('p','r','o','f')
# define c3__prox c3_s4('p','r','o','x')
# define c3__psdg c3_s4('p','s','d','g')
Expand Down
Loading

0 comments on commit a4aa77e

Please sign in to comment.