diff options
| author | ruki <[email protected]> | 2024-02-05 23:51:36 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-02-05 23:51:36 +0800 |
| commit | 8020014e06e7a43c9cd6cd3724f41521d8131723 (patch) | |
| tree | 3b901b4e1893c42a791b62f949d5b5d587e7b8da | |
| parent | 4972cfb86feab7310995ffeb84edd656017efab8 (diff) | |
add cosmocc toolchain and test
| -rw-r--r-- | tests/projects/c/cosmocc/src/main.c | 6 | ||||
| -rw-r--r-- | tests/projects/c/cosmocc/xmake.lua | 9 | ||||
| -rw-r--r-- | xmake/toolchains/cosmocc/check.lua | 55 | ||||
| -rw-r--r-- | xmake/toolchains/cosmocc/xmake.lua | 44 |
4 files changed, 114 insertions, 0 deletions
diff --git a/tests/projects/c/cosmocc/src/main.c b/tests/projects/c/cosmocc/src/main.c new file mode 100644 index 000000000..a1ce06b81 --- /dev/null +++ b/tests/projects/c/cosmocc/src/main.c @@ -0,0 +1,6 @@ +#include <stdio.h> + +int main(int argc, char** argv) { + printf("hello world\n"); + return 0; +} diff --git a/tests/projects/c/cosmocc/xmake.lua b/tests/projects/c/cosmocc/xmake.lua new file mode 100644 index 000000000..f625f7500 --- /dev/null +++ b/tests/projects/c/cosmocc/xmake.lua @@ -0,0 +1,9 @@ +add_rules("mode.debug", "mode.release") + +add_requires("cosmocc") + +target("test") + set_kind("binary") + add_files("src/*.c") + add_packages("cosmocc") + diff --git a/xmake/toolchains/cosmocc/check.lua b/xmake/toolchains/cosmocc/check.lua new file mode 100644 index 000000000..a1abb7daf --- /dev/null +++ b/xmake/toolchains/cosmocc/check.lua @@ -0,0 +1,55 @@ +--!A cross-toolchain 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 check.lua +-- + +-- imports +import("core.project.config") +import("lib.detect.find_path") + +-- check the cross toolchain +function main(toolchain) + + -- get sdk directory + local sdkdir = toolchain:sdkdir() + local bindir = toolchain:bindir() + + -- find cross toolchain from external envirnoment + local cross_toolchain = find_cross_toolchain(sdkdir, {bindir = bindir}) + if not cross_toolchain then + -- find it from packages + for _, package in ipairs(toolchain:packages()) do + local installdir = package:installdir() + if installdir and os.isdir(installdir) then + cross_toolchain = find_cross_toolchain(installdir) + if cross_toolchain then + break + end + end + end + end + if cross_toolchain then + toolchain:config_set("cross", cross_toolchain.cross) + toolchain:config_set("bindir", cross_toolchain.bindir) + toolchain:config_set("sdkdir", cross_toolchain.sdkdir) + toolchain:configs_save() + else + raise("cosmocc toolchain not found!") + end + return cross_toolchain +end diff --git a/xmake/toolchains/cosmocc/xmake.lua b/xmake/toolchains/cosmocc/xmake.lua new file mode 100644 index 000000000..d2637be98 --- /dev/null +++ b/xmake/toolchains/cosmocc/xmake.lua @@ -0,0 +1,44 @@ +--!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 xmake.lua +-- + +toolchain("cosmocc") + set_kind("standalone") + set_homepage("https://github.com/jart/cosmopolitan") + set_description("build-once run-anywhere c library") + + set_toolset("cc", "cosmocc") + set_toolset("cxx", "cosmocc", "cosmoc++") + set_toolset("cpp", "cosmocc -E") + set_toolset("as", "cosmocc") + set_toolset("ld", "cosmoc++", "cosmocc") + set_toolset("sh", "cosmoc++", "cosmocc") + set_toolset("ar", "cosmoar") + + on_check("check") + + on_load(function (toolchain) + if toolchain:is_arch("x86_64", "x64") then + target:set("toolset", "ranlib", "x86_64-linux-cosmo-ranlib") + target:set("toolset", "strip", "x86_64-linux-cosmo-strip") + else + target:set("toolset", "ranlib", "aarch64-linux-cosmo-ranlib") + target:set("toolset", "strip", "aarch64-linux-cosmo-strip") + end + end) |
