From 349e47bbeab371b7d4978cb3a8e8fc1b21fc398a Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Sun, 1 Dec 2024 02:15:29 -0500 Subject: [PATCH] Build statically for Windows 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. --- .github/workflows/main.yml | 58 +++++++++++------------------------ publish.gradle | 62 ++++++++++++++++++++++++++++++-------- 2 files changed, 67 insertions(+), 53 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b8538a1..89b57c4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -32,8 +32,6 @@ jobs: - uses: lukka/run-vcpkg@v11.5 with: vcpkgGitCommitId: '29b2ea2d4b6197e66ef346e62ccbba35b55b7de5' - - run: vcpkg install - name: install packages - run: ./gradlew publish ${{ matrix.build-options }} name: Build with Gradle - uses: actions/upload-artifact@v4 @@ -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 @@ -69,46 +67,26 @@ jobs: - uses: ilammy/msvc-dev-cmd@v1.13.0 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/run-vcpkg@v11.5 - 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 @@ -123,18 +101,18 @@ jobs: - uses: lukka/run-vcpkg@v11.5 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 diff --git a/publish.gradle b/publish.gradle index 208f77e..b25d07a 100644 --- a/publish.gradle +++ b/publish.gradle @@ -1,4 +1,3 @@ -import java.security.MessageDigest import org.gradle.internal.os.OperatingSystem import java.nio.file.Files @@ -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") { @@ -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('/', '') @@ -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 @@ -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' @@ -112,6 +145,7 @@ task cppHeadersZip(type: Zip) { } includeEmptyDirs = false + dependsOn buildVcpkg } task cppLibsZipStatic(type: Zip) { @@ -131,6 +165,7 @@ task cppLibsZipStatic(type: Zip) { include '**/*.lib' include '**/*.pdb' } + dependsOn buildVcpkg } task cppLibsZipStaticDebug(type: Zip) { @@ -150,6 +185,7 @@ task cppLibsZipStaticDebug(type: Zip) { include '**/*.lib' include '**/*.pdb' } + dependsOn buildVcpkg } if (!project.hasProperty('skipRelease')) {