Skip to content

Commit f65ae7d

Browse files
authored
Merge pull request #304 from Yubico/dennisdyallo/build-improvements
refactor(build): streamline version handling in build scripts
2 parents 8b6bf04 + c122327 commit f65ae7d

File tree

9 files changed

+128
-72
lines changed

9 files changed

+128
-72
lines changed

.github/workflows/build-nativeshims.yml

Lines changed: 24 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,12 @@ jobs:
3838
- run: |
3939
echo 'Running build script: Windows'
4040
cd Yubico.NativeShims
41-
& ./build-windows.ps1
42-
- name: Set version
43-
if: github.event.inputs.version
44-
shell: pwsh
45-
run: |
46-
$version = "${{ github.event.inputs.version }}"
47-
# Update CMakeLists.txt
48-
(Get-Content Yubico.NativeShims/CMakeLists.txt) -replace 'project\(Yubico.NativeShims VERSION [^)]+\)', "project(Yubico.NativeShims VERSION $version)" | Set-Content Yubico.NativeShims/CMakeLists.txt
49-
# Update vcpkg.json
50-
$vcpkg = Get-Content Yubico.NativeShims/vcpkg.json -Raw | ConvertFrom-Json
51-
$vcpkg.version = $version
52-
$vcpkg | ConvertTo-Json | Set-Content Yubico.NativeShims/vcpkg.json
53-
echo "Set version to $version"
41+
if ("${{ github.event.inputs.version }}" -ne "") {
42+
$baseVersion = "${{ github.event.inputs.version }}".Split('-')[0]
43+
& ./build-windows.ps1 -Version $baseVersion
44+
} else {
45+
& ./build-windows.ps1
46+
}
5447
- uses: actions/upload-artifact@v4
5548
with:
5649
name: win-x64
@@ -82,16 +75,12 @@ jobs:
8275
- run: |
8376
echo 'Running build script: Linux (amd64)'
8477
cd Yubico.NativeShims
85-
sh ./build-linux-amd64.sh
86-
- name: Set version
87-
if: github.event.inputs.version
88-
run: |
89-
VERSION=${{ github.event.inputs.version }}
90-
# Update CMakeLists.txt
91-
sed -i "s/project(Yubico.NativeShims VERSION [^)]*)/project(Yubico.NativeShims VERSION $VERSION)/" Yubico.NativeShims/CMakeLists.txt
92-
# Update vcpkg.json
93-
jq --arg v "$VERSION" '.version = $v' Yubico.NativeShims/vcpkg.json > tmp.json && mv tmp.json Yubico.NativeShims/vcpkg.json
94-
echo "Set version to $VERSION"
78+
if [ ! -z "${{ github.event.inputs.version }}" ]; then
79+
BASE_VERSION=$(echo "${{ github.event.inputs.version }}" | cut -d'-' -f1)
80+
sh ./build-linux-amd64.sh "$BASE_VERSION"
81+
else
82+
sh ./build-linux-amd64.sh
83+
fi
9584
- uses: actions/upload-artifact@v4
9685
with:
9786
name: linux-x64
@@ -105,16 +94,12 @@ jobs:
10594
- run: |
10695
echo 'Running build script: Linux (arm64)'
10796
cd Yubico.NativeShims
108-
sh ./build-linux-arm64.sh
109-
- name: Set version
110-
if: github.event.inputs.version
111-
run: |
112-
VERSION=${{ github.event.inputs.version }}
113-
# Update CMakeLists.txt
114-
sed -i "s/project(Yubico.NativeShims VERSION [^)]*)/project(Yubico.NativeShims VERSION $VERSION)/" Yubico.NativeShims/CMakeLists.txt
115-
# Update vcpkg.json
116-
jq --arg v "$VERSION" '.version = $v' Yubico.NativeShims/vcpkg.json > tmp.json && mv tmp.json Yubico.NativeShims/vcpkg.json
117-
echo "Set version to $VERSION"
97+
if [ ! -z "${{ github.event.inputs.version }}" ]; then
98+
BASE_VERSION=$(echo "${{ github.event.inputs.version }}" | cut -d'-' -f1)
99+
sh ./build-linux-arm64.sh "$BASE_VERSION"
100+
else
101+
sh ./build-linux-arm64.sh
102+
fi
118103
- uses: actions/upload-artifact@v4
119104
with:
120105
name: linux-arm64
@@ -128,16 +113,12 @@ jobs:
128113
- run: |
129114
echo 'Running build script: macOS'
130115
cd Yubico.NativeShims
131-
sh ./build-macOS.sh
132-
- name: Set version
133-
if: github.event.inputs.version
134-
run: |
135-
VERSION=${{ github.event.inputs.version }}
136-
# Update CMakeLists.txt
137-
sed -i "s/project(Yubico.NativeShims VERSION [^)]*)/project(Yubico.NativeShims VERSION $VERSION)/" Yubico.NativeShims/CMakeLists.txt
138-
# Update vcpkg.json
139-
jq --arg v "$VERSION" '.version = $v' Yubico.NativeShims/vcpkg.json > tmp.json && mv tmp.json Yubico.NativeShims/vcpkg.json
140-
echo "Set version to $VERSION"
116+
if [ ! -z "${{ github.event.inputs.version }}" ]; then
117+
BASE_VERSION=$(echo "${{ github.event.inputs.version }}" | cut -d'-' -f1)
118+
sh ./build-macOS.sh "$BASE_VERSION"
119+
else
120+
sh ./build-macOS.sh
121+
fi
141122
- uses: actions/upload-artifact@v4
142123
with:
143124
name: osx-x64

Yubico.NativeShims/CMakeLists.txt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
cmake_minimum_required(VERSION 3.13)
2-
project(Yubico.NativeShims VERSION 1.12)
2+
3+
# Set default version if not provided via command line
4+
if(NOT DEFINED PROJECT_VERSION)
5+
set(PROJECT_VERSION "1.14.0")
6+
endif()
7+
8+
# Set VCPKG manifest version to match project version
9+
set(VCPKG_MANIFEST_VERSION ${PROJECT_VERSION})
10+
11+
project(Yubico.NativeShims VERSION ${PROJECT_VERSION})
312
include(CheckCCompilerFlag)
413

514
if (APPLE OR UNIX)
@@ -104,6 +113,15 @@ target_sources(
104113
ssl.cmac.c
105114
)
106115

116+
# Add Windows resource file for version info
117+
if(WIN32)
118+
target_sources(
119+
Yubico.NativeShims
120+
PRIVATE
121+
Yubico.NativeShims.rc
122+
)
123+
endif()
124+
107125
# Linker
108126
target_link_libraries(
109127
Yubico.NativeShims

Yubico.NativeShims/Yubico.NativeShims.h.in

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,13 @@
6262
* exists on the system or not.
6363
*/
6464
#cmakedefine HAVE_PCSC_WINSCARD_H @HAVE_PCSC_WINSCARD_H@
65+
66+
/**
67+
* Version information
68+
*
69+
* Pre-processor symbols that describe the version of Yubico.NativeShims.
70+
*/
71+
#define YUBICO_NATIVE_SHIMS_VERSION "@PROJECT_VERSION@"
72+
#define YUBICO_NATIVE_SHIMS_VERSION_MAJOR @PROJECT_VERSION_MAJOR@
73+
#define YUBICO_NATIVE_SHIMS_VERSION_MINOR @PROJECT_VERSION_MINOR@
74+
#define YUBICO_NATIVE_SHIMS_VERSION_PATCH @PROJECT_VERSION_PATCH@
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <windows.h>
2+
#include "Yubico.NativeShims.h"
3+
4+
VS_VERSION_INFO VERSIONINFO
5+
FILEVERSION YUBICO_NATIVE_SHIMS_VERSION_MAJOR,YUBICO_NATIVE_SHIMS_VERSION_MINOR,YUBICO_NATIVE_SHIMS_VERSION_PATCH,0
6+
PRODUCTVERSION YUBICO_NATIVE_SHIMS_VERSION_MAJOR,YUBICO_NATIVE_SHIMS_VERSION_MINOR,YUBICO_NATIVE_SHIMS_VERSION_PATCH,0
7+
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
8+
FILEFLAGS 0
9+
FILEOS VOS_NT_WINDOWS32
10+
FILETYPE VFT_DLL
11+
FILESUBTYPE VFT2_UNKNOWN
12+
BEGIN
13+
BLOCK "StringFileInfo"
14+
BEGIN
15+
BLOCK "040904B0"
16+
BEGIN
17+
VALUE "CompanyName", "Yubico AB"
18+
VALUE "FileDescription", "Yubico Native Shims Library"
19+
VALUE "FileVersion", YUBICO_NATIVE_SHIMS_VERSION
20+
VALUE "InternalName", "Yubico.NativeShims.dll"
21+
VALUE "LegalCopyright", "Copyright (c) 2025 Yubico AB. All rights reserved."
22+
VALUE "OriginalFilename", "Yubico.NativeShims.dll"
23+
VALUE "ProductName", "Yubico .NET SDK"
24+
VALUE "ProductVersion", YUBICO_NATIVE_SHIMS_VERSION
25+
END
26+
END
27+
BLOCK "VarFileInfo"
28+
BEGIN
29+
VALUE "Translation", 0x409, 1200
30+
END
31+
END

Yubico.NativeShims/build-linux-amd64.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/bin/bash
22

3+
# Get version parameter
4+
VERSION=$1
5+
36
# Set environment variables
47
export VCPKG_INSTALLATION_ROOT=$GITHUB_WORKSPACE/vcpkg \
58
PATH=/usr/local/bin:$PATH
@@ -43,9 +46,10 @@ rm -rf "$build_dir"
4346
mkdir -p "$build_dir"
4447

4548
echo "Building for x64-linux ..."
46-
cmake -S . -B "$build_dir" \
47-
-DCMAKE_BUILD_TYPE=Release \
48-
-DCMAKE_TOOLCHAIN_FILE="$VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake" \
49-
-DVCPKG_TARGET_TRIPLET=x64-linux
49+
CMAKE_ARGS="-S . -B $build_dir -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=$VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-linux"
50+
if [ ! -z "$VERSION" ]; then
51+
CMAKE_ARGS="$CMAKE_ARGS -DPROJECT_VERSION=$VERSION"
52+
fi
53+
cmake $CMAKE_ARGS
5054

5155
cmake --build "$build_dir" -- -j $(nproc)

Yubico.NativeShims/build-linux-arm64.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/bin/bash
22

3+
# Get version parameter
4+
VERSION=$1
5+
36
# Set environment variables
47
export VCPKG_INSTALLATION_ROOT=$GITHUB_WORKSPACE/vcpkg \
58
VCPKG_FORCE_SYSTEM_BINARIES=1 \
@@ -57,11 +60,10 @@ rm -rf "$build_dir"
5760
mkdir -p "$build_dir"
5861

5962
echo "Building for arm64-linux ..."
60-
cmake -S . -B "$build_dir" \
61-
-DCMAKE_BUILD_TYPE=Release \
62-
-DCMAKE_TOOLCHAIN_FILE="$VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake" \
63-
-DVCPKG_TARGET_TRIPLET="arm64-linux" \
64-
-DVCPKG_CHAINLOAD_TOOLCHAIN_FILE="$(pwd)/cmake/aarch64-linux-gnu.toolchain.cmake" \
65-
-DOPENSSL_ROOT_DIR=$(pwd)/linux-arm64/vcpkg_installed/arm64-linux
63+
CMAKE_ARGS="-S . -B $build_dir -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=$VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=arm64-linux -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=$(pwd)/cmake/aarch64-linux-gnu.toolchain.cmake -DOPENSSL_ROOT_DIR=$(pwd)/linux-arm64/vcpkg_installed/arm64-linux"
64+
if [ ! -z "$VERSION" ]; then
65+
CMAKE_ARGS="$CMAKE_ARGS -DPROJECT_VERSION=$VERSION"
66+
fi
67+
cmake $CMAKE_ARGS
6668

6769
cmake --build "$build_dir" -- -j $(nproc)

Yubico.NativeShims/build-macOS.sh

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
1+
#!/bin/bash
2+
3+
# Get version parameter
4+
VERSION=$1
5+
16
rm -rf build64 buildarm osx-arm64 osx-x64
27

38
pushd $VCPKG_INSTALLATION_ROOT
49
git checkout master
510
./bootstrap-vcpkg.sh
611
popd
712

8-
cmake \
9-
-S . \
10-
-B ./build64 \
11-
-DCMAKE_BUILD_TYPE=Release \
12-
-DCMAKE_TOOLCHAIN_FILE=$VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake \
13-
-DVCPKG_TARGET_TRIPLET=x64-osx \
14-
-DCMAKE_OSX_ARCHITECTURES=x86_64
13+
CMAKE_ARGS="-S . -B ./build64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=$VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-osx -DCMAKE_OSX_ARCHITECTURES=x86_64"
14+
if [ ! -z "$VERSION" ]; then
15+
CMAKE_ARGS="$CMAKE_ARGS -DPROJECT_VERSION=$VERSION"
16+
fi
17+
cmake $CMAKE_ARGS
1518

1619
cmake --build ./build64
1720
mkdir -p osx-x64
1821
cp ./build64/libYubico.NativeShims.dylib ./osx-x64
1922

20-
cmake \
21-
-S . \
22-
-B ./buildarm \
23-
-DCMAKE_BUILD_TYPE=Release \
24-
-DCMAKE_TOOLCHAIN_FILE=$VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake \
25-
-DVCPKG_TARGET_TRIPLET=arm64-osx \
26-
-DCMAKE_OSX_ARCHITECTURES=arm64
23+
CMAKE_ARGS="-S . -B ./buildarm -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=$VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=arm64-osx -DCMAKE_OSX_ARCHITECTURES=arm64"
24+
if [ ! -z "$VERSION" ]; then
25+
CMAKE_ARGS="$CMAKE_ARGS -DPROJECT_VERSION=$VERSION"
26+
fi
27+
cmake $CMAKE_ARGS
2728

2829
cmake --build ./buildarm
2930
mkdir -p osx-arm64
Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
1+
param(
2+
[string]$Version
3+
)
4+
15
# Update to latest vcpkg baseline
26
Push-Location $env:VCPKG_INSTALLATION_ROOT
37
git checkout master
48
.\bootstrap-vcpkg.bat
59
Pop-Location
610

711
# 32-bit builds
8-
cmake -S . -B build32 -A Win32 -DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_INSTALLATION_ROOT\scripts\buildsystems\vcpkg.cmake" -DVCPKG_TARGET_TRIPLET=x86-windows-static
12+
$cmakeArgs = @("-S", ".", "-B", "build32", "-A", "Win32", "-DCMAKE_TOOLCHAIN_FILE=$env:VCPKG_INSTALLATION_ROOT\scripts\buildsystems\vcpkg.cmake", "-DVCPKG_TARGET_TRIPLET=x86-windows-static")
13+
if ($Version) { $cmakeArgs += "-DPROJECT_VERSION=$Version" }
14+
cmake @cmakeArgs
915
cmake --build build32 --config Release
1016
New-Item -ItemType Directory -Path win-x86 -Force
1117
Copy-Item build32\Release\Yubico.NativeShims.dll win-x86
1218

1319
# 64-bit builds
14-
cmake -S . -B build64 -A x64 -DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_INSTALLATION_ROOT\scripts\buildsystems\vcpkg.cmake" -DVCPKG_TARGET_TRIPLET=x64-windows-static
20+
$cmakeArgs = @("-S", ".", "-B", "build64", "-A", "x64", "-DCMAKE_TOOLCHAIN_FILE=$env:VCPKG_INSTALLATION_ROOT\scripts\buildsystems\vcpkg.cmake", "-DVCPKG_TARGET_TRIPLET=x64-windows-static")
21+
if ($Version) { $cmakeArgs += "-DPROJECT_VERSION=$Version" }
22+
cmake @cmakeArgs
1523
cmake --build build64 --config Release
1624
New-Item -ItemType Directory -Path win-x64 -Force
1725
Copy-Item build64\Release\Yubico.NativeShims.dll win-x64
1826

1927
# ARM64 builds
20-
cmake -S . -B buildarm -A arm64 -DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_INSTALLATION_ROOT\scripts\buildsystems\vcpkg.cmake" -DVCPKG_TARGET_TRIPLET=arm64-windows-static
28+
$cmakeArgs = @("-S", ".", "-B", "buildarm", "-A", "arm64", "-DCMAKE_TOOLCHAIN_FILE=$env:VCPKG_INSTALLATION_ROOT\scripts\buildsystems\vcpkg.cmake", "-DVCPKG_TARGET_TRIPLET=arm64-windows-static")
29+
if ($Version) { $cmakeArgs += "-DPROJECT_VERSION=$Version" }
30+
cmake @cmakeArgs
2131
cmake --build buildarm --config Release
2232
New-Item -ItemType Directory -Path win-arm64 -Force
2333
Copy-Item buildarm\Release\Yubico.NativeShims.dll win-arm64

Yubico.NativeShims/vcpkg.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
33
"name": "yubico-nativeshims",
4-
"version": "1.13.2",
54
"dependencies": [
65
"openssl"
76
]

0 commit comments

Comments
 (0)