generated from bazel-contrib/rules-template
-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add release rules for binaries (#280)
Adds release infra for the rust binaries. --- ### Type of change - Chore (any other change that doesn't affect source or test files, such as configuration)
- Loading branch information
Matt Mackay
authored
Feb 29, 2024
1 parent
82ad68f
commit 9e2c653
Showing
12 changed files
with
347 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,7 @@ | |
**/*.whl | ||
.venv/ | ||
|
||
!third_party/** | ||
|
||
# TODO: enable when it is more stable, maybe Bazel 7.1 | ||
MODULE.bazel.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
third_party/com.github/bazel-contrib/toolchains_llvm/BUILD.bazel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
exports_files( | ||
["clang_ldd.patch"], | ||
visibility = ["//visibility:public"], | ||
) |
66 changes: 66 additions & 0 deletions
66
third_party/com.github/bazel-contrib/toolchains_llvm/clang_ldd.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
diff --git a/toolchain/cc_toolchain_config.bzl b/toolchain/cc_toolchain_config.bzl | ||
index b2aa92a..87c6614 100644 | ||
--- a/toolchain/cc_toolchain_config.bzl | ||
+++ b/toolchain/cc_toolchain_config.bzl | ||
@@ -112,8 +112,6 @@ def cc_toolchain_config( | ||
"-fdebug-prefix-map={}=__bazel_toolchain_llvm_repo__/".format(toolchain_path_prefix), | ||
] | ||
|
||
- is_xcompile = not (host_os == target_os and host_arch == target_arch) | ||
- | ||
# Default compiler flags: | ||
compile_flags = [ | ||
"--target=" + target_system_name, | ||
@@ -149,12 +147,15 @@ def cc_toolchain_config( | ||
# unused symbols are not stripped. | ||
link_libs = [] | ||
|
||
+ use_lld = True | ||
+ | ||
# Linker flags: | ||
- if host_os == "darwin" and not is_xcompile: | ||
+ if host_os == "darwin": | ||
# lld is experimental for Mach-O, so we use the native ld64 linker. | ||
# TODO: How do we cross-compile from Linux to Darwin? | ||
use_lld = False | ||
link_flags.extend([ | ||
+ "-mmacosx-version-min=11.0", | ||
"-headerpad_max_install_names", | ||
"-fobjc-link-runtime", | ||
]) | ||
@@ -175,8 +176,8 @@ def cc_toolchain_config( | ||
# always link C++ libraries. | ||
cxx_standard = compiler_configuration["cxx_standard"] | ||
stdlib = compiler_configuration["stdlib"] | ||
- if stdlib == "builtin-libc++" and is_xcompile: | ||
- stdlib = "stdc++" | ||
+ # if stdlib == "builtin-libc++": | ||
+ # stdlib = "stdc++" | ||
if stdlib == "builtin-libc++": | ||
cxx_flags = [ | ||
"-std=" + cxx_standard, | ||
@@ -186,11 +187,11 @@ def cc_toolchain_config( | ||
# For single-platform builds, we can statically link the bundled | ||
# libraries. | ||
link_flags.extend([ | ||
- "-l:libc++.a", | ||
- "-l:libc++abi.a", | ||
- "-l:libunwind.a", | ||
+ # "-l:libc++.a", | ||
+ # "-l:libc++abi.a", | ||
+ # "-l:libunwind.a", | ||
# Compiler runtime features. | ||
- "-rtlib=compiler-rt", | ||
+ # "-rtlib=compiler-rt", | ||
# To support libunwind. | ||
"-lpthread", | ||
"-ldl", | ||
@@ -207,7 +208,7 @@ def cc_toolchain_config( | ||
# have the sysroot directory on the search path and then add the | ||
# toolchain directory back after we are done. | ||
link_flags.extend([ | ||
- "-L{}/usr/lib".format(compiler_configuration["sysroot_path"]), | ||
+ # "-L{}/usr/lib".format(compiler_configuration["sysroot_path"]), | ||
"-lc++", | ||
"-lc++abi", | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
[ | ||
platform( | ||
name = "{}_{}".format(os, cpu), | ||
constraint_values = [ | ||
"@platforms//os:" + os, | ||
"@platforms//cpu:" + cpu, | ||
], | ||
visibility = ["//py/tools:__subpackages__"], | ||
) | ||
for os in [ | ||
"linux", | ||
"macos", | ||
] | ||
for cpu in [ | ||
"aarch64", | ||
"x86_64", | ||
] | ||
] | ||
|
||
LINUX_ARTIFACTS = [ | ||
"//py/tools/unpack_bin:linux", | ||
"//py/tools/venv_bin:linux", | ||
] | ||
|
||
MACOS_ARTIFACTS = [ | ||
"//py/tools/unpack_bin:macos", | ||
"//py/tools/venv_bin:macos", | ||
] | ||
|
||
sh_binary( | ||
name = "copy_release_artifacts", | ||
srcs = ["copy_release_artifacts.sh"], | ||
args = select({ | ||
"@platforms//os:linux": ["$(rlocationpaths {})".format(s) for s in LINUX_ARTIFACTS], | ||
"@platforms//os:macos": ["$(rlocationpaths {})".format(s) for s in MACOS_ARTIFACTS], | ||
}), | ||
data = select({ | ||
"@platforms//os:linux": LINUX_ARTIFACTS, | ||
"@platforms//os:macos": MACOS_ARTIFACTS, | ||
}), | ||
deps = ["@bazel_tools//tools/bash/runfiles"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env bash | ||
# Copies release files from bazel-out to a common folder so the GitHub Actions | ||
# configuration can easily find them all | ||
|
||
# --- begin runfiles.bash initialization v3 --- | ||
# Copy-pasted from the Bazel Bash runfiles library v3. | ||
set -uo pipefail; set +e; f=bazel_tools/tools/bash/runfiles/runfiles.bash | ||
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ | ||
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ | ||
source "$0.runfiles/$f" 2>/dev/null || \ | ||
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ | ||
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ | ||
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e | ||
# --- end runfiles.bash initialization v3 --- | ||
|
||
if [[ -z "${DEST:-}" ]]; then | ||
>&2 echo "ERROR: specify DEST environment variable" | ||
exit 1 | ||
fi | ||
|
||
cd $BUILD_WORKSPACE_DIRECTORY | ||
for arg in "$@" | ||
do cp -pv "$(rlocation $arg)" $DEST | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"Make releases for platforms supported by rules_py" | ||
|
||
load("@aspect_bazel_lib//lib:transitions.bzl", "platform_transition_filegroup") | ||
load("@aspect_bazel_lib//lib:copy_file.bzl", "copy_file") | ||
load("@aspect_bazel_lib//tools/release:hashes.bzl", "hashes") | ||
|
||
# buildozer: disable=function-docstring | ||
def multi_arch_rust_binary_release(name, src, os, archs = ["aarch64", "x86_64"], **kwargs): | ||
outs = [] | ||
for arch in archs: | ||
bin = Label(src).name | ||
platform_transition_filegroup( | ||
name = "{}_{}_{}_build".format(bin, os, arch), | ||
srcs = [src], | ||
target_platform = "//tools/release:{}_{}".format(os, arch), | ||
target_compatible_with = ["@platforms//os:{}".format(os)], | ||
) | ||
|
||
artifact = "{}-{}-{}".format(bin, os, arch) | ||
outs.append(artifact) | ||
copy_file( | ||
name = "copy_{}_{}_{}".format(bin, os, arch), | ||
src = "{}_{}_{}_build".format(bin, os, arch), | ||
out = artifact, | ||
target_compatible_with = ["@platforms//os:{}".format(os)], | ||
) | ||
|
||
hash_file = "{}_{}_{}.sha256".format(bin, os, arch) | ||
outs.append(hash_file) | ||
hashes( | ||
name = hash_file, | ||
src = artifact, | ||
target_compatible_with = ["@platforms//os:{}".format(os)], | ||
) | ||
|
||
native.filegroup( | ||
name = name, | ||
srcs = outs, | ||
target_compatible_with = ["@platforms//os:{}".format(os)], | ||
tags = ["manual"], | ||
**kwargs | ||
) |
Oops, something went wrong.