From f0c7f06ff5c86622a2bb2ffd42d11f33ffb60fcd Mon Sep 17 00:00:00 2001 From: hstyi Date: Thu, 20 Feb 2025 20:30:07 +0800 Subject: [PATCH] chore: optimize package size --- .github/workflows/windows-x86-64.yml | 5 ++++ build.gradle.kts | 44 +++++++++++++++++++++++++--- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/.github/workflows/windows-x86-64.yml b/.github/workflows/windows-x86-64.yml index 3876f2b..bc6acf0 100644 --- a/.github/workflows/windows-x86-64.yml +++ b/.github/workflows/windows-x86-64.yml @@ -16,6 +16,11 @@ jobs: distribution: 'jetbrains' java-version: '21' + - name: Install zip + run: | + $system32 = [System.Environment]::GetEnvironmentVariable("WINDIR") + "\System32" + Invoke-WebRequest -Uri "http://stahlworks.com/dev/zip.exe" -OutFile "$system32\zip.exe" + - uses: actions/cache@v4 with: path: | diff --git a/build.gradle.kts b/build.gradle.kts index a782228..b5b64ca 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -142,16 +142,15 @@ tasks.test { tasks.register("copy-dependencies") { val dir = layout.buildDirectory.dir("libs") from(configurations.runtimeClasspath).into(dir) + val jna = libs.jna.asProvider().get() + val pty4j = libs.pty4j.get() + val jSerialComm = libs.jSerialComm.get() // 对 JNA 和 PTY4J 的本地库提取 // 提取出来是为了单独签名,不然无法通过公证 if (os.isMacOsX && macOSSign) { doLast { - val jna = libs.jna.asProvider().get() val dylib = dir.get().dir("dylib").asFile - val pty4j = libs.pty4j.get() - val jSerialComm = libs.jSerialComm.get() - for (file in dir.get().asFile.listFiles() ?: emptyArray()) { if ("${jna.name}-${jna.version}" == file.nameWithoutExtension) { val targetDir = File(dylib, jna.name) @@ -203,6 +202,43 @@ tasks.register("copy-dependencies") { } } } + } else if (os.isLinux || os.isWindows) { // 缩减安装包 + doLast { + for (file in dir.get().asFile.listFiles() ?: emptyArray()) { + if ("${jna.name}-${jna.version}" == file.nameWithoutExtension) { + exec { commandLine("zip", "-d", file.absolutePath, "com/sun/jna/darwin-*") } + exec { commandLine("zip", "-d", file.absolutePath, "com/sun/jna/sunos-*") } + exec { commandLine("zip", "-d", file.absolutePath, "com/sun/jna/openbsd-*") } + exec { commandLine("zip", "-d", file.absolutePath, "com/sun/jna/freebsd-*") } + exec { commandLine("zip", "-d", file.absolutePath, "com/sun/jna/dragonflybsd-*") } + exec { commandLine("zip", "-d", file.absolutePath, "com/sun/jna/aix-*") } + if (os.isWindows) { + exec { commandLine("zip", "-d", file.absolutePath, "com/sun/jna/linux-*") } + } else if (os.isLinux) { + exec { commandLine("zip", "-d", file.absolutePath, "com/sun/jna/win32-*") } + } + } else if ("${pty4j.name}-${pty4j.version}" == file.nameWithoutExtension) { + exec { commandLine("zip", "-d", file.absolutePath, "resources/*darwin*") } + exec { commandLine("zip", "-d", file.absolutePath, "resources/*freebsd*") } + if (os.isWindows) { + exec { commandLine("zip", "-d", file.absolutePath, "resources/*linux*") } + } else if (os.isLinux) { + exec { commandLine("zip", "-d", file.absolutePath, "resources/*win*") } + } + } else if ("${jSerialComm.name}-${jSerialComm.version}" == file.nameWithoutExtension) { + exec { commandLine("zip", "-d", file.absolutePath, "Android/*") } + exec { commandLine("zip", "-d", file.absolutePath, "FreeBSD/*") } + exec { commandLine("zip", "-d", file.absolutePath, "OpenBSD/*") } + exec { commandLine("zip", "-d", file.absolutePath, "OSX/*") } + exec { commandLine("zip", "-d", file.absolutePath, "Solaris/*") } + if (os.isWindows) { + exec { commandLine("zip", "-d", file.absolutePath, "Linux/*") } + } else if (os.isLinux) { + exec { commandLine("zip", "-d", file.absolutePath, "Windows/*") } + } + } + } + } } }