Skip to content

Commit

Permalink
Add bazel build
Browse files Browse the repository at this point in the history
  • Loading branch information
JalonWong committed Jan 23, 2024
1 parent 67b1c35 commit ac74bf2
Show file tree
Hide file tree
Showing 46 changed files with 714 additions and 544 deletions.
8 changes: 8 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
common --spawn_strategy=local
common --verbose_failures
common --enable_bzlmod=false

build -c opt

build:gcc --cxxopt=-std=c++17 --host_cxxopt=-std=c++17
build:msvc --cxxopt=/std:c++17 --copt=/wd4267 --copt=/wd4244 --copt=/wd4141 --copt=/wd4805 --copt=/wd4715
207 changes: 69 additions & 138 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,75 +2,74 @@ name: Test Build
on:
push:
branches:
- master
- next
- main
pull_request:
schedule:
- cron: '0 0 * * 0' # Every Sunday at 00:00
branches:
- main
jobs:
distcheck:
strategy:
matrix:
os: [macos-latest, ubuntu-20.04]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Install Linux dependencies
if: startsWith(matrix.os, 'ubuntu')
run: sudo apt-get install -y protobuf-compiler libprotobuf-dev libprotoc-dev
- name: Install Mac dependencies
if: startsWith(matrix.os, 'macos')
run: brew install protobuf automake
- name: Run distcheck
run: |
./autogen.sh
./configure
make -j${nproc} distcheck VERBOSE=1
# distcheck:
# strategy:
# matrix:
# os: [macos-latest, ubuntu-20.04]
# runs-on: ${{ matrix.os }}
# steps:
# - uses: actions/checkout@v2
# - name: Install Linux dependencies
# if: startsWith(matrix.os, 'ubuntu')
# run: sudo apt-get install -y protobuf-compiler libprotobuf-dev libprotoc-dev
# - name: Install Mac dependencies
# if: startsWith(matrix.os, 'macos')
# run: brew install protobuf automake
# - name: Run distcheck
# run: |
# ./autogen.sh
# ./configure
# make -j${nproc} distcheck VERBOSE=1

distcheck-multiarch:
runs-on: ubuntu-20.04
strategy:
matrix:
include:
- arch: armv7
- arch: aarch64
- arch: s390x
- arch: ppc64le
steps:
- uses: actions/checkout@v2
- uses: uraimo/run-on-arch-action@v2.0.9
name: Install dependencies and run distcheck
id: runcmd
with:
arch: ${{ matrix.arch }}
githubToken: ${{ github.token }}
distro: ubuntu20.04
install: |
apt-get update -q -y
apt-get install -q -y build-essential autoconf automake libtool pkg-config
apt-get install -q -y protobuf-compiler libprotobuf-dev libprotoc-dev
# distcheck-multiarch:
# runs-on: ubuntu-20.04
# strategy:
# matrix:
# include:
# - arch: armv7
# - arch: aarch64
# - arch: s390x
# - arch: ppc64le
# steps:
# - uses: actions/checkout@v2
# - uses: uraimo/run-on-arch-action@v2.0.9
# name: Install dependencies and run distcheck
# id: runcmd
# with:
# arch: ${{ matrix.arch }}
# githubToken: ${{ github.token }}
# distro: ubuntu20.04
# install: |
# apt-get update -q -y
# apt-get install -q -y build-essential autoconf automake libtool pkg-config
# apt-get install -q -y protobuf-compiler libprotobuf-dev libprotoc-dev

run: |
./autogen.sh
./configure
make -j3 distcheck VERBOSE=1
# run: |
# ./autogen.sh
# ./configure
# make -j3 distcheck VERBOSE=1

valgrind:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: sudo apt-get install -y protobuf-compiler libprotobuf-dev libprotoc-dev valgrind
- name: Run distcheck with valgrind
run: |
./autogen.sh
./configure --enable-valgrind-tests CFLAGS="-fsanitize=undefined -fno-sanitize-recover=undefined"
make -j${nproc} distcheck DISTCHECK_CONFIGURE_FLAGS="--enable-valgrind-tests CFLAGS=\"-fsanitize=undefined -fno-sanitize-recover=undefined\"" VERBOSE=1
# valgrind:
# runs-on: ubuntu-20.04
# steps:
# - uses: actions/checkout@v4
# - name: Install dependencies
# run: sudo apt-get install -y protobuf-compiler libprotobuf-dev libprotoc-dev valgrind
# - name: Run distcheck with valgrind
# run: |
# ./autogen.sh
# ./configure --enable-valgrind-tests CFLAGS="-fsanitize=undefined -fno-sanitize-recover=undefined"
# make -j${nproc} distcheck DISTCHECK_CONFIGURE_FLAGS="--enable-valgrind-tests CFLAGS=\"-fsanitize=undefined -fno-sanitize-recover=undefined\"" VERBOSE=1

coverage:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Install dependencies
run: sudo apt-get install -y protobuf-compiler libprotobuf-dev libprotoc-dev lcov
- name: Run coverage build
Expand All @@ -86,86 +85,18 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

cmake:
bazel:
strategy:
matrix:
build_type: [Debug, Release]
os: [macos-latest, ubuntu-20.04]
os: [macos-latest, ubuntu-22.04, windows-2019]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Install Linux dependencies
if: startsWith(matrix.os, 'ubuntu')
run: sudo apt-get install -y protobuf-compiler libprotobuf-dev libprotoc-dev
- name: Install Mac dependencies
if: startsWith(matrix.os, 'macos')
run: brew install protobuf abseil
- name: Run cmake tests
run: |
mkdir build-cmake/bin
cd build-cmake/bin
cmake -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DBUILD_TESTS=ON -DCMAKE_INSTALL_PREFIX=protobuf-c-bin ../
make -j3
make test
make install
cmake-msvc:
strategy:
matrix:
build-type: [Debug, Release]
shared-lib: [ON, OFF]
name: "MSVC CMake (${{ matrix.build-type }}, DLL: ${{ matrix.shared-lib }})"
runs-on: windows-latest
env:
PROTOBUF_VERSION: 24.3
ABSEIL_VERSION: "20230802.0"
steps:
- uses: actions/checkout@v2
- uses: ilammy/msvc-dev-cmd@v1
with:
arch: amd64
- uses: actions/cache@v2
id: protobuf-cache
- uses: actions/checkout@v4
- name: Init msbuild
if: startsWith(matrix.os, 'win')
uses: microsoft/setup-msbuild@v1
with:
path: ~/protobuf-bin
key: ${{ env.PROTOBUF_VERSION }}-${{ matrix.shared-lib }}-${{ matrix.build-type}}
- uses: actions/cache@v2
id: abseil-cache
with:
path: ~/abseil-bin
key: ${{ env.ABSEIL_VERSION }}-${{ matrix.shared-lib }}-${{ matrix.build-type}}
- name: Build and install abseil
if: steps.abseil-cache.outputs.cache-hit != 'true'
run: |
cd ~
git clone --depth=1 https://github.com/abseil/abseil-cpp.git -b ${{ env.ABSEIL_VERSION }} abseil
cd ~/abseil && mkdir build && cd build
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DCMAKE_INSTALL_PREFIX=~/abseil-bin -DBUILD_SHARED_LIBS=${{ matrix.shared-lib }} -DABSL_PROPAGATE_CXX_STD=ON -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded${{ matrix.build-type == 'Debug' && 'Debug' || '' }}${{ matrix.shared-lib == 'ON' && 'DLL' || '' }} -DCMAKE_CXX_STANDARD=17 ..
nmake
nmake install
- name: Build and install utf8 compression algorithm
if: matrix.shared-lib == 'OFF'
run: |
cd ~
git clone --depth=1 https://github.com/protocolbuffers/utf8_range.git utf8_range
cd ~/utf8_range && mkdir build && cd build
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DCMAKE_INSTALL_PREFIX=~/utf8_range-bin -DCMAKE_CXX_STANDARD=17 -Dutf8_range_ENABLE_TESTS=OFF -DBUILD_SHARED_LIBS=OFF -Dabsl_ROOT=~/abseil-bin -DCMAKE_POLICY_DEFAULT_CMP0074=NEW -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_MSVC_RUNTIME_LIBRARY='MultiThreaded${{ matrix.build-type == 'Debug' && 'Debug' || '' }}' ..
nmake
nmake install
- name: Build and install protobuf
if: steps.protobuf-cache.outputs.cache-hit != 'true'
run: |
cd ~
git clone --depth=1 https://github.com/protocolbuffers/protobuf.git -b v${{ env.PROTOBUF_VERSION }} protobuf
cd ~/protobuf && mkdir build && cd build
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=~/protobuf-bin -Dprotobuf_BUILD_SHARED_LIBS=${{ matrix.shared-lib }} -DCMAKE_CXX_STANDARD=17 -Dprotobuf_BUILD_EXAMPLES=OFF -Dprotobuf_ABSL_PROVIDER=package -Dabsl_ROOT=~/abseil-bin -DABSL_PROPAGATE_CXX_STD=ON ..
nmake
nmake install
- name: Run cmake tests
run: |
mkdir build-cmake/bin
cd build-cmake/bin
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DBUILD_TESTS=ON -DCMAKE_INSTALL_PREFIX=~/protobuf-c-bin -DBUILD_SHARED_LIBS=${{ matrix.shared-lib }} -DProtobuf_ROOT="~/protobuf-bin" -Dabsl_ROOT="~/abseil-bin" -Dutf8_range_ROOT="~/utf8_range-bin" ..
nmake
nmake test
nmake install
vs-version: '[16,17)'
msbuild-architecture: x64
- name: Run tests
run: python ci.py test
71 changes: 71 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Release
on:
push:
tags:
- 'v*'
jobs:
linux:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
- name: pack
run: python ci.py release -p=protobuf-c-linux-x86_64.zip
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./protobuf-c-linux-x86_64.zip
asset_name: protobuf-c-linux-x86_64.zip
asset_content_type: application/zip

macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: pack
run: python ci.py release -p=protobuf-c-osx-x86_64.zip
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./protobuf-c-osx-x86_64.zip
asset_name: protobuf-c-osx-x86_64.zip
asset_content_type: application/zip

windows:
runs-on: windows-2019
steps:
- uses: actions/checkout@v4
- name: Init msbuild
uses: microsoft/setup-msbuild@v1
with:
vs-version: '[16,17)'
msbuild-architecture: x64
- name: pack
run: python ci.py release -p=protobuf-c-win64.zip
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./protobuf-c-win64.zip
asset_name: protobuf-c-win64.zip
asset_content_type: application/zip
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ t/version/version
*.pb-c.h
*.pb.cc
*.pb.h
/bazel-*
/.vscode
50 changes: 50 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
load("//build-bazel:base.bzl", "VER", "protobuf_cc_library")

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

cc_library(
name = "protobuf-c",
srcs = ["protobuf-c/protobuf-c.c"],
hdrs = ["protobuf-c/protobuf-c.h"],
)

protobuf_cc_library(
name = "protobuf-c_cc_proto",
srcs = ["protobuf-c/protobuf-c.proto"],
includes = [],
)

cc_binary(
name = "protoc-gen-c",
srcs = glob(["protoc-c/*.cc"]),
defines = ['PACKAGE_VERSION=\\"' + VER + '\\"'],
includes = ["protoc-c"],
deps = [
":protobuf-c",
":protobuf-c_cc_proto",
],
)

filegroup(
name = "all",
srcs = [
":protoc-gen-c",
"//protobuf-c",
],
)

test_suite(
name = "tests",
tests = [
"//t:test-generated-code",
"//t:test-generated-code2",
"//t:test-generated-code_v3",
"//t:test-version",
"//t/issue204",
"//t/issue220",
"//t/issue251",
"//t/issue330",
"//t/issue375",
"//t/issue440",
],
)
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,28 @@ If building from a git checkout, the `autotools` (`autoconf`, `automake`, `libto

./autogen.sh && ./configure && make && make install

### Use Bazel to build

```shell
bazel build :all
# Use MSVC
bazel build --config=msvc :all
```

## Test

If you want to execute test cases individually, please run the following command after running `./configure` once:

make check

### Use Bazel to test

```shell
bazel test :tests
# Use MSVC
bazel test --config=msvc :tests
```

## Documentation

See the [online Doxygen documentation here](https://protobuf-c.github.io/protobuf-c) or [the Wiki](https://github.com/protobuf-c/protobuf-c/wiki) for a detailed reference. The Doxygen documentation can be built from the source tree by running:
Expand Down
Loading

0 comments on commit ac74bf2

Please sign in to comment.