-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for building Z3 using Bazel.
Signed-off-by: Steffen Smolka <steffen.smolka@gmail.com>
- Loading branch information
Showing
6 changed files
with
159 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Use Bzlmod (`MODULE.bazel`) instead of `WORKSPACE.bazel`. | ||
common --enable_bzlmod | ||
common --noenable_workspace | ||
|
||
# Use C++20. | ||
build --cxxopt=-std=c++20 | ||
build --host_cxxopt=-std=c++20 | ||
|
||
# Use Clang. | ||
build --action_env=CC=clang | ||
build --action_env=CXX=clang++ |
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,75 @@ | ||
name: Bazel Build | ||
|
||
on: | ||
push: | ||
pull_request: | ||
|
||
jobs: | ||
build: | ||
|
||
strategy: | ||
matrix: | ||
# We only test on the oldest version we want to support and latest. | ||
# We trust that things also work for versions in the middle. | ||
os: [ubuntu-22.04, ubuntu-latest] | ||
# See Bazelisk README for legal values. | ||
bazel_version: [7.x, latest] | ||
# Don't abort other runs when one of them fails, to ease debugging. | ||
fail-fast: false | ||
|
||
runs-on: ${{ matrix.os }} | ||
|
||
env: | ||
# This tells Bazelisk (installed as `bazel`) to use specified version. | ||
# https://github.com/bazelbuild/bazelisk?tab=readme-ov-file#how-does-bazelisk-know-which-bazel-version-to-run | ||
USE_BAZEL_VERSION: ${{ matrix.bazel_version }} | ||
CACHE_KEY: bazel-${{ matrix.bazel_version }} | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Mount bazel cache | ||
uses: actions/cache/restore@v4 | ||
with: | ||
path: "~/.cache/bazel" | ||
key: ${{ env.CACHE_KEY }}-${{ hashFiles('**/*.bazel*', '**/*.bzl') }} | ||
restore-keys: | | ||
${{ env.CACHE_KEY }} | ||
- name: Save start time | ||
uses: josStorer/get-current-time@v2 | ||
id: start-time | ||
with: | ||
format: X # https://momentjs.com/docs/#/displaying/format/ | ||
|
||
- run: bazel build //... | ||
|
||
- name: Save end time | ||
# Needed to save cache regardless of build failures. | ||
if: always() | ||
uses: josStorer/get-current-time@v2 | ||
id: end-time | ||
with: | ||
format: X # https://momentjs.com/docs/#/displaying/format/ | ||
|
||
- name: Calculate build duration | ||
# Needed to save cache regardless of build failures. | ||
if: always() | ||
run: | | ||
START=${{ steps.start-time.outputs.formattedTime }} | ||
END=${{ steps.end-time.outputs.formattedTime }} | ||
DURATION=$(( $END - $START )) | ||
echo "duration=$DURATION" | tee "$GITHUB_ENV" | ||
- name: Compress cache | ||
# Needed to save cache regardless of build failures. | ||
if: always() | ||
run: rm -rf $(bazel info repository_cache) | ||
|
||
- name: Save bazel cache | ||
uses: actions/cache/save@v4 | ||
# Create new cache entry if on master branch or build takes >3mins. | ||
if: always() && (github.ref_name == 'master' || env.duration > 180) | ||
with: | ||
path: "~/.cache/bazel" | ||
key: ${{ env.CACHE_KEY }}-${{ hashFiles('**/*.bazel*', '**/*.bzl') }}-${{ github.run_id }} |
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 |
---|---|---|
|
@@ -109,3 +109,6 @@ CMakeSettings.json | |
dbg/** | ||
*.wsp | ||
CppProperties.json | ||
# Bazel generated files | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") | ||
load("@rules_license//rules:license.bzl", "license") | ||
|
||
package(default_applicable_licenses = [":license"]) | ||
|
||
license( | ||
name = "license", | ||
license_kinds = ["@rules_license//licenses/spdx:MIT"], | ||
license_text = "LICENSE.txt", | ||
) | ||
|
||
exports_files(["LICENSE.txt"]) | ||
|
||
filegroup( | ||
name = "all_files", | ||
srcs = glob(["**"]), | ||
) | ||
|
||
configure_make( | ||
name = "z3", | ||
args = [ | ||
"--directory build", | ||
# "-j8", | ||
], | ||
configure_in_place = True, | ||
env = { | ||
# See https://github.com/bazelbuild/rules_foreign_cc/issues/239. | ||
"CFLAGS": "-Dredacted=0", | ||
"CXXFLAGS": "-Dredacted=0", | ||
"PYTHON": "python3", | ||
}, | ||
lib_source = ":all_files", | ||
out_binaries = ["z3"], | ||
out_shared_libs = ["libz3.so"], | ||
targets = ["install"], | ||
visibility = ["//visibility:public"], | ||
) |
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,18 @@ | ||
module( | ||
name = "z3", | ||
version = "4.14.0", | ||
bazel_compatibility = [">=7.0.0"], | ||
) | ||
|
||
bazel_dep(name = "rules_foreign_cc", version = "0.14.0") | ||
bazel_dep(name = "rules_license", version = "1.0.0") | ||
|
||
# Enables formatting all Bazel files (.bazel, .bzl) by running: | ||
# ```bash | ||
# bazel run -- @buildifier_prebuilt//:buildifier --lint=fix -r . | ||
# ``` | ||
bazel_dep( | ||
name = "buildifier_prebuilt", | ||
version = "8.0.1", | ||
dev_dependency = True, | ||
) |
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