mirror of
https://github.com/urbit/vere.git
synced 2024-10-05 15:49:00 +03:00
Refactor the way arguments are passed in bazel, add -flto
This adds a macro "vere_library" which supports our concepts of debug and release builds, and gives finer-grained control over which copts/linkopts are passed and when. Takes advantage of bazel's "compilation_mode={dbg,opt}" to control debug/optimized builds.
This commit is contained in:
parent
9fac6236ed
commit
f7a75b51f0
21
.bazelrc
21
.bazelrc
@ -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'
|
||||
@ -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
BUILD.bazel
32
BUILD.bazel
@ -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
|
||||
#
|
||||
|
@ -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,
|
||||
)
|
||||
|
@ -2,7 +2,9 @@
|
||||
# LIBRARIES
|
||||
#
|
||||
|
||||
cc_library(
|
||||
load("//bazel:common_settings.bzl", "vere_library")
|
||||
|
||||
vere_library(
|
||||
name = "c3",
|
||||
srcs = glob(
|
||||
[
|
||||
|
@ -2,7 +2,9 @@
|
||||
# LIBRARIES
|
||||
#
|
||||
|
||||
cc_library(
|
||||
load("//bazel:common_settings.bzl", "vere_library")
|
||||
|
||||
vere_library(
|
||||
name = "ent",
|
||||
srcs = ["ent.c"],
|
||||
hdrs = ["ent.h"],
|
||||
|
@ -2,7 +2,9 @@
|
||||
# LIBRARIES
|
||||
#
|
||||
|
||||
cc_library(
|
||||
load("//bazel:common_settings.bzl", "vere_library")
|
||||
|
||||
vere_library(
|
||||
name = "noun",
|
||||
srcs = glob(
|
||||
[
|
||||
|
@ -2,7 +2,9 @@
|
||||
# LIBRARIES
|
||||
#
|
||||
|
||||
cc_library(
|
||||
load("//bazel:common_settings.bzl", "vere_library")
|
||||
|
||||
vere_library(
|
||||
name = "ur",
|
||||
srcs = [
|
||||
"bitstream.c",
|
||||
|
@ -2,7 +2,9 @@
|
||||
# LIBRARIES
|
||||
#
|
||||
|
||||
cc_library(
|
||||
load("//bazel:common_settings.bzl", "vere_library")
|
||||
|
||||
vere_library(
|
||||
name = "urcrypt",
|
||||
srcs = glob(
|
||||
[
|
||||
|
@ -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"],
|
||||
|
@ -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
|
||||
@ -86,7 +88,7 @@ genrule(
|
||||
# LIBRARIES
|
||||
#
|
||||
|
||||
cc_library(
|
||||
vere_library(
|
||||
name = "vere",
|
||||
srcs = glob(
|
||||
[
|
||||
@ -138,7 +140,7 @@ cc_library(
|
||||
# BINARIES
|
||||
#
|
||||
|
||||
cc_binary(
|
||||
vere_binary(
|
||||
name = "urbit",
|
||||
srcs = [
|
||||
"main.c",
|
||||
|
Loading…
Reference in New Issue
Block a user