Skip to content

Commit

Permalink
Build packages via Bazel
Browse files Browse the repository at this point in the history
  • Loading branch information
kiron1 committed Jul 29, 2023
1 parent fbdcc9f commit 8e9e84e
Show file tree
Hide file tree
Showing 40 changed files with 1,535 additions and 275 deletions.
29 changes: 29 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,33 @@ build --verbose_failures

build --flag_alias=features=//:features

build --verbose_failures

test --test_output=errors

build --enable_platform_specific_config

build:macos --apple_crosstool_top=@local_config_apple_cc//:toolchain
build:macos --crosstool_top=@local_config_apple_cc//:toolchain
build:macos --host_crosstool_top=@local_config_apple_cc//:toolchain

build:x86_64_apple_darwin --platforms=:x86_64-apple-darwin
build:x86_64_apple_darwin --cpu=darwin_x86_64

build:aarch64_apple_darwin --platforms=:aarch64-apple-darwin
build:aarch64_apple_darwin --cpu=darwin_arm64

# Always display the flags being used
common:ci --announce_rc

# UI for cleaner CI output
common:ci --color=no
common:ci --curses=no
common:ci --show_timestamps
common:ci --ui_event_filters=-info
common:ci --noshow_progress

build:ci --disk_cache=~/.cache/bazel_build_cache
build:ci --repository_cache=~/.cache/bazel_repo_cache

try-import %workspace%/user.bazelrc
160 changes: 114 additions & 46 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,138 @@ on:
pull_request:
branches: [ main ]

# defaults:
# run:
# shell: bash

env:
# https://github.com/bazelbuild/bazel/issues/3001
# MSYS2_ARG_CONV_EXCL: "*"
# MSYS_NO_PATHCONV: 1
RUSTFLAGS: -Dwarnings

jobs:
build_and_test:
name: Build and test

version:
name: Current proxydetox version
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Run version
id: version
run: |
bazel build --config=ci //:version
printf 'version=%s-%s\n' "$(cat bazel-bin/version.txt)" "$(git rev-parse --short=10 HEAD)" >> "${GITHUB_OUTPUT}"
bazel_build_and_test:
name: Bazel build and test
runs-on: ${{ matrix.os }}

needs: version

strategy:
matrix:
build:
- macos-aarch64
- macos-x86_64
- ubuntu-20.04
- ubuntu-22.04
- windows
# - windows
include:
- build: ubuntu-20.04
os: ubuntu-20.04
mkcmd: ./tools/mkdeb.sh -d focal
- build: ubuntu-22.04
os: ubuntu-22.04
mkcmd: ./tools/mkdeb.sh -d jammy
- build: macos-aarch64
os: macos-latest
mkcmd: ./tools/mkpkg.sh -a aarch64 -t aarch64-apple-darwin
buildflags: --features=negotiate --config=aarch64_apple_darwin
dotest: false
pkgfile: proxydetox-${{ needs.version.outputs.version }}-aarch64-apple-darwin.pkg
- build: macos-x86_64
os: macos-latest
mkcmd: ./tools/mkpkg.sh
buildflags: --features=negotiate --config=x86_64_apple_darwin
dotest: true
pkgfile: proxydetox-${{ needs.version.outputs.version }}-x86_64-apple-darwin.pkg
- build: ubuntu-20.04
os: ubuntu-20.04
buildflags: --features=negotiate
dotest: true
pkgfile: proxydetox-${{ needs.version.outputs.version }}-x86_64-focal.deb
- build: ubuntu-22.04
os: ubuntu-22.04
buildflags: --features=negotiate
dotest: true
pkgfile: proxydetox-${{ needs.version.outputs.version }}-x86_64-jammy.deb
# - build: windows
# os: windows-latest
# buildflags: --features=negotiate
# dotest: true
# pkgfile: proxydetox-${{ needs.version.outputs.version }}-x86_64-linux.zip

steps:
- name: Git checkout with LF
run: |
git config --global core.autocrlf false
git config --global core.eol lf
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Bazel cache
uses: actions/cache@v3
with:
path: |
~/.cache/bazel_build_cache
~/.cache/bazel_repo_cache
key: ${{ runner.os }}-bazel-${{ hashFiles('Cargo.Bazel.lock', 'WORKSPACE') }}
restore-keys: |
${{ runner.os }}-bazel-
- name: Setup Windows Bazelrc
# https://bazel.build/configure/windows
run: |
echo "startup --output_user_root=C:/tmp" > ${{ github.workspace }}/user.bazelrc
if: startswith(matrix.os, 'windows')
- name: Install Linux dependency
run: sudo apt-get install libkrb5-dev
if: startswith(matrix.os, 'ubuntu')
# see https://github.com/rust-lang/rust-bindgen/issues/1797
- name: Install Windows dependency (LLVM)
uses: KyleMayes/[email protected]
if: startswith(matrix.os, 'windows')
with:
version: "11.0"
directory: ${{ runner.temp }}/llvm
- name: Set LIBCLANG_PATH
run: echo "LIBCLANG_PATH=$((gcm clang).source -replace "clang.exe")" >> $env:GITHUB_ENV
if: startswith(matrix.os, 'windows')
- name: Run tests
run: 'bazel test --config=ci ${{ matrix.buildflags }} "//..."'
if: ${{ matrix.dotest }}
- name: Build package
run: bazel build -c opt --config=ci ${{ matrix.buildflags }} //pkg
- name: Query package file
id: querypkg
run: |
BAZEL_OUT=$(bazel info --config=ci output_path)
PKGFILE=$(bazel cquery --config=ci ${{ matrix.buildflags }} --output=files //pkg)
printf 'bazel_output_path=%s\n' "${BAZEL_OUT}" | tee -a "${GITHUB_OUTPUT}"
printf 'pkgfile=%s/%s\n' "${BAZEL_OUT}" "${PKGFILE#bazel-out/}" | tee -a "${GITHUB_OUTPUT}"
- name: Upload package artifact
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.pkgfile }}
path: ./${{ steps.querypkg.outputs.pkgfile }}

cargo_build_and_test:
name: Cargo build and test
runs-on: ${{ matrix.os }}

strategy:
matrix:
build:
- windows
include:
- build: windows
os: windows-latest
mkcmd: ./tools/mkzip.ps1
Expand All @@ -52,13 +155,6 @@ jobs:
toolchain: stable
profile: minimal
override: true
- name: Install Rust (macos-aarach64)
if: ${{ matrix.build == 'macos-aarch64' }}
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: aarch64-apple-darwin
profile: minimal
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.os }}
Expand Down Expand Up @@ -86,34 +182,6 @@ jobs:
name: ${{ steps.buildpkg.outputs.pkgfile }}
path: ./${{ steps.buildpkg.outputs.pkgfile }}

bazel_build:
name: Bazel build
runs-on: ${{ matrix.os }}

strategy:
matrix:
build: [macos]
include:
- build: macos
os: macos-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Bazel cache
uses: actions/cache@v3
with:
path: |
~/.cache/bazel_build_cache
~/.cache/bazel_repo_cache
key: ${{ runner.os }}-bazel-${{ hashFiles('Cargo.Bazel.lock', 'WORKSPACE') }}
restore-keys: |
${{ runner.os }}-bazel-
- name: Bazel build
run: bazel build --disk_cache=~/.cache/bazel_build_cache --repository_cache=~/.cache/bazel_repo_cache //macos/app:ProxydetoxApp

format_check:
name: Rust lint
runs-on: ubuntu-20.04
Expand Down
24 changes: 23 additions & 1 deletion BUILD
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
load("@bazel_skylib//rules:common_settings.bzl", "string_list_flag")
load("@bazel_skylib//rules:common_settings.bzl", "string_flag", "string_list_flag")

exports_files(
[".cargo/config.toml"],
visibility = ["//visibility:public"],
)

string_flag(
name = "version",
build_setting_default = "0",
visibility = ["//visibility:public"],
)

string_list_flag(
name = "features",
build_setting_default = [],
Expand All @@ -16,3 +22,19 @@ config_setting(
":features": "negotiate",
},
)

platform(
name = "x86_64-apple-darwin",
constraint_values = [
"@platforms//cpu:x86_64",
"@platforms//os:macos",
],
)

platform(
name = "aarch64-apple-darwin",
constraint_values = [
"@platforms//cpu:arm64",
"@platforms//os:macos",
],
)
Loading

0 comments on commit 8e9e84e

Please sign in to comment.