2026-07-06 09:01:23 +02:00
|
|
|
param(
|
|
|
|
|
[Parameter(Mandatory = $true)]
|
|
|
|
|
[string]$Modules
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
|
|
2026-07-06 09:38:15 +02:00
|
|
|
$AllowedModules = @(
|
|
|
|
|
"java.base",
|
|
|
|
|
"java.compiler",
|
|
|
|
|
"java.desktop",
|
|
|
|
|
"java.instrument",
|
|
|
|
|
"java.logging",
|
|
|
|
|
"java.management",
|
|
|
|
|
"java.naming",
|
|
|
|
|
"java.net.http",
|
|
|
|
|
"java.prefs",
|
|
|
|
|
"java.rmi",
|
|
|
|
|
"java.scripting",
|
|
|
|
|
"java.security.jgss",
|
|
|
|
|
"java.security.sasl",
|
|
|
|
|
"java.sql",
|
|
|
|
|
"java.transaction.xa",
|
|
|
|
|
"java.xml",
|
|
|
|
|
"java.xml.crypto",
|
|
|
|
|
"jdk.crypto.ec",
|
|
|
|
|
"jdk.crypto.cryptoki",
|
|
|
|
|
"jdk.unsupported",
|
|
|
|
|
"jdk.dynalink"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
$RequestedModules = @($Modules -split "," | ForEach-Object { $_.Trim() } | Where-Object { $_ })
|
|
|
|
|
if ($RequestedModules.Count -eq 0) {
|
|
|
|
|
throw "At least one jlink module is required."
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$InvalidModules = $RequestedModules | Where-Object {
|
|
|
|
|
($_ -notmatch '^[A-Za-z0-9_.]+$') -or ($_ -notin $AllowedModules)
|
|
|
|
|
}
|
|
|
|
|
if ($InvalidModules) {
|
|
|
|
|
throw "Unsupported jlink module(s): $($InvalidModules -join ', ')"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$ModulesArg = $RequestedModules -join ","
|
|
|
|
|
|
2026-07-06 09:01:23 +02:00
|
|
|
$Jlink = if ($env:JAVA_HOME) {
|
|
|
|
|
Join-Path $env:JAVA_HOME "bin/jlink.exe"
|
|
|
|
|
} else {
|
|
|
|
|
"jlink.exe"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$HelpText = & $Jlink --help 2>&1 | Out-String
|
2026-07-06 09:19:15 +02:00
|
|
|
# Older JDKs do not support the newer zip compressor selector, so fall back to
|
|
|
|
|
# the numeric compression level they do understand.
|
2026-07-06 09:01:23 +02:00
|
|
|
$Compress = if ($HelpText -match "zip-\[0-9\]") { "zip-6" } else { "2" }
|
|
|
|
|
|
|
|
|
|
& $Jlink `
|
2026-07-06 09:38:15 +02:00
|
|
|
--add-modules "$ModulesArg,jdk.crypto.mscapi" `
|
2026-07-06 09:01:23 +02:00
|
|
|
--strip-debug `
|
|
|
|
|
--compress="$Compress" `
|
|
|
|
|
--no-header-files `
|
|
|
|
|
--no-man-pages `
|
|
|
|
|
--output runtime/jre
|
|
|
|
|
|
2026-07-06 09:19:15 +02:00
|
|
|
# Tauri's resource staging preserves source permissions, so the bundled runtime
|
|
|
|
|
# must be writable here or the next incremental build can fail on read-only JRE
|
|
|
|
|
# files copied into the target directory.
|
2026-07-06 09:01:23 +02:00
|
|
|
Get-ChildItem -Recurse runtime/jre -Force -File | ForEach-Object {
|
|
|
|
|
$_.Attributes = $_.Attributes -band (-bnot [System.IO.FileAttributes]::ReadOnly)
|
|
|
|
|
}
|