Skip to content

Commit

Permalink
Fix C++ build workflow (#1065)
Browse files Browse the repository at this point in the history
## 🎟️ Tracking

https://bitwarden.atlassian.net/browse/SM-1446

## 📔 Objective

Fix the C++ build workflow. Relies on changes from #1002, which will
need to be merged first.

## ⏰ Reminders before review

- Contributor guidelines followed
- All formatters and local linters executed and passed
- Written new unit and / or integration tests where applicable
- Protected functional changes with optionality (feature flags)
- Used internationalization (i18n) for all UI strings
- CI builds passed
- Communicated to DevOps any deployment requirements
- Updated any necessary documentation (Confluence, contributing docs) or
informed the documentation
  team

## 🦮 Reviewer guidelines

<!-- Suggested interactions but feel free to use (or not) as you desire!
-->

- 👍 (`:+1:`) or similar for great changes
- 📝 (`:memo:`) or ℹ️ (`:information_source:`) for notes or general info
- ❓ (`:question:`) for questions
- 🤔 (`:thinking:`) or 💭 (`:thought_balloon:`) for more open inquiry
that's not quite a confirmed
  issue and could potentially benefit from discussion
- 🎨 (`:art:`) for suggestions / improvements
- ❌ (`:x:`) or ⚠️ (`:warning:`) for more significant problems or
concerns needing attention
- 🌱 (`:seedling:`) or ♻️ (`:recycle:`) for future improvements or
indications of technical debt
- ⛏ (`:pick:`) for minor or nitpick changes

---------

Co-authored-by: Colton Hurst <[email protected]>
Co-authored-by: Colton Hurst <[email protected]>
Co-authored-by: Maciej Zieniuk <[email protected]>
  • Loading branch information
4 people authored Sep 20, 2024
1 parent dd555ce commit eeda462
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 45 deletions.
69 changes: 32 additions & 37 deletions .github/workflows/build-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ jobs:
- os: macos-13
target: x86_64-apple-darwin

# - os: windows-2022
# target: x86_64-pc-windows-msvc
- os: macos-13
target: aarch64-apple-darwin

- os: windows-2022
target: x86_64-pc-windows-msvc

- os: ubuntu-22.04
target: x86_64-unknown-linux-gnu
Expand All @@ -52,16 +55,6 @@ jobs:
brew install nlohmann-json
brew install boost
- name: Cache vcpkg
if: runner.os == 'Windows'
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: C:/vcpkg/
key: vcpkg-${{ runner.os }}-${{ matrix.settings.target }}
restore-keys: |
vcpkg-${{ runner.os }}-
vcpkg-
- name: Export GitHub Actions cache environment variables
if: runner.os == 'Windows'
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
Expand All @@ -70,22 +63,6 @@ jobs:
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
- name: Install libraries for Windows
if: runner.os == 'Windows' && steps.cache.outputs.cache-hit != 'true'
env:
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"
run: |
vcpkg install boost --binarysource="clear;x-gha,readwrite"
vcpkg install nlohmann-json --binarysource="clear;x-gha,readwrite"
shell: pwsh

- name: Save cache
if: runner.os == 'Windows'
uses: actions/cache/save@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: C:/vcpkg/
key: vcpkg-${{ runner.os }}-${{ matrix.settings.target }}

- name: Download schemas
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
Expand Down Expand Up @@ -114,6 +91,20 @@ jobs:
Get-Acl languages/cpp/include/* | Format-List
- name: Ensure bitwarden-c is in include folder
working-directory: languages/cpp
shell: bash
run: |
mv include/release/* include/
if [[ '${{ runner.os }}' == 'macOS' || '${{ runner.os }}' == 'Linux' ]]; then
ls include/libbitwarden_c.* || { echo "Missing libbitwarden_c.*"; exit 1; }
fi
if [[ '${{ runner.os }}' == 'Windows' ]]; then
ls include/bitwarden_c.dll || { echo "Missing bitwarden_c.dll"; exit 1; }
ls include/bitwarden_c.dll.lib || { echo "Missing bitwarden_c.dll.lib"; exit 1; }
fi
rmdir include/release
- name: Build unix
working-directory: languages/cpp
if: runner.os == 'macOS' || runner.os == 'Linux'
Expand All @@ -139,24 +130,28 @@ jobs:
if: runner.os == 'Windows'
working-directory: languages/cpp
env:
BOOST_INCLUDE_DIR: C:\vcpkg\installed\x64-windows\include\boost
NLOHMANN_JSON_INCLUDE_DIR: C:\vcpkg\installed\x64-windows\include\nlohmann-json
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"
run: |
mkdir build
cd build
$DNLOHMANN_PATH="C:\vcpkg\installed\x64-windows\include\nlohmann-json"
$DBOOST_PATH="C:\vcpkg\installed\x64-windows\include\boost"
$DTARGET="include/libbitwarden_c.dll"
cmake .. -DNLOHMANN=$DNLOHMANN_PATH -DBOOST=$DBOOST_PATH -DTARGET="include/libbitwarden_c.dll" -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/languages/cpp/ -DBUILD_TESTING=OFF
cmake --build .
$env:DTARGET="include\bitwarden_c.dll.lib"
cmake .. -DTARGET="$env:DTARGET" -DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_INSTALLATION_ROOT\scripts\buildsystems\vcpkg.cmake"
cmake --build . --config Release
shell: pwsh

- name: Copy artifacts
working-directory: languages/cpp/build
shell: bash
run: |
mkdir artifacts
cp libbitwarden_c.* artifacts
cp libBitwardenClient.* artifacts
if [[ '${{ runner.os }}' == 'macOS' || '${{ runner.os }}' == 'Linux' ]]; then
cp libbitwarden_c.* artifacts
cp libBitwardenClient.* artifacts
fi
if [[ '${{ runner.os }}' == 'Windows' ]]; then
cp */BitwardenClient.* artifacts
cp ../include/bitwarden_c.{lib,dll.lib,dll} artifacts
fi
- name: Upload C++ package for ${{ matrix.settings.target }}
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0
Expand Down
1 change: 1 addition & 0 deletions languages/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.15)
project(BitwardenClient)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

# Set placeholders to be passed from command line
set(NLOHMANN_JSON_INCLUDE_DIR_PLACEHOLDER ${NLOHMANN})
Expand Down
17 changes: 9 additions & 8 deletions languages/cpp/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "bitwarden-sdk-secrets",
"version": "0.1.0",
"homepage": "https://github.com/bitwarden/sdk/tree/languages/cpp",
"description": "Bitwarden Secrets Manager SDK for C++",
"dependencies": [
"boost",
"nlohmann-json"
]
"name": "bitwarden-sdk-secrets",
"version": "0.1.0",
"homepage": "https://github.com/bitwarden/sdk/tree/languages/cpp",
"description": "Bitwarden Secrets Manager SDK for C++",
"dependencies": [
"boost-uuid",
"boost-optional",
"nlohmann-json"
]
}

0 comments on commit eeda462

Please sign in to comment.