Skip to content

Commit

Permalink
Provide build dependencies (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmades authored Jul 15, 2024
1 parent 4812f8e commit bc42f58
Show file tree
Hide file tree
Showing 13 changed files with 1,133 additions and 0 deletions.
Empty file added -
Empty file.
107 changes: 107 additions & 0 deletions .github/workflows/build-dependencies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
on:
workflow_call:
inputs:
platform:
description: "Platform"
required: true
type: string
build_type:
description: "Build type"
required: true
type: string

jobs:
build:
name: ${{ inputs.platform }}-${{ inputs.build_type }}

runs-on: ${{ inputs.platform }}

steps:
# Step: Checkout
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12-dev"
cache: "pip"

- name: Generate cache key
id: cache-key-gen
shell: bash
run: |
cache_key="dependencies-cache-key-${{ inputs.platform }}-${{ inputs.build_type }}-$(echo $GITHUB_REF | sed 's/refs\/heads\///')"
echo "cache_key=$cache_key" >> $GITHUB_OUTPUT
# Step: Set paths
- name: Set paths
id: paths
shell: bash
run: |
if [ "${{ runner.os }}" == "Windows" ]; then
path_sep="\\\\"
else
path_sep="/"
fi
echo "path_sep=$path_sep" >> $GITHUB_OUTPUT
build_dir="${{ github.workspace }}${path_sep}build"
echo "build_dir=$build_dir" >> $GITHUB_OUTPUT
dependencies_work_dir="${{ github.workspace }}${path_sep}dependencies${path_sep}work"
echo "dependencies_work_dir=$dependencies_work_dir" >> $GITHUB_OUTPUT
dependencies_install_dir="${{ github.workspace }}${path_sep}dependencies${path_sep}install"
echo "dependencies_install_dir=$dependencies_install_dir" >> $GITHUB_OUTPUT
- name: Restore cached dependencies
id: restore-cached-dependencies
uses: actions/cache/restore@v4
with:
path: ${{ steps.paths.outputs.dependencies_install_dir }}
key: ${{ steps.cache-key-gen.outputs.cache_key }}
restore-keys: |
dependencies-cache-key-${{ inputs.platform }}-${{ inputs.build_type }}-master
dependencies-cache-key-${{ inputs.platform }}-${{ inputs.build_type }}-
- name: Install python requirements
if: steps.restore-cached-dependencies.outputs.cache-hit != 'true'
shell: bash
run: |
path_sep="${{ steps.paths.outputs.path_sep }}"
python -m pip install -r "${{ github.workspace }}${path_sep}scripts${path_sep}dependencies_installer${path_sep}requirements.txt"
- name: Build dependencies
if: steps.restore-cached-dependencies.outputs.cache-hit != 'true'
shell: bash
run: |
pwsh -command '`
$tags=@{`
zlib = "v1.2.13"; `
hdf5 = "hdf5-1_14_0"; `
sundials = "v5.8.0"; `
yamlcpp = "0.8.0"; `
catch2 = "v3.5.2"; `
googletest = "v1.14.0"; `
units = "v0.9.1"; `
fmt = "9.1.0"; `
eigen ="3.4.0"; `
boost ="1.84.0"; `
cantera = "v3.0.0" `
}; `
$path_sep="${{ steps.paths.outputs.path_sep }}"; `
. ${{ github.workspace }}${path_sep}scripts${path_sep}dependencies_installer${path_sep}InstallDependencies.ps1 `
-WorkDir "${{ steps.paths.outputs.dependencies_work_dir }}" `
-InstallDir "${{ steps.paths.outputs.dependencies_install_dir }}" `
-BuildType "${{ inputs.build_type }}" `
-ParallelJobs 10 `
-GitTags $tags `
-Clean `
'
- name: Cache dependencies
uses: actions/cache@v4
if: steps.restore-cached-dependencies.outputs.cache-hit != 'true'
with:
path: ${{ steps.paths.outputs.dependencies_install_dir }}
key: ${{ steps.cache-key-gen.outputs.cache_key }}
3 changes: 3 additions & 0 deletions .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ on:
push:
branches:
- master
- "release/v[0-9].[0-9].[0-9]"
- "feature/**"
# Manual trigger
workflow_dispatch:

jobs:
clang_format:
Expand Down
55 changes: 55 additions & 0 deletions .github/workflows/run-workflows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Run Workflows

on:
push:
branches:
- main
- 'release/v[0-9]+\.[0-9]+\.[0-9]+'
- "feature/**"
pull_request:
types:
- opened
- synchronize
branches:
- 'release/v[0-9]+\.[0-9]+\.[0-9]+'
- "feature/**"
# Manual trigger
workflow_dispatch:

jobs:
define_build_strategy:
name: Define build strategy
runs-on: ubuntu-22.04
outputs:
matrix: ${{ steps.strategy.outputs.matrix }}

steps:
- name: Define build strategy
id: strategy
env:
MATRIX: >-
{
"include": [
{
"platform": "ubuntu-22.04",
"build_type": "Release"
}
]
}
run: echo "matrix=$(jq -r -c . <<< "$MATRIX")" >> $GITHUB_OUTPUT

- name: Display build config
run: jq . <<< '${{ steps.strategy.outputs.matrix }}'

build_dependencies:
name: Build dependencies

needs: define_build_strategy

strategy:
matrix: ${{ fromJson(needs.define_build_strategy.outputs.matrix) }}

uses: ./.github/workflows/build-dependencies.yml
with:
platform: ${{ matrix.platform }}
build_type: ${{ matrix.build_type }}
6 changes: 6 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
scons
setuptools
wheel
ruamel.yaml
pytest

161 changes: 161 additions & 0 deletions scripts/dependencies_installer/BoostInstaller.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
using module ./Utilities.psm1

class BoostInstaller {
hidden [string] $Tag
hidden [string] $BuildType
hidden [int] $ParallelJobs = 1

hidden [string] $Name = 'boost'
hidden [string] $BuildDir = (Join-Path $Global:BuildDir $this.Name)
hidden [string] $InstallDir = (Join-Path $Global:InstallDir $this.Name)
hidden [string] $ExtractDir
hidden [string] $ArchivePath
hidden [string] $Stem

hidden [bool] $DoInstall = $false

# Default constructor
BoostInstaller() { $this.Initialise(@{}) }

BoostInstaller([hashtable] $Properties) {
[BoostInstaller]::ValidateProperties($Properties)
$this.Initialise($Properties)
$this.ProcessDirectories()
}

hidden static [void] ValidateProperties([hashtable] $Properties) {

[string[]] $requiredProperties = @(
'Tag',
'BuildType'
)

[string[]] $optionalProperties = @(
'ParallelJobs'
)

$allProperties = $requiredProperties + $optionalProperties

foreach ($property in $requiredProperties) {
if (-not $Properties.ContainsKey($property)) {
throw "Not all required properties are provided"
}
}

foreach ($property in $Properties.Keys) {
if ($allProperties -notcontains $property) {
throw "Invalid properties are provided"
}
}
}

# Initialiser method
hidden [void] Initialise([hashtable]$Properties) {
foreach ($Property in $Properties.Keys) {
$this.$Property = $Properties.$Property
}
}

hidden [void] ProcessDirectories() {
if (-not(Test-Path -Path $this.InstallDir)) {
New-Item $this.InstallDir -Type Directory
if (Test-Path -Path $this.BuildDir) {
Remove-Item $this.BuildDir -Recurse -Force
}
New-Item $this.BuildDir -Type Directory
$this.DoInstall = $true
}
}

hidden [void] Downlaod() {
$VersionUnderScore = $this.Tag.Replace('.', '_')
$this.Stem = $this.Name + '_' + $VersionUnderScore
$FileName = $this.Stem + ($Global:IsLinux ? '.tar.gz' : '.zip')
$this.ArchivePath = (Join-Path $Global:DownloadDir $FileName)

if (-not(Test-Path -Path $this.ArchivePath)) {
$URL = (@('https://boostorg.jfrog.io/artifactory/main/release'; $this.Tag; 'source'; $FileName) -Join '/')
$WebClient = [System.Net.WebClient]::new()
$WebClient.DownloadFile($URL, $this.ArchivePath)
$ExitCode = $LASTEXITCODE
if ( $ExitCode -ne 0 ) {
throw ('Failed to download boost.')
}
}
}

hidden [void] Extract() {
$this.ExtractDir = (Join-Path $Global:ExtractDir $this.Stem)
if (-not(Test-Path -Path $this.ExtractDir)) {
if ($Global:IsLinux) {
New-Item $this.ExtractDir -Type Directory
tar -xvf $this.ArchivePath -C $Global:ExtractDir
}
else {
Add-Type -Assembly "System.IO.Compression.Filesystem"
[System.IO.Compression.ZipFile]::ExtractToDirectory($this.ArchivePath, $Global:ExtractDir)
#Expand-Archive -Force $this.ArchivePath -DestinationPath $Global:ExtractDir
}
$ExitCode = $LASTEXITCODE
if ( $ExitCode -ne 0 ) {
throw ('Failed to extract boost.')
}
}
}

hidden [void] Bootstrap() {
Push-Location $this.ExtractDir
Start-Process -FilePath ('./bootstrap' + ($Global:IsLinux ? '.sh' : '.bat')) -Wait -NoNewWindow
$ExitCode = $LASTEXITCODE
if ( $ExitCode -ne 0 ) {
throw ('Failed to boostrap boost.')
}
Pop-Location
}

hidden [void] Install() {
Push-Location $this.ExtractDir
$BOOSTBuildArgumentList = `
' -j' + $this.ParallelJobs `
+ ' -d0' `
+ ' --build-dir=' + $this.BuildDir `
+ ' --prefix=' + $this.InstallDir `
+ ' --layout=system' `
+ ' variant=release' `
+ ' runtime-link=static' `
+ ' link=static' `
+ ' address-model=64' `
+ ' install'
Start-Process -FilePath './b2' -ArgumentList $BOOSTBuildArgumentList -Wait -NoNewWindow
$ExitCode = $LASTEXITCODE
if ( $ExitCode -ne 0 ) {
throw ('Failed to install boost.')
}
Pop-Location
}

[string] Directory() { return $this.InstallDir }

[string] StaticLibraryDirectory() { return (Join-Path $this.InstallDir 'lib') }

[string] IncludeDirectory() {
$VersionUnderScore = $this.Tag.Replace('.', '_')
$IndexOfLastUnderscore = $VersionUnderScore.LastIndexOf("_")
$VersionUnderScoreMajorMinor = $VersionUnderScore.Substring(0, $IndexOfLastUnderscore)
return (Join-Path $this.InstallDir 'include' ($this.Name + '-' + $VersionUnderScoreMajorMinor))
}

[void] Run() {
if ($this.DoInstall) {
Utilities\PrintDecoratedMessage $this.Name "Start"
$this.Downlaod()
$this.Extract()
$this.Bootstrap()
$this.Install()
Utilities\PrintDecoratedMessage $this.Name "End"
}
else {
Write-Host $this.Name is already installed.
}
}
}
Loading

0 comments on commit bc42f58

Please sign in to comment.