Skip to content

Commit

Permalink
[build] CMake: add Maven build functionality
Browse files Browse the repository at this point in the history
Add Python script to package libraries

Shortened if statement (thanks Tyler!)

Remove scrapped CMake archiver

Package up headers

Install source files

Add BUILD_MAVEN option to README-CMAKE.md

[ci] Build maven artifacts in CI

Fix cmake build with BUILD_MAVEN=ON

Fix wpigui install

Split CMake Maven build matrix to separate job

Package up source files

Fix up RIO compiler detection

Test RIO build

Build protobuf into wpiutil for CMake Maven builds

Install JNI headers

Manually set Java include dirs

Put platform variables in their own module

Add OpenCV finder

Fix protobuf

Use build config RelWithDebInfo

Fix protobuf

Grab JNI headers
Downloaded from GitHub on suggestion of Thad

Remove Release config

Add NI Libraries finder

Update CI

Link NI Libraries to the HAL and build Athena HAL

Fix CI

Grab NI runtime library

Disable tests on the RIO build

Don't use vcpkg for CMake Maven and unify Maven builds

Disable examples and sim modules for the RIO build

Disable use-after-free warning for EigenJNI

Grab protoc for Windows

Fix protoc on Mac

Fix compiler warnings

Properly download protoc and fix Windows build

Move flags around and upload artifacts

Allow specifying source directories

Unify protoc and Java setup and setup Python

Fix up packager script

Fetch all tags

Make Windows tests work

Add artifact option to control location
Using the project name is a bad assumption, and breaks on the Glass libs

Install JNI headers without extra native-headers directory

Add full Debug/RelWithDebInfo matrix and Windows ARM64 build

Build universal Mac binaries

Add full Linux matrix

Update toolchain files

Suppress warning

Install and package apps

Add workspace as safe dir and print git result

Sign macOS apps and refactor packaging script

Refactor find modules to use FetchContent

Use Artifactory for sccache

Fetch libssh artifacts

Sign dylibs on Mac

Install everything to artifact dirs, make less assumptions in Python script
Also add more info to CMake build

Setup Maven build for sim extensions and fieldImages

Match native-utils flags for MSVC
  • Loading branch information
Gold856 committed Aug 22, 2024
1 parent 7a2604b commit 2e4d354
Show file tree
Hide file tree
Showing 40 changed files with 1,223 additions and 226 deletions.
166 changes: 166 additions & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,169 @@ jobs:
working-directory: build-cmake
# UnitTest_test segfaults on exit occasionally
run: ctest --output-on-failure -E 'UnitTest'

build-maven:
strategy:
fail-fast: false
matrix:
config: [Debug, RelWithDebInfo]
name: [RIO, Linux Arm32, Linux Arm64, Linux x86-64, macOS, Windows x86-64, Windows ARM64]
include:
- os: ubuntu-22.04
name: RIO
container: wpilib/roborio-cross-ubuntu:2024-22.04
flags: "--preset ci-maven-linux-cross --toolchain ./cmake/toolchains/arm-frc-gnueabi.toolchain.cmake -DWITH_SIMULATION_MODULES=OFF -DWITH_GUI=OFF"
protoc-archive: protoc-21.12-linux-x86_64.zip
install-location: /tmp/install
- os: ubuntu-22.04
name: Linux Arm32
container: wpilib/raspbian-cross-ubuntu:bullseye-22.04
flags: "--preset ci-maven-linux-cross --toolchain ./cmake/toolchains/arm-pi-gnueabihf.toolchain.cmake"
protoc-archive: protoc-21.12-linux-x86_64.zip
install-location: /tmp/install
- os: ubuntu-22.04
name: Linux Arm64
container: wpilib/aarch64-cross-ubuntu:bullseye-22.04
flags: "--preset ci-maven-linux-cross --toolchain ./cmake/toolchains/aarch64-bullseye-gnu.toolchain.cmake"
protoc-archive: protoc-21.12-linux-x86_64.zip
install-location: /tmp/install
- os: ubuntu-22.04
name: Linux x86-64
container: wpilib/ubuntu-base:22.04
flags: "--preset ci-maven-unix"
protoc-archive: protoc-21.12-linux-x86_64.zip
install-location: /tmp/install
- os: macOS-14
name: macOS
container: ""
env: "PATH=\"/opt/homebrew/opt/protobuf@3/bin:$PATH\""
flags: "--preset ci-maven-unix '-DCMAKE_OSX_ARCHITECTURES=arm64;x86_64' -DCMAKE_LIBRARY_PATH=/opt/homebrew/opt/protobuf@3/lib"
protoc-archive: protoc-21.12-osx-universal_binary.zip
install-location: /tmp/install
- os: windows-2022
name: Windows x86-64
container: ""
msvc: amd64
flags: "--preset ci-maven '-DProtobuf_PROTOC_EXECUTABLE=bin/protoc.exe' '-DPROTOC_COMPILER=bin/protoc.exe'"
protoc-archive: protoc-21.12-win64.zip
install-location: D:/install
- os: windows-2022
name: Windows ARM64
container: ""
msvc: amd64_arm64
flags: "--preset ci-maven -DWITH_TESTS=OFF '-DProtobuf_PROTOC_EXECUTABLE=bin/protoc.exe' '-DPROTOC_COMPILER=bin/protoc.exe'"
protoc-archive: protoc-21.12-win64.zip
install-location: D:/install

name: "Build Maven - ${{ matrix.name }} ${{ matrix.config }}"
runs-on: ${{ matrix.os }}
container: ${{ matrix.container }}
steps:
- name: Install dependencies (Linux)
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y libprotobuf-dev ninja-build

- name: Install dependencies (macOS)
run: brew install protobuf@3 ninja
if: runner.os == 'macOS'

- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 17

- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: '3.10'

- uses: ilammy/msvc-dev-cmd@v1.13.0
with:
arch: ${{ matrix.msvc }}
if: runner.os == 'Windows'

- name: Download JNI headers (Linux)
if: runner.os == 'Linux' && matrix.name != 'Linux x86-64'
run: |
mkdir /tmp/jni/
wget https://raw.githubusercontent.com/openjdk/jdk21/master/src/java.base/unix/native/include/jni_md.h -O /tmp/jni/jni_md.h
wget https://raw.githubusercontent.com/openjdk/jdk21/master/src/java.base/share/native/include/jni.h -O /tmp/jni/jni.h
- name: Install CMake
if: runner.os == 'Windows'
uses: lukka/get-cmake@v3.29.3

- name: Run sccache-cache
uses: mozilla-actions/sccache-action@v0.0.5

- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true

- name: Add workspace as safe directory (Container)
if: matrix.container != ''
run: git config --global --add safe.directory /__w/allwpilib/allwpilib

- name: Download protoc
run: curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v21.12/${{ matrix.protoc-archive }}

- name: Unpack protoc
if: runner.os != 'Windows'
run: unzip ${{ matrix.protoc-archive }}

- name: Unpack protoc (Windows)
if: runner.os == 'Windows'
run: tar -xf ${{ matrix.protoc-archive }}

- name: configure
run: cmake -DCMAKE_INSTALL_PREFIX=${{ matrix.install-location }} -DCMAKE_BUILD_TYPE=${{ matrix.config }} ${{ matrix.flags }}

- name: build
working-directory: build-cmake
run: cmake --build . --parallel $(nproc) --target install
env:
SCCACHE_WEBDAV_ENDPOINT: https://frcmaven.wpi.edu/artifactory/wpilib-generic-gradle-cache-local
SCCACHE_WEBDAV_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
SCCACHE_WEBDAV_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}

- name: test
if: runner.os != 'Windows'
working-directory: build-cmake
run: ctest --output-on-failure

- name: test (Windows)
if: runner.os == 'Windows'
working-directory: build
# UnitTest_test segfaults on exit occasionally
run: ctest --output-on-failure -E 'UnitTest'

- name: Import Developer ID Certificate
uses: wpilibsuite/import-signing-certificate@v2
with:
certificate-data: ${{ secrets.APPLE_CERTIFICATE_DATA }}
certificate-passphrase: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
keychain-password: ${{ secrets.APPLE_KEYCHAIN_PASSWORD }}
if: |
matrix.artifact-name == 'macOS' && (github.repository_owner == 'wpilibsuite' &&
(github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')))
- name: Set Keychain Lock Timeout
run: security set-keychain-settings -lut 3600
if: |
matrix.artifact-name == 'macOS' && (github.repository_owner == 'wpilibsuite' &&
(github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')))
- name: Sign macOS apps
run: python library_packager.py --install_directory ${{ matrix.install-location }} sign --developer_id ${{ secrets.APPLE_DEVELOPER_ID }}
if: |
matrix.artifact-name == 'macOS' && (github.repository_owner == 'wpilibsuite' &&
(github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')))
- name: Package artifacts
run: python library_packager.py --install_directory ${{ matrix.install-location }} package

- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.name }} ${{ matrix.config }}
path: ${{ matrix.install-location }}/*.zip
65 changes: 53 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

# Options for building certain parts of the repo. Everything is built by default.
option(BUILD_SHARED_LIBS "Build with shared libs (needed for JNI)" ON)
option(BUILD_MAVEN "Build Maven artifacts")
option(WITH_JAVA "Include Java and JNI in the build" OFF)
option(WITH_JAVA_SOURCE "Build Java source jars" ${WITH_JAVA})
option(WITH_CSCORE "Build cscore (needs OpenCV)" ON)
Expand Down Expand Up @@ -132,39 +133,79 @@ find_package(LIBSSH 0.7.1)

set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON)
set(protobuf_MODULE_COMPATIBLE ON CACHE BOOL "" FORCE)
find_package(Protobuf REQUIRED)
if(BUILD_MAVEN)
find_package(Protobuf MODULE REQUIRED)
if(MSVC)
set_target_properties(
protobuf::protoc
PROPERTIES
IMPORTED_LOCATION_DEBUG ${Protobuf_PROTOC_EXECUTABLE}
IMPORTED_LOCATION_RELWITHDEBINFO ${Protobuf_PROTOC_EXECUTABLE}
)
endif()
else()
find_package(Protobuf REQUIRED)
endif()
find_program(PROTOC_COMPILER protoc REQUIRED)
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG OFF)

get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)

if(isMultiConfig)
if(NOT "Asan" IN_LIST CMAKE_CONFIGURATION_TYPES)
list(APPEND CMAKE_CONFIGURATION_TYPES Asan)
endif()
if(NOT "Tsan" IN_LIST CMAKE_CONFIGURATION_TYPES)
list(APPEND CMAKE_CONFIGURATION_TYPES Tsan)
endif()
if(NOT "Ubsan" IN_LIST CMAKE_CONFIGURATION_TYPES)
list(APPEND CMAKE_CONFIGURATION_TYPES Ubsan)
if(BUILD_MAVEN)
list(REMOVE_ITEM CMAKE_CONFIGURATION_TYPES MinSizeRel Release)
else()
if(NOT "Asan" IN_LIST CMAKE_CONFIGURATION_TYPES)
list(APPEND CMAKE_CONFIGURATION_TYPES Asan)
endif()
if(NOT "Tsan" IN_LIST CMAKE_CONFIGURATION_TYPES)
list(APPEND CMAKE_CONFIGURATION_TYPES Tsan)
endif()
if(NOT "Ubsan" IN_LIST CMAKE_CONFIGURATION_TYPES)
list(APPEND CMAKE_CONFIGURATION_TYPES Ubsan)
endif()
endif()
else()
set(allowedBuildTypes
set(allowedBuildTypes Debug RelWithDebInfo)
set(cmake_only_build_types
Asan
Tsan
Ubsan
Debug
Release
RelWithDebInfo
MinSizeRel
)
if(NOT BUILD_MAVEN)
set(allowedBuildTypes ${allowedBuildTypes} ${cmake_only_build_types})
endif()
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "${allowedBuildTypes}")

if(CMAKE_BUILD_TYPE AND NOT CMAKE_BUILD_TYPE IN_LIST allowedBuildTypes)
message(FATAL_ERROR "Invalid build type: ${CMAKE_BUILD_TYPE}")
endif()
endif()

if(BUILD_MAVEN AND MSVC)
string(
REGEX REPLACE
"/INCREMENTAL( |$)"
"/INCREMENTAL:NO "
CMAKE_SHARED_LINKER_FLAGS_DEBUG
${CMAKE_SHARED_LINKER_FLAGS_DEBUG}
)
string(
REGEX REPLACE
"/INCREMENTAL( |$)"
"/INCREMENTAL:NO "
CMAKE_EXE_LINKER_FLAGS_DEBUG
${CMAKE_EXE_LINKER_FLAGS_DEBUG}
)

string(APPEND CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO " /OPT:REF,ICF")
string(APPEND CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO " /OPT:REF,ICF")

string(APPEND CMAKE_SHARED_LINKER_FLAGS "/PDBALTPATH:%_PDB% /DEPENDENTLOADFLAG:0x1100")
string(APPEND CMAKE_EXE_LINKER_FLAGS "/PDBALTPATH:%_PDB% /DEPENDENTLOADFLAG:0x1100")
endif()
set(CMAKE_C_FLAGS_ASAN
"${CMAKE_C_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer"
CACHE STRING
Expand Down
34 changes: 33 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,38 @@
"cacheVariables": {
"WITH_JAVA": "ON"
}
},
{
"name": "ci-maven",
"description": "Maven config",
"inherits": "with-java",
"cacheVariables": {
"BUILD_MAVEN": true,
"Protobuf_INCLUDE_DIR": "wpiutil/src/main/native/thirdparty/protobuf/include",
"WITH_EXAMPLES": true
}
},
{
"name": "ci-maven-unix",
"description": "Maven config for compiling on *nix platforms",
"inherits": ["ci-maven", "sccache"],
"cacheVariables": {
"Protobuf_INCLUDE_DIR": "wpiutil/src/main/native/thirdparty/protobuf/include",
"Protobuf_PROTOC_EXECUTABLE": "bin/protoc",
"PROTOC_COMPILER": "bin/protoc"
}
},
{
"name": "ci-maven-linux-cross",
"description": "Maven config for cross-compiling Linux",
"inherits": "ci-maven-unix",
"cacheVariables": {
"Protobuf_LIBRARIES": "/usr/lib/x86_64-linux-gnu",
"JAVA_INCLUDE_PATH": "/tmp/jni/",
"JAVA_INCLUDE_PATH2": "/tmp/jni/",
"JAVA_JVM_LIBRARY": "$JAVA_HOME/lib/libjvm.so",
"WITH_TESTS": false
}
}
]
}
}
2 changes: 2 additions & 0 deletions README-CMAKE.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ The following build options are available:

* `BUILD_SHARED_LIBS` (ON Default)
* This option will cause CMake to build static libraries instead of shared libraries. If this is off, `WITH_JAVA` must be off. Otherwise CMake will error.
* `BUILD_MAVEN` (OFF Default)
* This option will build wpilib with maven artifacts.
* `WITH_CSCORE` (ON Default)
* This option will cause cscore to be built. Turning this off will implicitly disable cameraserver. If this is off, the OpenCV build requirement is removed.
* `WITH_EXAMPLES` (OFF Default)
Expand Down
Loading

0 comments on commit 2e4d354

Please sign in to comment.