Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
14 changes: 10 additions & 4 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
alias(
name = "bzlreg",
visibility = ["//visibility:public"],
actual = "//bzlreg:bzlreg",
load("@bzlws//rules:bzlws_copy.bzl", "bzlws_copy")

bzlws_copy(
name = "copy_dist",
srcs = [
"//bzlmod:all_platforms",
"//bzlreg:all_platforms",
],
out = "dist/{FILENAME}",
force = True,
)
34 changes: 22 additions & 12 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,39 @@ bazel_dep(name = "boost.url", version = "1.83.0.bzl.2")
bazel_dep(name = "libdeflate", version = "1.19")
bazel_dep(name = "abseil-cpp", version = "20250127.0")
bazel_dep(name = "boringssl", version = "0.20250212.0")
bazel_dep(name = "bzlws", version = "0.2.0")
bazel_dep(name = "aspect_bazel_lib", version = "2.13.0")
bazel_dep(name = "hermetic_cc_toolchain", version = "3.1.1")
bazel_dep(name = "docopt.cpp")

bazel_dep(name = "toolchains_llvm", version = "1.3.0", dev_dependency = True)
bazel_dep(name = "hedron_compile_commands", dev_dependency = True)
zig_toolchains = use_extension("@hermetic_cc_toolchain//toolchain:ext.bzl", "toolchains")
use_repo(zig_toolchains, "zig_sdk", "zig_sdk-linux-amd64", "zig_sdk-linux-arm64", "zig_sdk-macos-amd64", "zig_sdk-macos-arm64", "zig_sdk-windows-amd64")

bazel_dep(name = "docopt.cpp")
register_toolchains(
"@zig_sdk//toolchain:windows_amd64",
"@zig_sdk//toolchain:linux_amd64_musl",
"@zig_sdk//toolchain:linux_arm64_musl",
"@zig_sdk//toolchain:darwin_amd64",
"@zig_sdk//toolchain:darwin_arm64",
dev_dependency = True,
)

bazel_dep(name = "hedron_compile_commands", dev_dependency = True)
git_override(
module_name = "hedron_compile_commands",
commit = "204aa593e002cbd177d30f11f54cff3559110bb9",
remote = "https://github.com/hedronvision/bazel-compile-commands-extractor.git",
)

llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm")
llvm.toolchain(llvm_version = "16.0.4")
use_repo(llvm, "llvm_toolchain")

register_toolchains(
"@llvm_toolchain//:all",
dev_dependency = True,
)

git_override(
module_name = "docopt.cpp",
commit = "e2f9cdba36c3b70883cea848a8e4d72d9b9a3fac",
remote = "https://github.com/ecsact-dev/docopt.cpp",
)

# using newer version of zig in our fork
git_override(
module_name = "hermetic_cc_toolchain",
commit = "dd09c59e690869e1e3b6d64c073f125f17c03290",
remote = "git@github.com:seaube/hermetic_cc_toolchain.git",
)
238 changes: 177 additions & 61 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

45 changes: 44 additions & 1 deletion bazel/copts.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
load("@aspect_bazel_lib//lib:transitions.bzl", "platform_transition_filegroup")
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")

PLATFORMS = [
"@zig_sdk//platform:windows_amd64",
"@zig_sdk//platform:linux_amd64",
"@zig_sdk//platform:linux_arm64",
"@zig_sdk//platform:darwin_amd64",
"@zig_sdk//platform:darwin_arm64",
]

PLATFORMS_EXT = {
"windows_amd64": ".exe",
"linux_amd64": "",
"linux_arm64": "",
"darwin_amd64": "",
"darwin_arm64": "",
}

copts = select({
("@rules_cc//cc/compiler:clang"): [
"@rules_cc//cc/compiler:clang": [
"-std=c++20",
"-fexperimental-library",
],
Expand All @@ -12,3 +31,27 @@ copts = select({
"-std=c++20",
],
})

def for_all_platforms(name):
for platform in PLATFORMS:
platform_name = platform.split(":")[1]
platform_transition_filegroup(
name = "for-{}-{}".format(platform_name, name),
srcs = [":{}".format(name)],
target_platform = platform,
)
copy_file(
name = "copy-{}-{}".format(name, platform_name),
src = ":for-{}-{}".format(platform_name, name),
out = "{}-{}{}".format(
name,
platform_name,
PLATFORMS_EXT[platform_name],
),
is_executable = True,
)

native.filegroup(
name = "all_platforms",
srcs = [":copy-{}-{}".format(name, platform.split(":")[1]) for platform in PLATFORMS],
)
4 changes: 3 additions & 1 deletion bzlmod/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
load("//bazel:copts.bzl", "copts")
load("//bazel:copts.bzl", "copts", "for_all_platforms")

package(default_visibility = ["//:__subpackages__"])

Expand Down Expand Up @@ -80,3 +80,5 @@ cc_binary(
"@docopt.cpp//:docopt",
],
)

for_all_platforms("bzlmod")
4 changes: 3 additions & 1 deletion bzlreg/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
load("//bazel:copts.bzl", "copts")
load("//bazel:copts.bzl", "copts", "for_all_platforms")

package(default_visibility = ["//:__subpackages__"])

Expand Down Expand Up @@ -152,3 +152,5 @@ cc_binary(
"@docopt.cpp//:docopt",
],
)

for_all_platforms("bzlreg")
2 changes: 1 addition & 1 deletion install.cmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@echo off

bazel build //bzlmod //bzlreg -c opt
bazel build //bzlmod //bzlreg -c dbg
xcopy /Y /F "%~dp0bazel-bin\bzlmod\bzlmod.exe" "%USERPROFILE%\.local\bin\"
xcopy /Y /F "%~dp0bazel-bin\bzlreg\bzlreg.exe" "%USERPROFILE%\.local\bin\"
Loading