Skip to content

Commit

Permalink
Revert "bazel: delete bazel build system"
Browse files Browse the repository at this point in the history
This reverts commit 6d3f9b2.
  • Loading branch information
yosoyubik committed Oct 18, 2024
1 parent 4232f8e commit c4ba180
Show file tree
Hide file tree
Showing 75 changed files with 4,196 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Enable configurations specific to the host platform.
common --enable_platform_specific_config

# Disallow empty `glob()`s.
build --incompatible_disallow_empty_glob

# Don't auto-detect the C/C++ toolchain.
build --action_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1

# Use platforms to select toolchains.
# See https://bazel.build/concepts/platforms#cxx and
# https://github.com/bazelbuild/bazel/issues/7260.
build --incompatible_enable_cc_toolchain_resolution

# Disable transitions.
# See https://github.com/bazelbuild/rules_docker/issues/2052.
build --@io_bazel_rules_docker//transitions:enable=false

# Add aliases for compiler version build settings.
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 --host_copt='-g'
build --strip=never

# 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'
build --host_copt='-DU3_CPU_DEBUG'
build --host_copt='-DU3_MEMORY_DEBUG'
build --host_copt='-DC3DBG'
build --host_copt='-DU3_SNAPSHOT_VALIDATION'

# Set as per-file copts as a plain --copt gets passed to third party
# dependencies which forces recompilation (slow) if you are switching between
# including/excluding a symbol define.
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'

# Any personal configuration should go in .user.bazelrc.
try-import %workspace%/.user.bazelrc
214 changes: 214 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
load("//bazel:common_settings.bzl", "string_flag")
exports_files(["PACE"])

#
# OS-CPU CONFIG SETTINGS
#

config_setting(
name = "linux_aarch64",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:aarch64",
],
)

config_setting(
name = "linux_x86_64",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
)

config_setting(
name = "macos_aarch64",
constraint_values = [
"@platforms//os:macos",
"@platforms//cpu:aarch64",
],
)

config_setting(
name = "macos_x86_64",
constraint_values = [
"@platforms//os:macos",
"@platforms//cpu:x86_64",
],
)

#
# 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
#

# Version flag for clang.
string_flag(
name = "clang_version",
# macOS uses `clang-15.0.0` by default.
build_setting_default = "15.0.0",
visibility = ["//visibility:public"],
)

# Version flag for gcc.
string_flag(
name = "gcc_version",
# musl-cross-make uses `gcc-11.4.0` by default.
build_setting_default = "11.4.0",
visibility = ["//visibility:public"],
)

#
# PLATFORMS
#
# A platform takes one of two formats: `<compiler>-<os>-<cpu>` or `<os>-<cpu>`
# if the compiler is unspecified.

# Linux aarch64 platform with unspecified compiler.
platform(
name = "linux-aarch64",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:aarch64",
],
)

# Linux x86_64 platform with unspecified compiler.
platform(
name = "linux-x86_64",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
)

# Linux x86_64 platform with gcc.
platform(
name = "gcc-linux-x86_64",
constraint_values = [
":gcc",
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
)

platform(
name = "macos-aarch64",
constraint_values = [
"@platforms//os:macos",
"@platforms//cpu:aarch64",
],
)

platform(
name = "clang-macos-aarch64",
constraint_values = [
":clang",
"@platforms//os:macos",
"@platforms//cpu:aarch64",
],
)

platform(
name = "macos-x86_64",
constraint_values = [
"@platforms//os:macos",
"@platforms//cpu:x86_64",
],
)

platform(
name = "clang-macos-x86_64",
constraint_values = [
":clang",
"@platforms//os:macos",
"@platforms//cpu:x86_64",
],
)

# Produce the `U3_VERE_PACE` macro.
genrule(
name = "pace_hdr",
srcs = ["PACE"],
outs = ["pace.h"],
cmd = """
echo '#ifndef URBIT_PACE_H' > $@
echo '#define URBIT_PACE_H' >> $@
printf '#define U3_VERE_PACE "%s"\n' $$(cat $< | tr -d '\n') >> $@
echo '#endif' >> $@
""",
visibility = ["//:__subpackages__"],
)

genrule(
name = "version_str",
srcs = [
# Bazel warns dependency checking directories is unsound, but there's no
# apparent way around depending on .git if we want to run git commands.
".git",
"PACE",
"VERSION",
],
outs = ["version"],
cmd = """
version_num=$$(cat $(execpath VERSION) | tr -d '\n')
commit_sha=$$(git rev-parse --short HEAD)
if [ $$(tr -d '\n' < $(execpath PACE)) == "live" ]; then
version="$$version_num"
else
version="$$version_num-$$commit_sha"
fi
echo -n $$version > $@
""",
visibility = ["//:__subpackages__"],
)

# Produce the `URBIT_VERSION` macro.
genrule(
name = "version_hdr",
srcs = [":version_str"],
outs = ["version.h"],
cmd = """
echo '#ifndef URBIT_VERSION_H' > $@
echo '#define URBIT_VERSION_H' >> $@
printf '#define URBIT_VERSION "%s"\n' $$(cat $< | tr -d '\n') >> $@
echo '#endif' >> $@
""",
visibility = ["//:__subpackages__"],
)

alias(
name = "urbit",
actual = "//pkg/vere:urbit",
)
1 change: 1 addition & 0 deletions PACE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
once
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.1
Loading

0 comments on commit c4ba180

Please sign in to comment.