Skip to content

Commit 2637d48

Browse files
authored
Merge pull request #172 from alicevision/copilot/fix-171
[CI] Add GitHub Actions CI for Windows and refactoring
2 parents cf2d0e8 + feb71ed commit 2637d48

File tree

9 files changed

+593
-139
lines changed

9 files changed

+593
-139
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: 'Build Configuration'
2+
description: 'Build PopSift for a specific configuration (Release/Debug)'
3+
4+
inputs:
5+
build-type:
6+
description: 'Build type (Release or Debug)'
7+
required: true
8+
platform:
9+
description: 'Platform (linux or windows)'
10+
required: true
11+
deps-install-dir:
12+
description: 'Dependencies install directory (Linux only)'
13+
required: false
14+
default: '/opt/'
15+
vcpkg-root:
16+
description: 'vcpkg root directory (Windows only)'
17+
required: false
18+
workspace-dir:
19+
description: 'Workspace directory (Windows only)'
20+
required: false
21+
22+
runs:
23+
using: 'composite'
24+
steps:
25+
# Linux steps
26+
- name: Setup directories (Linux)
27+
if: inputs.platform == 'linux'
28+
shell: bash
29+
run: |
30+
source ./.github/scripts/build-linux.sh
31+
BUILD_TYPE=${{ inputs.build-type }} setup_directories
32+
33+
- name: Configure CMake (Linux)
34+
if: inputs.platform == 'linux'
35+
shell: bash
36+
run: |
37+
source ./.github/scripts/build-linux.sh
38+
configure_cmake "${{ inputs.build-type }}" "${{ inputs.deps-install-dir }}"
39+
40+
- name: Build and Install (Linux)
41+
if: inputs.platform == 'linux'
42+
shell: bash
43+
run: |
44+
source ./.github/scripts/build-linux.sh
45+
build_and_install "${{ inputs.build-type }}"
46+
47+
- name: Build As Third Party (Linux)
48+
if: inputs.platform == 'linux'
49+
shell: bash
50+
run: |
51+
source ./.github/scripts/build-linux.sh
52+
build_as_third_party "${{ inputs.build-type }}" "${{ inputs.deps-install-dir }}"
53+
54+
# Windows steps
55+
- name: Setup directories (Windows)
56+
if: inputs.platform == 'windows'
57+
shell: powershell
58+
run: |
59+
. .\.github\scripts\build-windows.ps1
60+
Setup-Directories -BuildType "${{ inputs.build-type }}"
61+
62+
- name: Configure CMake (Windows)
63+
if: inputs.platform == 'windows'
64+
shell: powershell
65+
run: |
66+
. .\.github\scripts\build-windows.ps1
67+
Configure-CMake -BuildType "${{ inputs.build-type }}" -VcpkgRoot "${{ inputs.vcpkg-root }}" -WorkspaceDir "${{ inputs.workspace-dir }}"
68+
69+
- name: Build and Install (Windows)
70+
if: inputs.platform == 'windows'
71+
shell: powershell
72+
run: |
73+
. .\.github\scripts\build-windows.ps1
74+
Build-AndInstall -BuildType "${{ inputs.build-type }}"
75+
76+
- name: Build As Third Party (Windows)
77+
if: inputs.platform == 'windows'
78+
shell: powershell
79+
run: |
80+
. .\.github\scripts\build-windows.ps1
81+
Build-AsThirdParty -BuildType "${{ inputs.build-type }}" -VcpkgRoot "${{ inputs.vcpkg-root }}" -WorkspaceDir "${{ inputs.workspace-dir }}"

.github/scripts/build-linux.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/bash
2+
# Linux build functions for PopSift
3+
# Usage: source this file and call the individual functions
4+
5+
# Creates the necessary build directories for different build types
6+
# Uses BUILD_TYPE environment variable to create build and install directories
7+
setup_directories() {
8+
echo "Setting up build directories..."
9+
mkdir -p ./build_"${BUILD_TYPE,,}"
10+
mkdir -p ./build_as_3rdparty_"${BUILD_TYPE,,}"
11+
mkdir -p ../popsift_install_"${BUILD_TYPE,,}"
12+
}
13+
14+
# Configures CMake for PopSift build with specified options
15+
# Parameters:
16+
# $1 - build_type: Release or Debug
17+
# $2 - deps_dir: Directory containing pre-installed dependencies (e.g., /opt/)
18+
# Creates a build directory named <build_$build_type> and runs CMake configuration with PopSift-specific options
19+
configure_cmake() {
20+
local build_type="$1"
21+
local deps_dir="$2"
22+
local build_dir="build_${build_type,,}"
23+
local install_dir="../popsift_install_${build_type,,}"
24+
25+
echo "Configuring CMake for $build_type..."
26+
cd "./$build_dir" || exit
27+
cmake .. \
28+
-DCMAKE_BUILD_TYPE="$build_type" \
29+
-DBUILD_SHARED_LIBS:BOOL=ON \
30+
-DCMAKE_PREFIX_PATH="$deps_dir" \
31+
-DPopSift_BUILD_DOCS:BOOL=OFF \
32+
-DCMAKE_INSTALL_PREFIX:PATH="$PWD/$install_dir"
33+
cd ..
34+
}
35+
36+
# Builds and installs PopSift for the specified build type
37+
# Parameters:
38+
# $1 - build_type: Release or Debug
39+
# Uses parallel build with all available CPU cores
40+
build_and_install() {
41+
local build_type="$1"
42+
local build_dir="build_${build_type,,}"
43+
44+
echo "Building and installing $build_type..."
45+
cd "./$build_dir" || exit
46+
cmake --build . --config "$build_type" --parallel
47+
cmake --install . --config "$build_type"
48+
cd ..
49+
}
50+
51+
# Tests building PopSift applications as a third-party consumer
52+
# This verifies that the installed PopSift can be found and used by external projects
53+
# Parameters:
54+
# $1 - build_type: Release or Debug
55+
# $2 - deps_dir: Directory containing pre-installed dependencies
56+
# Builds only the application from src/application using the installed PopSift library
57+
build_as_third_party() {
58+
local build_type="$1"
59+
local deps_dir="$2"
60+
local build_dir="build_as_3rdparty_${build_type,,}"
61+
local install_dir="../popsift_install_${build_type,,}"
62+
63+
echo "Testing third-party build for $build_type..."
64+
cd "./$build_dir" || exit
65+
cmake ../src/application \
66+
-DBUILD_SHARED_LIBS:BOOL=ON \
67+
-DCMAKE_BUILD_TYPE="$build_type" \
68+
-DCMAKE_PREFIX_PATH:PATH="$PWD/$install_dir;$deps_dir"
69+
cmake --build . --config "$build_type" --parallel
70+
cd ..
71+
}

.github/scripts/build-windows.ps1

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# Windows build functions for PopSift
2+
# Usage: source this file and call the individual functions
3+
4+
<#
5+
.SYNOPSIS
6+
Creates the necessary build directories for different build types on Windows.
7+
8+
.DESCRIPTION
9+
Sets up build directories for the main PopSift build and third-party build testing.
10+
Creates directories with lowercase build type names (e.g. build_release) following Windows conventions.
11+
12+
.PARAMETER BuildType
13+
The build configuration (Release or Debug)
14+
#>
15+
function Setup-Directories {
16+
param([string]$BuildType)
17+
18+
Write-Host "Setting up build directories for $BuildType..."
19+
$buildDir = "build_$($BuildType.ToLower())"
20+
$thirdPartyDir = "build_as_3rdparty_$($BuildType.ToLower())"
21+
22+
New-Item -ItemType Directory -Path $buildDir -Force | Out-Null
23+
New-Item -ItemType Directory -Path $thirdPartyDir -Force | Out-Null
24+
}
25+
26+
<#
27+
.SYNOPSIS
28+
Configures CMake for PopSift build on Windows using vcpkg for dependency management.
29+
30+
.DESCRIPTION
31+
Sets up CMake configuration with Visual Studio 2022 generator, enables shared libraries,
32+
and configures PopSift-specific options. Uses vcpkg manifest mode for dependency management.
33+
34+
.PARAMETER BuildType
35+
The build configuration (Release or Debug)
36+
37+
.PARAMETER VcpkgRoot
38+
Path to the vcpkg installation directory
39+
40+
.PARAMETER WorkspaceDir
41+
Path to the workspace directory for install location
42+
#>
43+
function Configure-CMake {
44+
param(
45+
[string]$BuildType,
46+
[string]$VcpkgRoot,
47+
[string]$WorkspaceDir
48+
)
49+
50+
Write-Host "Configuring CMake for $BuildType..."
51+
$buildDir = "build_$($BuildType.ToLower())"
52+
$installDir = "$WorkspaceDir/install_$($BuildType.ToLower())"
53+
$vcpkgToolchain = "$VcpkgRoot/scripts/buildsystems/vcpkg.cmake"
54+
55+
Set-Location $buildDir
56+
cmake .. -G "Visual Studio 17 2022" -A x64 `
57+
-DBUILD_SHARED_LIBS:BOOL=ON `
58+
-DCMAKE_GENERATOR_TOOLSET="cuda=$env:CUDA_PATH" `
59+
-DPopSift_USE_GRID_FILTER:BOOL=ON `
60+
-DPopSift_BUILD_DOCS:BOOL=OFF `
61+
-DPopSift_USE_POSITION_INDEPENDENT_CODE:BOOL=ON `
62+
-DPopSift_BUILD_EXAMPLES:BOOL=ON `
63+
-DCMAKE_BUILD_TYPE="$BuildType" `
64+
-DCMAKE_INSTALL_PREFIX="$installDir" `
65+
-DVCPKG_INSTALLED_DIR="$env:VCPKG_INSTALLED_DIR" `
66+
-DCMAKE_TOOLCHAIN_FILE="$vcpkgToolchain"
67+
68+
if ($LASTEXITCODE -ne 0) {
69+
throw "CMake configuration failed for $BuildType"
70+
}
71+
Set-Location ..
72+
}
73+
74+
<#
75+
.SYNOPSIS
76+
Builds and installs PopSift for the specified build configuration.
77+
78+
.DESCRIPTION
79+
Performs parallel build using all available CPU cores and installs the built
80+
libraries and executables to the configured install directory.
81+
82+
.PARAMETER BuildType
83+
The build configuration (Release or Debug)
84+
#>
85+
function Build-AndInstall {
86+
param([string]$BuildType)
87+
88+
Write-Host "Building and installing $BuildType..."
89+
$buildDir = "build_$($BuildType.ToLower())"
90+
91+
Set-Location $buildDir
92+
cmake --build . --config $BuildType --parallel
93+
if ($LASTEXITCODE -ne 0) {
94+
throw "Build failed for $BuildType"
95+
}
96+
97+
cmake --build . --config $BuildType --target install
98+
if ($LASTEXITCODE -ne 0) {
99+
throw "Install failed for $BuildType"
100+
}
101+
Set-Location ..
102+
}
103+
104+
<#
105+
.SYNOPSIS
106+
Tests building PopSift applications as a third-party consumer on Windows.
107+
108+
.DESCRIPTION
109+
Verifies that the installed PopSift can be found and used by external projects.
110+
This is important for testing the installation and packaging. Uses vcpkg manifest
111+
mode dependencies from the main project build since src/application doesn't have
112+
its own vcpkg.json file.
113+
114+
.PARAMETER BuildType
115+
The build configuration (Release or Debug)
116+
117+
.PARAMETER VcpkgRoot
118+
Path to the vcpkg installation directory
119+
120+
.PARAMETER WorkspaceDir
121+
Path to the workspace directory containing the main build and install
122+
#>
123+
function Build-AsThirdParty {
124+
param(
125+
[string]$BuildType,
126+
[string]$VcpkgRoot,
127+
[string]$WorkspaceDir
128+
)
129+
130+
Write-Host "Testing third-party build for $BuildType..."
131+
$thirdPartyDir = "build_as_3rdparty_$($BuildType.ToLower())"
132+
$installDir = "$WorkspaceDir/install_$($BuildType.ToLower())"
133+
$vcpkgToolchain = "$VcpkgRoot/scripts/buildsystems/vcpkg.cmake"
134+
135+
# In vcpkg manifest mode, dependencies are installed locally in vcpkg_installed/
136+
# Since src/application doesn't have vcpkg.json, we need to point to the main project's vcpkg_installed directory so the third-party build can find the dependencies
137+
$mainProjectVcpkgInstalled = $env:VCPKG_INSTALLED_DIR
138+
Write-Host "Dependencies installed in $mainProjectVcpkgInstalled..."
139+
# print first level content of the folder mainProjectVcpkgInstalled
140+
Get-ChildItem -Path $mainProjectVcpkgInstalled -Directory | ForEach-Object { Write-Host " - $($_.Name)" }
141+
142+
Set-Location $thirdPartyDir
143+
cmake ../src/application -G "Visual Studio 17 2022" -A x64 `
144+
-DBUILD_SHARED_LIBS:BOOL=ON `
145+
-DCMAKE_BUILD_TYPE=$BuildType `
146+
-DCMAKE_PREFIX_PATH="$installDir;$mainProjectVcpkgInstalled/x64-windows" `
147+
-DCMAKE_TOOLCHAIN_FILE="$vcpkgToolchain" `
148+
-DVCPKG_INSTALLED_DIR="$mainProjectVcpkgInstalled" `
149+
-DVCPKG_TARGET_TRIPLET=x64-windows
150+
151+
if ($LASTEXITCODE -ne 0) {
152+
throw "Third-party CMake configuration failed for $BuildType"
153+
}
154+
155+
cmake --build . --config $BuildType --parallel
156+
if ($LASTEXITCODE -ne 0) {
157+
throw "Third-party build failed for $BuildType"
158+
}
159+
Set-Location ..
160+
}

0 commit comments

Comments
 (0)