Skip to content

Commit

Permalink
Add flag to build a static binary for easy use in various environments.
Browse files Browse the repository at this point in the history
Use CI to build a static built artifact.
  • Loading branch information
hzeller committed May 25, 2024
1 parent e544df9 commit 01db6d8
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
46 changes: 45 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
- main

jobs:
Build:
Test:
runs-on: ubuntu-24.04
steps:
- name: Checkout code
Expand Down Expand Up @@ -180,3 +180,47 @@ jobs:
run: |
clang-tidy-18 --version
CLANG_TIDY=clang-tidy-18 scripts/run-clang-tidy-cached.cc
BuildStaticBinary:
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Create Cache Timestamp
id: cache_timestamp
uses: nanzm/[email protected]
with:
format: 'YYYY-MM-DD-HH-mm-ss'

- name: Mount bazel cache
uses: actions/cache@v4
with:
path: "~/.cache/bazel"
key: bazelcache_release_${{ steps.cache_timestamp.outputs.time }}
restore-keys: bazelcache_release_

- name: Build
run: |
export CC=gcc-13
export CXX=g++-13
bazel build -c opt --//bant:create_static_linked_executables bant:bant
VERSION=$(git log --date=short --pretty=format:'%cd_%h' -n1)
OUT=bant-${VERSION}-x86
echo "OUT=${OUT}" >> $GITHUB_ENV
mkdir -p "${OUT}/bin"
install bazel-bin/bant/bant "${OUT}/bin"
strip "${OUT}/bin/bant"
# We need to pack it to retain proper unix permissions.
# Unfortunately, github packs the whole result in a *.zip archive.
tar cvzf "${OUT}.tar.gz" ${OUT}
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.OUT }}
path: ${{ env.OUT }}.tar.gz
22 changes: 22 additions & 0 deletions bant/BUILD
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("@com_github_google_rules_install//installer:def.bzl", "installer")

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

bool_flag(
name = "create_static_linked_executables",
build_setting_default = False,
)

config_setting(
name = "static_linked_executables",
flag_values = {":create_static_linked_executables": "true"},
)

installer(
name = "install",
data = [
Expand All @@ -17,6 +28,17 @@ cc_binary(
srcs = [
"bant.cc",
],
features = select({
"//bant:static_linked_executables": [
"fully_static_link",
"-supports_start_end_lib",
],
"//conditions:default": [],
}),
linkopts = select({
"//bant:static_linked_executables": ["-fuse-ld=bfd"],
"//conditions:default": [],
}),
deps = [
":session",
":types",
Expand Down

0 comments on commit 01db6d8

Please sign in to comment.