Skip to content

Commit

Permalink
openjdk: improve download link (#5760)
Browse files Browse the repository at this point in the history
* openjdk: improve download link

* fix mingw download

* fix java run

* jnipp: only native build

* openjdk: improve plat

* disable mingw

* improve on_fetch

* fix arch name

* use bindirs

* improve bindirs for on_fetch

* fix bindirs
  • Loading branch information
star-hengxing authored Nov 17, 2024
1 parent 52d80bc commit 5c4a0af
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 44 deletions.
21 changes: 16 additions & 5 deletions packages/j/jnipp/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,34 @@ package("jnipp")

add_versions("v1.0.0", "e5ff425e1af81d6c0a80420f5b3a46986cdb5f2a1c34449e2fb262eb2edf885b")

if is_plat("windows") then
if is_plat("windows", "mingw") then
add_syslinks("advapi32")
end

add_deps("openjdk")
add_deps("openjdk", {kind = "library"})

on_install("windows|x64", "linux|x86_64", "macosx|x86_64", "macosx|arm64", "mingw|x86_64", function (package)
if on_check then
on_check(function (package)
if not package:is_arch64() then
raise("package(jnipp) unsupported 32-bit arch")
end
if package:is_cross() then
raise("package(jnipp) only support native build")
end
end)
end

on_install("windows", "linux", "macosx", function (package)
io.writefile("xmake.lua", [[
add_rules("mode.debug", "mode.release")
add_requires("openjdk")
add_requires("openjdk", {kind = "library"})
set_languages("c++14")
target("jnipp")
set_kind("$(kind)")
add_files("jnipp.cpp")
add_headerfiles("jnipp.h")
add_packages("openjdk")
if is_plat("windows") then
if is_plat("windows", "mingw") then
add_syslinks("advapi32")
if is_kind("shared") then
add_rules("utils.symbols.export_all", {export_classes = true})
Expand Down
32 changes: 32 additions & 0 deletions packages/o/openjdk/fetch.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
function main(package, opt)
if not opt.system then
return
end

local java = package:find_tool("java", opt)
if not java then
return
end

local result = {}
result.version = java.version

if package:is_binary() then
return result
end

if is_host("windows") then
local sdkdir = os.getenv("JAVA_HOME")
if not os.isdir(sdkdir) then
return
end

result.includedirs = {path.join(sdkdir, "include"), path.join(sdkdir, "include/win32")}
result.linkdirs = path.join(sdkdir, "lib")
result.links = {"jvm", "jawt"}
result.bindirs = {path.join(sdkdir, "bin"), path.join(sdkdir, "bin/server")}
return result
end
-- TODO: linux, mac
-- ubuntu: /usr/lib/jvm/java-11-openjdk-amd64
end
93 changes: 54 additions & 39 deletions packages/o/openjdk/xmake.lua
Original file line number Diff line number Diff line change
@@ -1,63 +1,74 @@
package("openjdk")
set_kind("binary")
set_homepage("https://jdk.java.net")
set_description("Java Development Kit builds, from Oracle")
set_license("GPL-2.0")

if is_host("windows", "mingw") then
add_urls("https://download.oracle.com/java/$(version)/latest/jdk-$(version)_windows-x64_bin.zip")
add_versions("17", "c98d85c8417703b0f72ddc5757ed66f3478ea7107b0e6d2a98cadbc73a45d77b")
add_versions("21", "776afe55020560f175d8099710d8ac07c4d40772c694385c3dd765117cbd0ac3")
-- https://learn.microsoft.com/en-us/java/openjdk/download
if is_host("windows") then
if os.arch() == "x64" then
add_urls("https://aka.ms/download-jdk/microsoft-jdk-$(version)-windows-x64.zip")

add_versions("21.0.5", "12e42c2c572a111f38e2a9e044afc50dbdac850349a4d4bb26808ed33119a9cd")
elseif os.arch() == "arm64" then
add_urls("https://aka.ms/download-jdk/microsoft-jdk-$(version)-windows-aarch64.zip")

add_versions("21.0.5", "5eaa375659c543a5d3310d51004e3bdc290ff9e48e9bcd29187dfafeca97c2a4")
end
elseif is_host("linux") then
if is_arch("x86_64") then
add_urls("https://download.oracle.com/java/$(version)/latest/jdk-$(version)_linux-x64_bin.tar.gz")
add_versions("17", "e4fb2df9a32a876afb0a6e17f54c594c2780e18badfa2e8fc99bc2656b0a57b1")
add_versions("21", "9f1f4a7f25ef6a73255657c40a6d7714f2d269cf15fb2ff1dc9c0c8b56623a6f")
elseif is_arch("arm64") then
add_urls("https://download.oracle.com/java/$(version)/latest/jdk-$(version)_linux-aarch64_bin.tar.gz")
add_versions("17", "745e7a387e059ddc2481ccd209d691ca926fc0f35d523051822f24b296d17df7")
add_versions("21", "14504bcdea0d8bc3fe9f065924e9e2dc631317b023a722565c8239075f39062d")
if os.arch() == "x86_64" then
add_urls("https://aka.ms/download-jdk/microsoft-jdk-$(version)-linux-x64.tar.gz")

add_versions("21.0.5", "0d42a80dbc92f2f112e6db3b4b9bd278c0776a73b6050812e720230813487ebd")
elseif os.arch() == "arm64-v8a" then
add_urls("https://aka.ms/download-jdk/microsoft-jdk-$(version)-linux-aarch64.tar.gz")

add_versions("21.0.5", "356844fe544085b00cd73935e0c7a4c534f286799728fa6d6e996d1cb8b1a682")
end
elseif is_host("macosx") then
if is_arch("x86_64") then
add_urls("https://download.oracle.com/java/$(version)/latest/jdk-$(version)_macos-x64_bin.tar.gz")
add_versions("17", "7b68b833f392aa543ba538f94c60fd477581fef96a9c1ae059fa4158e9ce75ff")
add_versions("21", "197a923b1f7ea2b224fafdfb9c3ef5fc8eb197d9817d7631d96da02b619f5975")
elseif is_arch("arm64") then
add_urls("https://download.oracle.com/java/$(version)/latest/jdk-$(version)_macos-aarch64_bin.tar.gz")
add_versions("17", "d5bec93922815e9337040678ddf3f40e50b63c2b588cf63574fa1f2010206042")
add_versions("21", "4b94951f03efe44cb6656e43f1098db3ce254a00412f9d22dff18a8328a7efdd")
if os.arch() == "x86_64" then
add_urls("https://aka.ms/download-jdk/microsoft-jdk-$(version)-macos-x64.tar.gz")

add_versions("21.0.5", "3e2317348141b28203fac39eaa60c14a1b3f1fdb9cfdbcb793eaa4dd5828da6e")
elseif os.arch() == "arm64" then
add_urls("https://aka.ms/download-jdk/microsoft-jdk-$(version)-macos-aarch64.tar.gz")

add_versions("21.0.5", "78aa915475b426c03059cc51e9c12596a5138457bd7ebb9b90daad119551662d")
end
end

add_configs("shared", {description = "Download shared binaries.", default = true, type = "boolean", readonly = true})
add_configs("runtimes", {description = "Set compiler runtimes.", default = "MD", readonly = true})
add_configs("debug", {description = "Enable debug symbols.", default = false, type = "boolean", readonly = true})

if is_plat("linux") then
add_deps("alsa-lib", {configs = {shared = true, versioned = false}})
add_deps("freetype", "libxtst", "libxi", "libxrender")
add_extsources("pacman::jdk-openjdk", "apt::default-jdk")
elseif is_plat("macosx") then
add_extsources("brew::openjdk")
end

on_fetch("windows", "mingw", function (package, opt)
if opt.system then
local sdkdir = os.getenv("JAVA_HOME")
if os.isdir(sdkdir) then
local result = {}
result.includedirs = {path.join(sdkdir, "include"), path.join(sdkdir, "include", "win32")}
result.linkdirs = path.join(sdkdir, "lib")
result.links = {"jvm", "jawt"}
package:addenv("PATH", path.join(sdkdir, "bin"), path.join(sdkdir, "bin", "server"))
return result
if is_plat("linux") then
add_deps("alsa-lib", {configs = {shared = true, versioned = false}})
add_deps("freetype", "libxtst", "libxi", "libxrender")
end

set_policy("package.precompiled", false)

on_fetch("fetch")

if on_check then
on_check(function (package)
if not package:is_arch64() then
raise("package(openjdk) unsupported 32-bit arch")
end
end
end)
end)
end

on_install("windows|x64", "linux|x86_64", "macosx|x86_64", "macosx|arm64", "mingw|x86_64", function (package)
on_install("windows|!x86", "linux", "macosx", function (package)
local plat
if package:is_plat("windows", "mingw") then
plat = "win32"
package:addenv("PATH", "bin/server")
package:add("bindirs", "bin/server")
else
package:add("linkdirs", "lib", "lib/server")
if package:is_plat("linux") then
Expand All @@ -75,10 +86,14 @@ package("openjdk")
os.cp("conf", package:installdir())

package:add("includedirs", "include", path.join("include", plat))
package:addenv("PATH", "bin")
package:add("bindirs", "bin")
end)

on_test(function (package)
os.vrun("java -version")
assert(package:has_cfuncs("JNI_CreateJavaVM", {includes = "jni.h"}))
if not package:is_cross() then
os.vrun("java -version")
end
if package:is_library() then
assert(package:has_cfuncs("JNI_CreateJavaVM", {includes = "jni.h"}))
end
end)

0 comments on commit 5c4a0af

Please sign in to comment.