Skip to content

Commit

Permalink
Merge develop to soon (#513)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkova authored Sep 8, 2023
2 parents b217982 + ef803b8 commit 99aab22
Show file tree
Hide file tree
Showing 23 changed files with 809 additions and 46 deletions.
21 changes: 8 additions & 13 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,21 @@ build --@io_bazel_rules_docker//transitions:enable=false
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 --per_file_copt='pkg/.*@-g'
build:linux --host_copt='-g'
build --strip=never

# Use -O3 as the default optimization level.
build --per_file_copt='pkg/.*@-O3'
# 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'

# Turn on 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='-DU3_CPU_DEBUG'
build --host_copt='-DU3_MEMORY_DEBUG'
build --host_copt='-DC3DBG'
Expand All @@ -45,12 +47,5 @@ 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'

# Enable maximum debug info and disable optimizations for debug config. It's
# important that these lines come after setting the default debug and
# optimization level flags above.
build:dbg --per_file_copt='pkg/.*@-O0'
build:dbg --per_file_copt='pkg/.*@-g3'
build:dbg --per_file_copt='pkg/.*@-DC3DBG'

# Any personal configuration should go in .user.bazelrc.
try-import %workspace%/.user.bazelrc
32 changes: 32 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,38 @@ config_setting(
],
)

#
# 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
#
Expand Down
5 changes: 3 additions & 2 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ bazel build :urbit
```

If you want a debug build, which changes the optimization level from `-O3` to
`-O0` and includes more debugging information, specify the `dbg` configuration:
`-O0` and includes more debugging information, specify `dbg` as the
`compilation_mode`:
```console
bazel build --config=dbg :urbit
bazel build --compilation_mode=dbg :urbit
```
Note that you cannot change the optimization level for third party
dependencies--those targets specified in `bazel/third_party`--from the command
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.11
2.12
4 changes: 2 additions & 2 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,10 @@ versioned_http_archive(
versioned_http_archive(
name = "zlib",
build_file = "//bazel/third_party/zlib:zlib.BUILD",
sha256 = "b3a24de97a8fdbc835b9833169501030b8977031bcb54b3b3ac13740f846ab30",
sha256 = "ff0ba4c292013dbc27530b3a81e1f9a813cd39de01ca5e0f8bf355702efa593e",
strip_prefix = "zlib-{version}",
url = "https://www.zlib.net/zlib-{version}.tar.gz",
version = "1.2.13",
version = "1.3",
)

#
Expand Down
47 changes: 47 additions & 0 deletions bazel/common_settings.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,50 @@ string_flag = rule(
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 + select({
"//:debug": ["-O0", "-g3", "-DC3DBG"],
"//conditions:default": ["-O3"]
}) + 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'],
"//:thinlto": ['-flto=thin'],
"//conditions:default": []
}),
**kwargs,
)

def vere_binary(copts = [], linkopts = [], **kwargs):
native.cc_binary(
copts = copts + select({
"//:debug": ["-O0", "-g3", "-DC3DBG"],
"//conditions:default": ["-O3"]
}) + select({
"//:lto": ['-flto'],
"//:thinlto": ['-flto=thin'],
"//conditions:default": []
}) + select({
"//:debug": [],
"@platforms//os:linux": ["-g"],
"//conditions:default": [],
}),
linkopts = linkopts + ['-g'] + select({
"//:lto": ['-flto'],
"//:thinlto": ['-flto=thin'],
"//conditions:default": []
}),
**kwargs,
)
9 changes: 5 additions & 4 deletions bazel/toolchain/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ _aarch64_gcc = "toolchain-gcc-linux-aarch64"

cc_toolchain_config(
name = "gcc-linux-aarch64-config",
ar = "{}/aarch64-linux-musl/bin/aarch64-linux-musl-ar".format(_install_prefix),
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",
Expand Down Expand Up @@ -104,7 +104,7 @@ _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-ar".format(_install_prefix),
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",
Expand Down Expand Up @@ -279,7 +279,7 @@ cc_toolchain_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",
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`.
Expand All @@ -288,7 +288,8 @@ cc_toolchain_config(
cc = "/usr/local/opt/llvm@15/bin/clang",
compiler = "clang",
compiler_version = "//:clang_version",
ld = "/usr/bin/ld",
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",
Expand Down
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.

4 changes: 3 additions & 1 deletion pkg/c3/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
# LIBRARIES
#

cc_library(
load("//bazel:common_settings.bzl", "vere_library")

vere_library(
name = "c3",
srcs = glob(
[
Expand Down
3 changes: 3 additions & 0 deletions pkg/c3/motes.h
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,7 @@
# define c3__ktts c3_s4('k','t','t','s')
# define c3__ktwt c3_s4('k','t','w','t')
# define c3__ktzp c3_s4('k','t','z','p')
# define c3__l c3_s1('l')
# define c3__lamb c3_s4('l','a','m','b')
# define c3__lame c3_s4('l','a','m','e')
# define c3__lang c3_s4('l','a','n','g')
Expand All @@ -686,6 +687,7 @@
# define c3__lg c3_s2('l','g')
# define c3__lib c3_s3('l','i','b')
# define c3__libd c3_s4('l','i','b','d')
# define c3__lick c3_s4('l','i','c','k')
# define c3__life c3_s4('l','i','f','e')
# define c3__lift c3_s4('l','i','f','t')
# define c3__like c3_s4('l','i','k','e')
Expand Down Expand Up @@ -1082,6 +1084,7 @@
# define c3__smts c3_s4('s','m','t','s')
# define c3__snap c3_s4('s','n','a','p')
# define c3__so c3_s2('s','o')
# define c3__soak c3_s4('s','o','a','k')
# define c3__sock c3_s4('s','o','c','k')
# define c3__soft c3_s4('s','o','f','t')
# define c3__sole c3_s4('s','o','l','e')
Expand Down
4 changes: 3 additions & 1 deletion pkg/ent/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
# LIBRARIES
#

cc_library(
load("//bazel:common_settings.bzl", "vere_library")

vere_library(
name = "ent",
srcs = ["ent.c"],
hdrs = ["ent.h"],
Expand Down
4 changes: 3 additions & 1 deletion pkg/noun/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
# LIBRARIES
#

cc_library(
load("//bazel:common_settings.bzl", "vere_library")

vere_library(
name = "noun",
srcs = glob(
[
Expand Down
4 changes: 3 additions & 1 deletion pkg/ur/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
# LIBRARIES
#

cc_library(
load("//bazel:common_settings.bzl", "vere_library")

vere_library(
name = "ur",
srcs = [
"bitstream.c",
Expand Down
4 changes: 3 additions & 1 deletion pkg/urcrypt/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
# LIBRARIES
#

cc_library(
load("//bazel:common_settings.bzl", "vere_library")

vere_library(
name = "urcrypt",
srcs = glob(
[
Expand Down
4 changes: 3 additions & 1 deletion pkg/urcrypt/ge-additions/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
cc_library(
load("//bazel:common_settings.bzl", "vere_library")

vere_library(
name = "ge-additions",
srcs = ["ge-additions.c"],
hdrs = ["ge-additions.h"],
Expand Down
6 changes: 4 additions & 2 deletions pkg/vere/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# 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
Expand Down Expand Up @@ -86,7 +88,7 @@ genrule(
# LIBRARIES
#

cc_library(
vere_library(
name = "vere",
srcs = glob(
[
Expand Down Expand Up @@ -138,7 +140,7 @@ cc_library(
# BINARIES
#

cc_binary(
vere_binary(
name = "urbit",
srcs = [
"main.c",
Expand Down
1 change: 1 addition & 0 deletions pkg/vere/auto.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ u3_auto_init(u3_pier* pir_u)
car_u = _auto_link(u3_unix_io_init(pir_u), pir_u, car_u);
car_u = _auto_link(u3_term_io_init(pir_u), pir_u, car_u);
car_u = _auto_link(u3_fore_io_init(pir_u), pir_u, car_u);
car_u = _auto_link(u3_lick_io_init(pir_u), pir_u, car_u);

return car_u;
}
10 changes: 9 additions & 1 deletion pkg/vere/io/ames.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
c3_d fod_d; // forwards dropped count
c3_d foq_d; // forward queue size
c3_d fow_d; // forwarded count
c3_o for_o; // forwarding enabled
c3_d hed_d; // failed to read header
c3_d vet_d; // version mismatches filtered
c3_d mut_d; // invalid mugs filtered
Expand Down Expand Up @@ -1993,7 +1994,9 @@ _ames_hear(u3_ames* sam_u,
&& ( (pac_u->pre_u.rec_d[0] != sam_u->pir_u->who_d[0])
|| (pac_u->pre_u.rec_d[1] != sam_u->pir_u->who_d[1]) ) )
{
_ames_try_forward(pac_u);
if ( c3y == sam_u->sat_u.for_o ) {
_ames_try_forward(pac_u);
}
}
else {
// enter protocol-specific packet handling
Expand Down Expand Up @@ -2458,6 +2461,11 @@ u3_ames_io_init(u3_pier* pir_u)
sam_u->fig_u.see_o = c3y;
sam_u->fig_u.fit_o = c3n;

// enable forwarding on galaxies only
u3_noun who = u3i_chubs(2, sam_u->pir_u->who_d);
u3_noun rac = u3do("clan:title", who);
sam_u->sat_u.for_o = ( c3__czar == rac ) ? c3y : c3n;

// hashtable for scry cache
//
// 1500 bytes per packet * 100_000 = 150MB
Expand Down
7 changes: 2 additions & 5 deletions pkg/vere/io/conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,9 @@ _conn_moor_bail(void* ptr_v, ssize_t err_i, const c3_c* err_c)

if ( err_i != UV_EOF ) {
u3l_log("conn: moor bail %zd %s", err_i, err_c);
if ( _(can_u->liv_o) ) {
_conn_send_noun(can_u, u3nq(0, c3__bail, u3i_word(err_i),
u3i_string(err_c)));
can_u->liv_o = c3n;
}
can_u->liv_o = c3n;
}

_conn_close_chan(san_u, can_u);
}

Expand Down
Loading

0 comments on commit 99aab22

Please sign in to comment.