Skip to content

Commit

Permalink
Build statically for Windows
Browse files Browse the repository at this point in the history
This fixes an issue where the import libraries were being zipped up instead of static libraries. As part of this, Gradle now executes vcpkg as part of the build, because it's likely the triplet needed to build for Windows will be forgotten.
  • Loading branch information
Gold856 committed Dec 1, 2024
1 parent c97cda8 commit 349e47b
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 53 deletions.
58 changes: 18 additions & 40 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ jobs:
- uses: lukka/[email protected]
with:
vcpkgGitCommitId: '29b2ea2d4b6197e66ef346e62ccbba35b55b7de5'
- run: vcpkg install
name: install packages
- run: ./gradlew publish ${{ matrix.build-options }}
name: Build with Gradle
- uses: actions/upload-artifact@v4
Expand All @@ -48,10 +46,10 @@ jobs:
include:
- artifact-name: WinArm64
tool-arch: amd64_arm64
build-options: -Pplatform=arm64-windows
build-options: -Pplatform=arm64-windows-static
- artifact-name: Win64
tool-arch: amd64
build-options: -Pplatform=x64-windows
build-options: -Pplatform=x64-windows-static

name: "Build - ${{ matrix.artifact-name }}"
runs-on: windows-2019
Expand All @@ -69,46 +67,26 @@ jobs:
- uses: ilammy/[email protected]
with:
arch: ${{ matrix.tool-arch }}
- run: vcpkg install --triplet=arm64-windows
name: install packages
if: matrix.artifact-name == 'WinArm64'
- run: vcpkg install --triplet=x64-windows
name: install packages
if: matrix.artifact-name == 'Win64'
- run: ./gradlew publish ${{ matrix.build-options }}
name: Build with Gradle
- run: ls vcpkg_installed/*/bin/*
name: List dependent DLLs
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact-name }}
path: gradleDir/outputs/

build-mac:
name: "Build - macOS"
runs-on: macOS-14
steps:
- uses: actions/checkout@v4
with:
submodules: 'true'
- uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'temurin'
- run: brew install cmake ninja
name: install ninja
- uses: lukka/[email protected]
with:
vcpkgGitCommitId: '29b2ea2d4b6197e66ef346e62ccbba35b55b7de5'
- run: vcpkg install --triplet=x64-osx
name: install packages
- run: ./gradlew publish -Pplatform=x64-osx
name: Build with Gradle
- uses: actions/upload-artifact@v4
with:
name: macOS
path: gradleDir/outputs/
strategy:
fail-fast: false
matrix:
include:
- artifact-name: macOSArm
build-options: -Pplatform=arm64-osx
- artifact-name: macOS
build-options: -Pplatform=x64-osx

build-mac-arm:
name: "Build - macOS (Arm)"
name: "Build - ${{ matrix.artifact-name }}"
runs-on: macOS-14
steps:
- uses: actions/checkout@v4
Expand All @@ -123,18 +101,18 @@ jobs:
- uses: lukka/[email protected]
with:
vcpkgGitCommitId: '29b2ea2d4b6197e66ef346e62ccbba35b55b7de5'
- run: vcpkg install --triplet=arm64-osx
name: install packages
- run: ./gradlew publish -Pplatform=arm64-osx
- run: ./gradlew publish ${{ matrix.build-options }}
name: Build with Gradle
- run: ls vcpkg_installed/*/lib/*
name: List dependent shared libraries
- uses: actions/upload-artifact@v4
with:
name: macOSArm
name: ${{ matrix.artifact-name }}
path: gradleDir/outputs/

make_universal:
name: Make Universal
needs: [build-mac, build-mac-arm]
needs: [build-mac]
runs-on: macos-14
steps:
- uses: actions/checkout@v4
Expand Down
62 changes: 49 additions & 13 deletions publish.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import java.security.MessageDigest
import org.gradle.internal.os.OperatingSystem

import java.nio.file.Files
Expand All @@ -22,16 +21,29 @@ publishing {
}

def getTriplet() {
def fileNameFinder = new FileNameFinder()
for (File folder : file("$projectDir/vcpkg_installed").listFiles()) {
if (folder.name == project.platform) {
println folder.name
return folder.name
}
def triplet
def os_name = System.getProperty("os.name")
def os_arch = System.getProperty("os.arch")

if (os_arch == 'amd64') {
os_arch = 'x64'
} else if (os_arch == 'i386') {
os_arch = 'x86'
} else if (os_arch == 'aarch64' || os_arch == 'arm64') {
os_arch = 'arm64'
}
throw new RuntimeException("Platform not found");
}

if (OperatingSystem.current().isWindows()) {
triplet = "${os_arch}-windows-static-md"
} else if (OperatingSystem.current().isLinux()) {
triplet = "${os_arch}-linux"
} else if (OperatingSystem.current().isMacOsX()) {
triplet = "${os_arch}-osx"
} else {
triplet = "${os_arch}-${os_name}"
}
return triplet
}

def getPlatformPath(triplet) {
if (triplet == "arm32-linux") {
Expand All @@ -44,16 +56,30 @@ def getPlatformPath(triplet) {
return "osx/x86-64"
} else if (triplet == "arm64-osx") {
return "osx/arm64"
} else if (triplet == "x64-windows") {
} else if (triplet == "x64-windows-static-md") {
return "windows/x86-64"
} else if (triplet == "arm64-windows") {
} else if (triplet == "arm64-windows-static-md") {
return "windows/arm64"
} else {
return ""
}
}
def triplet
if (!project.hasProperty('platform')) {
println "No 'platform' property specified; using the build system's platform"
triplet = getTriplet()
} else {
triplet = project.platform
}

if (project.hasProperty('forcealternatemacbuild')) {
if (project.platform == 'arm64-osx') {
triplet = 'x64-osx'
} else if (ext.platform == 'x64-osx') {
triplet = 'arm64-osx'
}
}

def triplet = getTriplet()
ext.platformPath = getPlatformPath(triplet)
ext.platformClassifier = ext.platformPath.replaceFirst('/', '')

Expand All @@ -70,7 +96,7 @@ def versionFile = file("$outputsFolder/version.txt")
def licenseFile = file("LICENSE.md")

def outputClassifierStatic = project.ext.platformClassifier + 'static'
System.out.println(triplet)
println triplet

task copyAllOutputs(type: Copy) {
destinationDir = outputsFolder
Expand All @@ -82,6 +108,13 @@ ext.addTaskToCopyAllOutputs = { task ->
copyAllOutputs.from task.archiveFile
}

task buildVcpkg(type: Exec) {
def baseArgs = ['install']
outputs.dir "vcpkg_installed/$triplet"
executable "$rootDir/vcpkg/vcpkg"
args baseArgs + "--triplet=$triplet"
}

task outputVersions() {
description = 'Prints the versions of this to a file for use by the downstream packaging project'
group = 'Build'
Expand Down Expand Up @@ -112,6 +145,7 @@ task cppHeadersZip(type: Zip) {
}

includeEmptyDirs = false
dependsOn buildVcpkg
}

task cppLibsZipStatic(type: Zip) {
Expand All @@ -131,6 +165,7 @@ task cppLibsZipStatic(type: Zip) {
include '**/*.lib'
include '**/*.pdb'
}
dependsOn buildVcpkg
}

task cppLibsZipStaticDebug(type: Zip) {
Expand All @@ -150,6 +185,7 @@ task cppLibsZipStaticDebug(type: Zip) {
include '**/*.lib'
include '**/*.pdb'
}
dependsOn buildVcpkg
}

if (!project.hasProperty('skipRelease')) {
Expand Down

0 comments on commit 349e47b

Please sign in to comment.