From 764a267a30d0ad8f6bb360562463d257594e2474 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 25 Feb 2025 22:52:53 +0800 Subject: add kotlin-native package stub --- tests/projects/kotlin-native/package/src/main.kt | 3 ++ tests/projects/kotlin-native/package/xmake.lua | 11 ++++ .../manager/kotlin-native/configurations.lua | 58 ++++++++++++++++++++++ .../package/manager/kotlin-native/find_package.lua | 37 ++++++++++++++ .../manager/kotlin-native/install_package.lua | 46 +++++++++++++++++ 5 files changed, 155 insertions(+) create mode 100644 tests/projects/kotlin-native/package/src/main.kt create mode 100644 tests/projects/kotlin-native/package/xmake.lua create mode 100644 xmake/modules/package/manager/kotlin-native/configurations.lua create mode 100644 xmake/modules/package/manager/kotlin-native/find_package.lua create mode 100644 xmake/modules/package/manager/kotlin-native/install_package.lua diff --git a/tests/projects/kotlin-native/package/src/main.kt b/tests/projects/kotlin-native/package/src/main.kt new file mode 100644 index 000000000..543f5ac8f --- /dev/null +++ b/tests/projects/kotlin-native/package/src/main.kt @@ -0,0 +1,3 @@ +fun main() { + println("hello xmake!") +} diff --git a/tests/projects/kotlin-native/package/xmake.lua b/tests/projects/kotlin-native/package/xmake.lua new file mode 100644 index 000000000..1b7d146f3 --- /dev/null +++ b/tests/projects/kotlin-native/package/xmake.lua @@ -0,0 +1,11 @@ +add_rules("mode.debug", "mode.release") + +add_requires("kotlin-native") +add_requires("kotlin-native::org.jetbrains.kotlinx:kotlinx-serialization-json 1.8.0", {alias = "json"}) + +target("test") + set_kind("binary") + add_files("src/*.kt") + add_packages("json") + set_toolchains("@kotlin-native") + diff --git a/xmake/modules/package/manager/kotlin-native/configurations.lua b/xmake/modules/package/manager/kotlin-native/configurations.lua new file mode 100644 index 000000000..831403d03 --- /dev/null +++ b/xmake/modules/package/manager/kotlin-native/configurations.lua @@ -0,0 +1,58 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file configurations.lua +-- + +-- get architecture for kotlin-native +function arch(arch) + local archs = { + x86_64 = "x64", + i386 = "x86", + ["armeabi-v7a"] = "arm32", + ["arm64-v8a"] = "arm64", + armv7 = "arm32", + armv7s = "arm32" + } + return archs[arch] or arch +end + +-- get platform for kotlin-native +function plat(plat) + local plats = { + macosx = "macOS", + iphoneos = "ios", + appletvos = "tvos", + windows = "mingw" + } + return plats[plat] or plat +end + +-- get triplet +function triplet(plat, arch) + return plat .. arch +end + +-- get configurations +function main() + return { + repositories = {description = "set the maven repositories", default = { + "https://repo.maven.apache.org/maven2" + }} + } +end + diff --git a/xmake/modules/package/manager/kotlin-native/find_package.lua b/xmake/modules/package/manager/kotlin-native/find_package.lua new file mode 100644 index 000000000..b58eff6b4 --- /dev/null +++ b/xmake/modules/package/manager/kotlin-native/find_package.lua @@ -0,0 +1,37 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file find_package.lua +-- + +-- imports +import("lib.detect.find_file") +import("lib.detect.find_tool") +import("core.base.option") +import("core.project.config") +import("core.project.target") +import("package.manager.kotlin-native.configurations") + +-- find package from the kotlin-native package manager +-- +-- @param name the package name, e.g. org.jetbrains.kotlinx:kotlinx-serialization-json 1.8.0 +-- @param opt the options, e.g. {verbose = true) +-- +function main(name, opt) + opt = opt or {} + +end diff --git a/xmake/modules/package/manager/kotlin-native/install_package.lua b/xmake/modules/package/manager/kotlin-native/install_package.lua new file mode 100644 index 000000000..008295f02 --- /dev/null +++ b/xmake/modules/package/manager/kotlin-native/install_package.lua @@ -0,0 +1,46 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file install_package.lua +-- + +-- imports +import("core.base.option") +import("core.base.json") +import("core.base.semver") +import("lib.detect.find_tool") +import("package.manager.kotlin-native.configurations") +import("net.http") + +-- install package +-- +-- @param name the package name, e.g. org.jetbrains.kotlinx:kotlinx-serialization-json 1.8.0 +-- @param opt the options, e.g. {verbose = true} +-- +function main(name, opt) + opt = opt or {} + local configs = opt.configs or {} + + -- init triplet + local arch = opt.arch + local plat = opt.plat + plat = configurations.plat(plat) + arch = configurations.arch(arch) + local triplet = configurations.triplet(plat, arch) + + +end -- cgit v1.3.1 From b5ec74aa63fd8c0888400a9b6bd075b19da5c4c3 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 25 Feb 2025 22:56:49 +0800 Subject: select package version --- tests/projects/kotlin-native/package/src/main.kt | 22 ++++++++++++- .../manager/kotlin-native/install_package.lua | 38 ++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/tests/projects/kotlin-native/package/src/main.kt b/tests/projects/kotlin-native/package/src/main.kt index 543f5ac8f..ec15ce26d 100644 --- a/tests/projects/kotlin-native/package/src/main.kt +++ b/tests/projects/kotlin-native/package/src/main.kt @@ -1,3 +1,23 @@ +import kotlinx.serialization.Serializable +import kotlinx.serialization.encodeToString +import kotlinx.serialization.json.Json + +@Serializable +private data class Message( + val topic: String, + val content: String, +) + +private val PrettyPrintJson = Json { + prettyPrint = true +} + fun main() { - println("hello xmake!") + val message = Message( + topic = "Kotlin/Native", + content = "Hello!" + ) + println(PrettyPrintJson.encodeToString(message)) } + + diff --git a/xmake/modules/package/manager/kotlin-native/install_package.lua b/xmake/modules/package/manager/kotlin-native/install_package.lua index 008295f02..b6326e49c 100644 --- a/xmake/modules/package/manager/kotlin-native/install_package.lua +++ b/xmake/modules/package/manager/kotlin-native/install_package.lua @@ -20,12 +20,34 @@ -- imports import("core.base.option") +import("core.base.global") import("core.base.json") import("core.base.semver") import("lib.detect.find_tool") import("package.manager.kotlin-native.configurations") import("net.http") +-- select package version +-- e.g. https://repo.maven.apache.org/maven2/org/jetbrains/kotlinx/kotlinx-serialization-json-iosarm64/maven-metadata.xml +function _select_package_version(name, opt) + local installdir = opt.installdir + local manifest_file = path.join(installdir, "maven-metadata.xml") + for _, repository in ipairs(opt.repositories) do + local manifest_url = ("%s/%s-%s/maven-metadata.xml", repository, (name:gsub("%.", "/"):gsub(":", "/")), opt.triplet) + local ok = try { + function() + http.download(manifest_url, manifest_file, { + insecure = global.get("insecure-ssl")}) + return true + end + } + if ok and os.isfile(manifest_file) then + local manifest = io.readfile(manifest_file) + print(manifest) + end + end +end + -- install package -- -- @param name the package name, e.g. org.jetbrains.kotlinx:kotlinx-serialization-json 1.8.0 @@ -34,6 +56,7 @@ import("net.http") function main(name, opt) opt = opt or {} local configs = opt.configs or {} + local repositories = opt.repositories -- init triplet local arch = opt.arch @@ -42,5 +65,20 @@ function main(name, opt) arch = configurations.arch(arch) local triplet = configurations.triplet(plat, arch) + -- select version + local installdir = assert(opt.installdir, "installdir not found!") + local require_version = opt.require_version + if require_version == "latest" then + require_version = nil + end + local version, repository = _select_package_version(name, { + triplet = triplet, + version = require_version, + installdir = installdir, + repositories = repositories}) + assert(version and repository, "package(%s): %s not found for %s!", name, require_version, triplet) + + + end -- cgit v1.3.1 From db5b62a1c1ef4c678e7feb843dde92c7ff1484b3 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 25 Feb 2025 22:59:58 +0800 Subject: download kotlib libs --- .../manager/kotlin-native/configurations.lua | 2 +- .../manager/kotlin-native/install_package.lua | 43 +++++++++++++++++----- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/xmake/modules/package/manager/kotlin-native/configurations.lua b/xmake/modules/package/manager/kotlin-native/configurations.lua index 831403d03..ef9a70f38 100644 --- a/xmake/modules/package/manager/kotlin-native/configurations.lua +++ b/xmake/modules/package/manager/kotlin-native/configurations.lua @@ -34,7 +34,7 @@ end -- get platform for kotlin-native function plat(plat) local plats = { - macosx = "macOS", + macosx = "macos", iphoneos = "ios", appletvos = "tvos", windows = "mingw" diff --git a/xmake/modules/package/manager/kotlin-native/install_package.lua b/xmake/modules/package/manager/kotlin-native/install_package.lua index b6326e49c..d8598def3 100644 --- a/xmake/modules/package/manager/kotlin-native/install_package.lua +++ b/xmake/modules/package/manager/kotlin-native/install_package.lua @@ -26,14 +26,16 @@ import("core.base.semver") import("lib.detect.find_tool") import("package.manager.kotlin-native.configurations") import("net.http") +import("core.base.semver") -- select package version -- e.g. https://repo.maven.apache.org/maven2/org/jetbrains/kotlinx/kotlinx-serialization-json-iosarm64/maven-metadata.xml function _select_package_version(name, opt) local installdir = opt.installdir + local require_version = opt.require_version local manifest_file = path.join(installdir, "maven-metadata.xml") for _, repository in ipairs(opt.repositories) do - local manifest_url = ("%s/%s-%s/maven-metadata.xml", repository, (name:gsub("%.", "/"):gsub(":", "/")), opt.triplet) + local manifest_url = ("%s/%s-%s/maven-metadata.xml"):format(repository, (name:gsub("%.", "/"):gsub(":", "/")), opt.triplet) local ok = try { function() http.download(manifest_url, manifest_file, { @@ -43,11 +45,32 @@ function _select_package_version(name, opt) } if ok and os.isfile(manifest_file) then local manifest = io.readfile(manifest_file) - print(manifest) + local versions = {} + for _, line in ipairs(manifest:split("\n")) do + local v = line:match("(.*)") + if v then + table.insert(versions, v) + end + end + local version = semver.select(require_version, versions) + if version then + return version, repository + end end end end +-- install package +-- e.g. https://repo.maven.apache.org/maven2/org/jetbrains/kotlinx/kotlinx-serialization-json-iosarm64/1.8.0/kotlinx-serialization-json-iosarm64-1.8.0.klib +function _install_package(name, opt) + local installdir = opt.installdir + local basename = name:split(":")[2] .. "-" .. opt.triplet + local library_file = path.join(installdir, "lib", basename .. ".klib") + local library_url = ("%s/%s-%s/%s-%s.klib"):format(opt.repository, (name:gsub("%.", "/"):gsub(":", "/")), opt.triplet, basename, opt.version) + http.download(library_url, library_file, { + insecure = global.get("insecure-ssl")}) +end + -- install package -- -- @param name the package name, e.g. org.jetbrains.kotlinx:kotlinx-serialization-json 1.8.0 @@ -56,7 +79,7 @@ end function main(name, opt) opt = opt or {} local configs = opt.configs or {} - local repositories = opt.repositories + local repositories = configs.repositories -- init triplet local arch = opt.arch @@ -68,17 +91,17 @@ function main(name, opt) -- select version local installdir = assert(opt.installdir, "installdir not found!") local require_version = opt.require_version - if require_version == "latest" then - require_version = nil - end local version, repository = _select_package_version(name, { triplet = triplet, - version = require_version, installdir = installdir, + require_version = require_version, repositories = repositories}) assert(version and repository, "package(%s): %s not found for %s!", name, require_version, triplet) - - - + -- do install + _install_package(name, { + triplet = triplet, + installdir = installdir, + version = version, + repository = repository}) end -- cgit v1.3.1 From ca1b4ed22e3f9aeebce728459960d9238dba39c3 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 25 Feb 2025 23:02:18 +0800 Subject: find kotlin packages --- .../package/manager/kotlin-native/find_package.lua | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/xmake/modules/package/manager/kotlin-native/find_package.lua b/xmake/modules/package/manager/kotlin-native/find_package.lua index b58eff6b4..6a8134ec6 100644 --- a/xmake/modules/package/manager/kotlin-native/find_package.lua +++ b/xmake/modules/package/manager/kotlin-native/find_package.lua @@ -33,5 +33,19 @@ import("package.manager.kotlin-native.configurations") -- function main(name, opt) opt = opt or {} - + local result = {} + local installdir = assert(opt.installdir, "installdir not found!") + local libraries = os.files(path.join(installdir, "lib", "*.klib")) + for _, libraryfile in ipairs(libraries) do + result.libfiles = result.libfiles or {} + result.links = result.links or {} + result.linkdirs = result.linkdirs or {} + table.insert(result.links, path.basename(libraryfile)) + table.insert(result.linkdirs, path.directory(libraryfile)) + table.insert(result.libfiles, libraryfile) + end + if result.links then + print(result) + return result + end end -- cgit v1.3.1 From c1fac4f233b9c33b897ec3348d908d9560eff385 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 25 Feb 2025 23:03:48 +0800 Subject: fix find kotlin libs --- .../package/manager/kotlin-native/find_package.lua | 15 +++------------ .../package/manager/kotlin-native/install_package.lua | 19 +++++++++++++------ 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/xmake/modules/package/manager/kotlin-native/find_package.lua b/xmake/modules/package/manager/kotlin-native/find_package.lua index 6a8134ec6..da2768306 100644 --- a/xmake/modules/package/manager/kotlin-native/find_package.lua +++ b/xmake/modules/package/manager/kotlin-native/find_package.lua @@ -35,17 +35,8 @@ function main(name, opt) opt = opt or {} local result = {} local installdir = assert(opt.installdir, "installdir not found!") - local libraries = os.files(path.join(installdir, "lib", "*.klib")) - for _, libraryfile in ipairs(libraries) do - result.libfiles = result.libfiles or {} - result.links = result.links or {} - result.linkdirs = result.linkdirs or {} - table.insert(result.links, path.basename(libraryfile)) - table.insert(result.linkdirs, path.directory(libraryfile)) - table.insert(result.libfiles, libraryfile) - end - if result.links then - print(result) - return result + local manifest_file = path.join(installdir, "installed_manifest.txt") + if os.isfile(manifest_file) then + return io.load(manifest_file) end end diff --git a/xmake/modules/package/manager/kotlin-native/install_package.lua b/xmake/modules/package/manager/kotlin-native/install_package.lua index d8598def3..aaac0fd33 100644 --- a/xmake/modules/package/manager/kotlin-native/install_package.lua +++ b/xmake/modules/package/manager/kotlin-native/install_package.lua @@ -33,20 +33,20 @@ import("core.base.semver") function _select_package_version(name, opt) local installdir = opt.installdir local require_version = opt.require_version - local manifest_file = path.join(installdir, "maven-metadata.xml") + local metadata_file = path.join(installdir, "maven-metadata.xml") for _, repository in ipairs(opt.repositories) do - local manifest_url = ("%s/%s-%s/maven-metadata.xml"):format(repository, (name:gsub("%.", "/"):gsub(":", "/")), opt.triplet) + local metadata_url = ("%s/%s-%s/maven-metadata.xml"):format(repository, (name:gsub("%.", "/"):gsub(":", "/")), opt.triplet) local ok = try { function() - http.download(manifest_url, manifest_file, { + http.download(metadata_url, metadata_file, { insecure = global.get("insecure-ssl")}) return true end } - if ok and os.isfile(manifest_file) then - local manifest = io.readfile(manifest_file) + if ok and os.isfile(metadata_file) then + local metadata = io.readfile(metadata_file) local versions = {} - for _, line in ipairs(manifest:split("\n")) do + for _, line in ipairs(metadata:split("\n")) do local v = line:match("(.*)") if v then table.insert(versions, v) @@ -69,6 +69,13 @@ function _install_package(name, opt) local library_url = ("%s/%s-%s/%s-%s.klib"):format(opt.repository, (name:gsub("%.", "/"):gsub(":", "/")), opt.triplet, basename, opt.version) http.download(library_url, library_file, { insecure = global.get("insecure-ssl")}) + + local manifest_file = path.join(installdir, "installed_manifest.txt") + io.save(manifest_file, { + links = basename, + linkdirs = path.directory(library_file), + libfiles = library_file, + version = opt.version}) end -- install package -- cgit v1.3.1 From ac47c85eb55b510b6b40a567ad86fb02a7a25425 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 25 Feb 2025 23:09:21 +0800 Subject: improve links --- tests/projects/kotlin-native/package/xmake.lua | 1 + xmake/languages/kotlin/load.lua | 9 +++++---- xmake/languages/kotlin/xmake.lua | 4 ---- xmake/modules/core/tools/kotlinc_native.lua | 5 +++++ xmake/modules/package/manager/kotlin-native/install_package.lua | 9 +++++---- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/tests/projects/kotlin-native/package/xmake.lua b/tests/projects/kotlin-native/package/xmake.lua index 1b7d146f3..14d74faf8 100644 --- a/tests/projects/kotlin-native/package/xmake.lua +++ b/tests/projects/kotlin-native/package/xmake.lua @@ -2,6 +2,7 @@ add_rules("mode.debug", "mode.release") add_requires("kotlin-native") add_requires("kotlin-native::org.jetbrains.kotlinx:kotlinx-serialization-json 1.8.0", {alias = "json"}) +add_requires("kotlin-native::org.jetbrains.kotlinx:kotlinx-serialization-json 1.8.0", {alias = "json"}) target("test") set_kind("binary") diff --git a/xmake/languages/kotlin/load.lua b/xmake/languages/kotlin/load.lua index 8d7ad0430..7964351ec 100644 --- a/xmake/languages/kotlin/load.lua +++ b/xmake/languages/kotlin/load.lua @@ -26,25 +26,26 @@ function _get_apis() , "target.add_ldflags" , "target.add_arflags" , "target.add_shflags" - , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path + , "target.add_links" -- option.add_xxx , "option.add_kcflags" , "option.add_ldflags" , "option.add_arflags" , "option.add_shflags" - , "option.add_rpathdirs" + , "option.add_links" -- toolchain.add_xxx , "toolchain.add_kcflags" , "toolchain.add_ldflags" , "toolchain.add_arflags" - , "toolchain.add_shflags" - , "toolchain.add_rpathdirs" + , "toolchain.add_links" } apis.paths = { -- target.add_xxx "target.add_linkdirs" -- option.add_xxx , "option.add_linkdirs" + -- toolchain.add_xxx + , "toolchain.add_linkdirs" } return apis end diff --git a/xmake/languages/kotlin/xmake.lua b/xmake/languages/kotlin/xmake.lua index 3269ea6cd..9820531b8 100644 --- a/xmake/languages/kotlin/xmake.lua +++ b/xmake/languages/kotlin/xmake.lua @@ -42,12 +42,10 @@ language("kotlin") , "config.frameworkdirs" , "target.linkdirs" , "target.frameworkdirs" - , "target.rpathdirs" , "target.strip" , "target.symbols" , "toolchain.linkdirs" , "toolchain.frameworkdirs" - , "toolchain.rpathdirs" , "config.frameworks" , "target.frameworks" , "toolchain.frameworks" @@ -63,12 +61,10 @@ language("kotlin") , "config.frameworkdirs" , "target.linkdirs" , "target.frameworkdirs" - , "target.rpathdirs" , "target.strip" , "target.symbols" , "toolchain.linkdirs" , "toolchain.frameworkdirs" - , "toolchain.rpathdirs" , "config.frameworks" , "target.frameworks" , "toolchain.frameworks" diff --git a/xmake/modules/core/tools/kotlinc_native.lua b/xmake/modules/core/tools/kotlinc_native.lua index 8c703477c..c785f646f 100644 --- a/xmake/modules/core/tools/kotlinc_native.lua +++ b/xmake/modules/core/tools/kotlinc_native.lua @@ -30,6 +30,11 @@ import("lib.detect.find_tool") function init(self) end +-- make the link flag +function nf_link(self, lib) + return {"-l", lib} +end + -- make the build arguments list function buildargv(self, sourcefiles, targetkind, targetfile, flags, opt) return self:program(), table.join(flags, sourcefiles, "-o", targetfile) diff --git a/xmake/modules/package/manager/kotlin-native/install_package.lua b/xmake/modules/package/manager/kotlin-native/install_package.lua index aaac0fd33..ed9cb4ab9 100644 --- a/xmake/modules/package/manager/kotlin-native/install_package.lua +++ b/xmake/modules/package/manager/kotlin-native/install_package.lua @@ -65,15 +65,14 @@ end function _install_package(name, opt) local installdir = opt.installdir local basename = name:split(":")[2] .. "-" .. opt.triplet - local library_file = path.join(installdir, "lib", basename .. ".klib") - local library_url = ("%s/%s-%s/%s-%s.klib"):format(opt.repository, (name:gsub("%.", "/"):gsub(":", "/")), opt.triplet, basename, opt.version) + local library_file = path.join(installdir, "klib", "platform", opt.plat .. "_" .. opt.arch, basename .. ".klib") + local library_url = ("%s/%s-%s/%s/%s-%s.klib"):format(opt.repository, (name:gsub("%.", "/"):gsub(":", "/")), opt.triplet, opt.version, basename, opt.version) http.download(library_url, library_file, { insecure = global.get("insecure-ssl")}) local manifest_file = path.join(installdir, "installed_manifest.txt") io.save(manifest_file, { - links = basename, - linkdirs = path.directory(library_file), + links = library_file, libfiles = library_file, version = opt.version}) end @@ -107,6 +106,8 @@ function main(name, opt) -- do install _install_package(name, { + plat = plat, + arch = arch, triplet = triplet, installdir = installdir, version = version, -- cgit v1.3.1 From 87693d5c7c360b3218032bc2bff4253a27ad0425 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 25 Feb 2025 23:29:45 +0800 Subject: add cli-parser test --- .../kotlin-native/package/cli-parser/src/main.kt | 10 ++++++++++ .../kotlin-native/package/cli-parser/xmake.lua | 10 ++++++++++ .../kotlin-native/package/json/src/main.kt | 23 ++++++++++++++++++++++ .../projects/kotlin-native/package/json/xmake.lua | 11 +++++++++++ tests/projects/kotlin-native/package/src/main.kt | 23 ---------------------- tests/projects/kotlin-native/package/xmake.lua | 12 ----------- xmake/rules/kotlin-native/xmake.lua | 1 + 7 files changed, 55 insertions(+), 35 deletions(-) create mode 100644 tests/projects/kotlin-native/package/cli-parser/src/main.kt create mode 100644 tests/projects/kotlin-native/package/cli-parser/xmake.lua create mode 100644 tests/projects/kotlin-native/package/json/src/main.kt create mode 100644 tests/projects/kotlin-native/package/json/xmake.lua delete mode 100644 tests/projects/kotlin-native/package/src/main.kt delete mode 100644 tests/projects/kotlin-native/package/xmake.lua diff --git a/tests/projects/kotlin-native/package/cli-parser/src/main.kt b/tests/projects/kotlin-native/package/cli-parser/src/main.kt new file mode 100644 index 000000000..dae11c45c --- /dev/null +++ b/tests/projects/kotlin-native/package/cli-parser/src/main.kt @@ -0,0 +1,10 @@ +import kotlinx.cli.ArgParser +import kotlinx.cli.ArgType +import kotlinx.cli.default + +fun main(args: Array) { + val parser = ArgParser("example") + val name by parser.option(ArgType.String, shortName = "n", description = "Your name").default("World") + parser.parse(args) + println("Hello, $name!") +} diff --git a/tests/projects/kotlin-native/package/cli-parser/xmake.lua b/tests/projects/kotlin-native/package/cli-parser/xmake.lua new file mode 100644 index 000000000..f2cfdac2b --- /dev/null +++ b/tests/projects/kotlin-native/package/cli-parser/xmake.lua @@ -0,0 +1,10 @@ +add_rules("mode.debug", "mode.release") + +add_requires("kotlin-native") +add_requires("kotlin-native::org.jetbrains.kotlinx:kotlinx-cli 0.3.6", {alias = "kotlinx-cli"}) + +target("test") + set_kind("binary") + add_files("src/*.kt") + add_packages("kotlinx-cli") + set_toolchains("@kotlin-native") diff --git a/tests/projects/kotlin-native/package/json/src/main.kt b/tests/projects/kotlin-native/package/json/src/main.kt new file mode 100644 index 000000000..ec15ce26d --- /dev/null +++ b/tests/projects/kotlin-native/package/json/src/main.kt @@ -0,0 +1,23 @@ +import kotlinx.serialization.Serializable +import kotlinx.serialization.encodeToString +import kotlinx.serialization.json.Json + +@Serializable +private data class Message( + val topic: String, + val content: String, +) + +private val PrettyPrintJson = Json { + prettyPrint = true +} + +fun main() { + val message = Message( + topic = "Kotlin/Native", + content = "Hello!" + ) + println(PrettyPrintJson.encodeToString(message)) +} + + diff --git a/tests/projects/kotlin-native/package/json/xmake.lua b/tests/projects/kotlin-native/package/json/xmake.lua new file mode 100644 index 000000000..2f085de15 --- /dev/null +++ b/tests/projects/kotlin-native/package/json/xmake.lua @@ -0,0 +1,11 @@ +add_rules("mode.debug", "mode.release") + +add_requires("kotlin-native") +add_requires("kotlin-native::org.jetbrains.kotlinx:kotlinx-serialization-json 1.8.0", {alias = "json"}) +add_requires("kotlin-native::org.jetbrains.kotlinx:kotlinx-serialization-core 1.8.0", {alias = "core"}) + +target("test") + set_kind("binary") + add_files("src/*.kt") + add_packages("json", "core") + set_toolchains("@kotlin-native") diff --git a/tests/projects/kotlin-native/package/src/main.kt b/tests/projects/kotlin-native/package/src/main.kt deleted file mode 100644 index ec15ce26d..000000000 --- a/tests/projects/kotlin-native/package/src/main.kt +++ /dev/null @@ -1,23 +0,0 @@ -import kotlinx.serialization.Serializable -import kotlinx.serialization.encodeToString -import kotlinx.serialization.json.Json - -@Serializable -private data class Message( - val topic: String, - val content: String, -) - -private val PrettyPrintJson = Json { - prettyPrint = true -} - -fun main() { - val message = Message( - topic = "Kotlin/Native", - content = "Hello!" - ) - println(PrettyPrintJson.encodeToString(message)) -} - - diff --git a/tests/projects/kotlin-native/package/xmake.lua b/tests/projects/kotlin-native/package/xmake.lua deleted file mode 100644 index 14d74faf8..000000000 --- a/tests/projects/kotlin-native/package/xmake.lua +++ /dev/null @@ -1,12 +0,0 @@ -add_rules("mode.debug", "mode.release") - -add_requires("kotlin-native") -add_requires("kotlin-native::org.jetbrains.kotlinx:kotlinx-serialization-json 1.8.0", {alias = "json"}) -add_requires("kotlin-native::org.jetbrains.kotlinx:kotlinx-serialization-json 1.8.0", {alias = "json"}) - -target("test") - set_kind("binary") - add_files("src/*.kt") - add_packages("json") - set_toolchains("@kotlin-native") - diff --git a/xmake/rules/kotlin-native/xmake.lua b/xmake/rules/kotlin-native/xmake.lua index 386c85677..f2bd9ed5c 100644 --- a/xmake/rules/kotlin-native/xmake.lua +++ b/xmake/rules/kotlin-native/xmake.lua @@ -21,6 +21,7 @@ rule("kotlin-native.build") set_sourcekinds("kc") on_load(function (target) + target:add("kcflags", "-opt-in=kotlinx.cinterop.ExperimentalForeignApi", {force = true}) if target:is_static() then target:add("arflags", {"-produce", "static"}, {force = true}) target:add("includedirs", target:targetdir(), {interface = true}) -- cgit v1.3.1