Skip to content

Commit

Permalink
Merge branch 'develop' into ted/ping
Browse files Browse the repository at this point in the history
  • Loading branch information
pkova committed Oct 20, 2023
2 parents ad238b5 + 2b024e9 commit 6ad7a1d
Show file tree
Hide file tree
Showing 48 changed files with 2,147 additions and 668 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
4 changes: 0 additions & 4 deletions .github/workflows/next.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,3 @@ jobs:
upload: true
next: ${{ github.ref_name }}
secrets: inherit

docker:
uses: ./.github/workflows/docker-shared.yml
secrets: inherit
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# IDEs.
/.vscode
/.idea

# Bazel.
/.user.bazelrc
/bazel-*
Expand Down
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
3.0
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
2 changes: 2 additions & 0 deletions pkg/c3/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@
mkdir(a, b);})
# define c3_rmdir(a) ({ \
rmdir(a);})
# define c3_link(a, b) ({ \
link(a, b);})
# define c3_unlink(a) ({ \
unlink(a);})
# define c3_fopen(a, b) ({ \
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 @@ -1083,6 +1085,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
Loading

0 comments on commit 6ad7a1d

Please sign in to comment.