Skip to content
Merged
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
43 changes: 8 additions & 35 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
common --enable_platform_specific_config
common:linux --host_platform=//:local_linux_platform
common:windows --host_platform=//:local_windows_platform

# Determines whether C++ binaries will be linked dynamically, interacting with the linkstatic attribute on build rules.
# off: Links all targets in mostly static mode. If -static is set in linkopts, targets will change to fully static.
Expand All @@ -8,41 +10,12 @@ build --dynamic_mode=off
build --experimental_platform_in_output_dir
build --incompatible_strict_action_env
build --compilation_mode=opt
build --features=thin_lto

# On Linux (targetting linux and macos) use the zig toolchain from hermetic_cc_toolchain
build:linux --platforms @zig_sdk//libc_aware/platform:linux_amd64_musl
build:linux --repo_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
build:linux --action_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
build:linux --host_action_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1

# Compilation Flags for zig-cc
build:linux --copt -ffunction-sections
build:linux --copt -fdata-sections
build:linux --strip=always

build:linux --features=thin_lto
# ThinLTO feature doesn't exist in Zig toolchain, so we must set the flags manually.
# It also doesn't support LTO on darwin targets, so we can't set this globally.
# Instead, we configure copt/linkopt inside the toolchain itself (with a WORKSPACE patch).
#build --copt -flto=thin

# On Windows, use the host toolchain
# NB: after https://github.com/uber/hermetic_cc_toolchain/pull/190 is included in a release,
# this flag should no longer be needed.
build:windows --noincompatible_enable_cc_toolchain_resolution
build:windows --copt=/W1
build:windows --copt=/WX
build:windows --copt=/external:W1
build:windows --copt=/diagnostics:column
build:windows --copt=/O2
build:windows --copt=/Ob2
build:windows --copt=/Oi
build:windows --copt=/D_MBCS
build:windows --copt=/DWIN32
build:windows --copt=/D_WINDOWS
build:windows --copt=/MD
build:windows --copt=/GS
build:windows --copt=/fp:precise
build:windows --copt=/Gd
build:windows --copt=/TC
common --repo_env=BAZEL_MSVC_RUNTIME_VISUAL_STUDIO_EULA=1
Comment thread
ArchangelX360 marked this conversation as resolved.
common --repo_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
build --action_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
build --host_action_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1

common --@llvm//config:experimental_stub_libgcc_s
Comment thread
ArchangelX360 marked this conversation as resolved.
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.4.1
9.1.0
46 changes: 11 additions & 35 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,65 +7,41 @@ on:
pull_request:
workflow_call:
outputs:
windows:
description: "Windows binaries"
value: ${{jobs.build_windows.outputs.artifact}}
linux:
description: "Linux and MacOS binaries"
binaries:
description: "Linux, MacOS and Windows binaries"
value: ${{jobs.build.outputs.artifact}}
permissions:
id-token: write
contents: read
attestations: write
jobs:
build:
name: darwin and linux
name: Build binaries
runs-on: ubuntu-latest
outputs:
artifact: ${{steps.upload.outputs.artifact-url}}
steps:
- uses: actions/checkout@v4
- run: |
bazel build //:for_all_platforms
mv bazel-out/darwin_arm64-opt/bin/external/libarchive\~/tar/bsdtar tar_darwin_arm64
mv bazel-out/darwin_amd64-opt/bin/external/libarchive\~/tar/bsdtar tar_darwin_amd64
mv bazel-out/linux_arm64_musl-opt/bin/external/libarchive\~/tar/bsdtar tar_linux_arm64
mv bazel-bin/external/libarchive\~/tar/bsdtar tar_linux_amd64
- uses: actions/attest-build-provenance@v2
mv bazel-out/macos_aarch64-opt/bin/external/libarchive+/tar/bsdtar tar_darwin_arm64
mv bazel-out/macos_x86_64-opt/bin/external/libarchive+/tar/bsdtar tar_darwin_amd64
mv bazel-out/linux_aarch64_musl-opt/bin/external/libarchive+/tar/bsdtar tar_linux_arm64
mv bazel-out/linux_x86_64_musl-opt/bin/external/libarchive+/tar/bsdtar tar_linux_amd64
mv bazel-out/windows_x86_64-opt/bin/external/libarchive+/tar/bsdtar.exe tar_windows_x86_64.exe
mv bazel-out/windows_aarch64-opt/bin/external/libarchive+/tar/bsdtar.exe tar_windows_arm64.exe
- uses: actions/attest-build-provenance@v4
with:
subject-path: 'tar_*'
- uses: actions/upload-artifact@v4
id: upload
with:
name: linux
name: binaries
retention-days: 1
path: |
tar_darwin_arm64
tar_darwin_amd64
tar_linux_arm64
tar_linux_amd64
build_windows:
name: windows
runs-on: windows-2022
outputs:
artifact: ${{steps.upload.outputs.artifact-url}}
steps:
- uses: actions/checkout@v4
- run: |
bazel build @libarchive//tar
mv bazel-bin/external/libarchive~/tar/bsdtar.exe tar_windows_x86_64.exe
bazel build --platforms @zig_sdk//platform:windows_arm64 @libarchive//tar
mv bazel-bin/external/libarchive~/tar/bsdtar.exe tar_windows_arm64.exe
- name: smoke test
run: ./tar_windows_x86_64.exe --help
- uses: actions/attest-build-provenance@v2
with:
subject-path: 'tar_*'
- uses: actions/upload-artifact@v4
id: upload
with:
name: windows
retention-days: 1
path: |
tar_windows_arm64.exe
tar_windows_x86_64.exe
30 changes: 22 additions & 8 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
load("@aspect_bazel_lib//lib:transitions.bzl", "platform_transition_filegroup")
load("@bazel_lib//lib:transitions.bzl", "platform_transition_filegroup")

PLATFORMS = [
"@zig_sdk//platform:darwin_amd64",
"@zig_sdk//platform:darwin_arm64",
"@zig_sdk//libc_aware/platform:linux_arm64_musl",
"@zig_sdk//libc_aware/platform:linux_amd64_musl"
"@llvm//platforms:macos_x86_64",
"@llvm//platforms:macos_aarch64",
"@llvm//platforms:linux_x86_64_musl",
"@llvm//platforms:linux_aarch64_musl",
"@llvm//platforms:windows_x86_64",
"@llvm//platforms:windows_aarch64",
]

[
platform_transition_filegroup(
name = "for_" + platform.split(":")[1],
srcs = ["@libarchive//tar"],
target_platform = platform,
tags = ["manual"],
)
for platform in PLATFORMS
]

filegroup(
name = "for_all_platforms",
srcs = ["for_" + platform.split(":")[1] for platform in PLATFORMS],
target_compatible_with = [
"@platforms//os:linux",
)

platform(
name = "local_linux_platform",
constraint_values = [
"@llvm//constraints/libc:gnu.2.28",
],
parents = ["@platforms//host"],
)

platform(
name = "local_windows_platform",
constraint_values = [
"@llvm//constraints/windows/abi:gnullvm",
],
parents = ["@platforms//host"],
)
24 changes: 13 additions & 11 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
bazel_dep(name = "aspect_bazel_lib", version = "2.15.3")
bazel_dep(name = "bazel_lib", version = "3.2.2")
bazel_dep(name = "platforms", version = "1.0.0")
bazel_dep(name = "libarchive", version = "3.8.1")
bazel_dep(name = "hermetic_cc_toolchain", version = "4.0.0")
bazel_dep(name = "llvm", version = "0.7.7")
bazel_dep(name = "xz", version = "5.4.5.bcr.8") # For compatibility with Bazel 9+
bazel_dep(name = "bzip2", version = "1.0.8.bcr.4") # For compatibility with Bazel 9+

# libarchive_bsdtar_windows_crlf.patch
# - tolerate mtree files with CRLF endings
# - TODO: remove when https://github.com/libarchive/libarchive/pull/2717 is merged
Comment thread
ArchangelX360 marked this conversation as resolved.
# libarchive_windows_mingw.patch
# - avoid redefining mode_t before MinGW sys/types.h provides it
# - link bcrypt for Windows clang/MinGW builds using libarchive's BCrypt path
single_version_override(
module_name = "libarchive",
patch_strip = 1,
patches = [
"//patches:libarchive_bsdtar_windows_crlf.patch",
"//patches:libarchive_windows_mingw.patch",
],
patch_strip = 1,
)

toolchains = use_extension("@hermetic_cc_toolchain//toolchain:ext.bzl", "toolchains")
use_repo(toolchains, "zig_sdk")
toolchains = use_extension("@llvm//extensions:toolchain.bzl", "toolchain")
use_repo(toolchains, "llvm_toolchains")

register_toolchains(
"@zig_sdk//libc_aware/toolchain:linux_arm64_musl",
"@zig_sdk//libc_aware/toolchain:linux_amd64_musl",
"@zig_sdk//toolchain:darwin_amd64",
"@zig_sdk//toolchain:darwin_arm64",
)
register_toolchains("@llvm_toolchains//:all")
41 changes: 41 additions & 0 deletions patches/libarchive_windows_mingw.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
diff --git a/libarchive_bazel_windows_config.h b/libarchive_bazel_windows_config.h
index e6473eb3..2b063ac1 100644
--- a/libarchive_bazel_windows_config.h
+++ b/libarchive_bazel_windows_config.h
@@ -118,7 +118,9 @@

#define gid_t short
#define id_t short
+#if !defined(__MINGW32__)
#define mode_t unsigned short
+#endif
#define pid_t int
#define ssize_t int64_t
#define uid_t short
diff --git a/libarchive/BUILD.bazel b/libarchive/BUILD.bazel
index 9dbef4e6..3689982d 100644
--- a/libarchive/BUILD.bazel
+++ b/libarchive/BUILD.bazel
@@ -3,6 +3,12 @@ load("//bazel:config.bzl", "PLATFORM_LOCAL_DEFINES")

package(default_visibility = ["//visibility:public"])

+config_setting(
+ name = "windows_clang",
+ constraint_values = ["@platforms//os:windows"],
+ flag_values = {"@rules_cc//cc/compiler:compiler": "clang"},
+)
+
cc_library(
name = "internal_hdrs",
hdrs = glob(["*.h"]),
@@ -168,6 +174,9 @@ cc_library(
"@rules_cc//cc/compiler:msvc-cl": [
"/DEFAULTLIB:bcrypt",
],
+ ":windows_clang": [
+ "-lbcrypt",
+ ],
"//conditions:default": [],
}),
local_defines = PLATFORM_LOCAL_DEFINES,
Loading