diff options
| author | ruki <[email protected]> | 2024-02-06 22:44:21 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-02-06 22:44:21 +0800 |
| commit | 78a1a52f425010571eda84ab1cefeb11d78c20c8 (patch) | |
| tree | d6e1a9e42a68a2e8674b96abd015800c572a5276 | |
| parent | 469f941f5680273b5b734996677b055a776f0056 (diff) | |
add cosmoar support
| -rw-r--r-- | tests/projects/c/cosmocc/console/src/main.c (renamed from tests/projects/c/cosmocc/src/main.c) | 0 | ||||
| -rw-r--r-- | tests/projects/c/cosmocc/console/test.lua (renamed from tests/projects/c/cosmocc/test.lua) | 0 | ||||
| -rw-r--r-- | tests/projects/c/cosmocc/console/xmake.lua (renamed from tests/projects/c/cosmocc/xmake.lua) | 0 | ||||
| -rw-r--r-- | tests/projects/c/cosmocc/static_library/src/foo.c | 5 | ||||
| -rw-r--r-- | tests/projects/c/cosmocc/static_library/src/foo.h | 2 | ||||
| -rw-r--r-- | tests/projects/c/cosmocc/static_library/src/main.c | 7 | ||||
| -rw-r--r-- | tests/projects/c/cosmocc/static_library/xmake.lua | 15 | ||||
| -rw-r--r-- | xmake/modules/core/tools/ar.lua | 5 | ||||
| -rw-r--r-- | xmake/modules/core/tools/cosmoar.lua | 38 | ||||
| -rw-r--r-- | xmake/modules/core/tools/cosmocc.lua | 1 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_cosmoar.lua | 44 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_cosmocc.lua | 6 |
12 files changed, 118 insertions, 5 deletions
diff --git a/tests/projects/c/cosmocc/src/main.c b/tests/projects/c/cosmocc/console/src/main.c index a1ce06b81..a1ce06b81 100644 --- a/tests/projects/c/cosmocc/src/main.c +++ b/tests/projects/c/cosmocc/console/src/main.c diff --git a/tests/projects/c/cosmocc/test.lua b/tests/projects/c/cosmocc/console/test.lua index d6ef2e8da..d6ef2e8da 100644 --- a/tests/projects/c/cosmocc/test.lua +++ b/tests/projects/c/cosmocc/console/test.lua diff --git a/tests/projects/c/cosmocc/xmake.lua b/tests/projects/c/cosmocc/console/xmake.lua index babd520a2..babd520a2 100644 --- a/tests/projects/c/cosmocc/xmake.lua +++ b/tests/projects/c/cosmocc/console/xmake.lua diff --git a/tests/projects/c/cosmocc/static_library/src/foo.c b/tests/projects/c/cosmocc/static_library/src/foo.c new file mode 100644 index 000000000..1a1fb3425 --- /dev/null +++ b/tests/projects/c/cosmocc/static_library/src/foo.c @@ -0,0 +1,5 @@ +#include "foo.h" + +int add(int a, int b) { + return a + b; +} diff --git a/tests/projects/c/cosmocc/static_library/src/foo.h b/tests/projects/c/cosmocc/static_library/src/foo.h new file mode 100644 index 000000000..16d451cbb --- /dev/null +++ b/tests/projects/c/cosmocc/static_library/src/foo.h @@ -0,0 +1,2 @@ +int add(int a, int b); + diff --git a/tests/projects/c/cosmocc/static_library/src/main.c b/tests/projects/c/cosmocc/static_library/src/main.c new file mode 100644 index 000000000..a4c769408 --- /dev/null +++ b/tests/projects/c/cosmocc/static_library/src/main.c @@ -0,0 +1,7 @@ +#include "foo.h" +#include <stdio.h> + +int main(int argc, char** argv) { + printf("add(1, 2) = %d\n", add(1, 2)); + return 0; +} diff --git a/tests/projects/c/cosmocc/static_library/xmake.lua b/tests/projects/c/cosmocc/static_library/xmake.lua new file mode 100644 index 000000000..73d0a681d --- /dev/null +++ b/tests/projects/c/cosmocc/static_library/xmake.lua @@ -0,0 +1,15 @@ +add_rules("mode.release", "mode.debug") + +add_requires("cosmocc") +set_toolchains("@cosmocc") + +target("foo") + set_kind("static") + add_files("src/foo.c") + +target("demo") + set_kind("binary") + add_deps("foo") + add_files("src/main.c") + + diff --git a/xmake/modules/core/tools/ar.lua b/xmake/modules/core/tools/ar.lua index 0496238b4..b302504d8 100644 --- a/xmake/modules/core/tools/ar.lua +++ b/xmake/modules/core/tools/ar.lua @@ -49,7 +49,8 @@ function linkargv(self, objectfiles, targetkind, targetfile, flags, opt) end -- link the library file -function link(self, objectfiles, targetkind, targetfile, flags) +function link(self, objectfiles, targetkind, targetfile, flags, opt) + opt = opt or {} os.mkdir(path.directory(targetfile)) -- @note remove the previous archived file first to force recreating a new file @@ -57,7 +58,7 @@ function link(self, objectfiles, targetkind, targetfile, flags) -- link it local program, argv = linkargv(self, objectfiles, targetkind, targetfile, flags) - os.runv(program, argv, {envs = self:runenvs()}) + os.runv(program, argv, {envs = self:runenvs(), shell = opt.shell}) end diff --git a/xmake/modules/core/tools/cosmoar.lua b/xmake/modules/core/tools/cosmoar.lua new file mode 100644 index 000000000..2ee1741ae --- /dev/null +++ b/xmake/modules/core/tools/cosmoar.lua @@ -0,0 +1,38 @@ +--!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 cosmoar.lua +-- + +inherit("ar") + +function init(self) + _super.init(self) +end + +function link(self, objectfiles, targetkind, targetfile, flags, opt) + opt = opt or {} + if is_host("windows") then + targetfile = targetfile:gsub("\\", "/") + local objectfiles_new = {} + for idx, objectfile in ipairs(objectfiles) do + objectfiles_new[idx] = objectfiles[idx]:gsub("\\", "/") + end + objectfiles = objectfiles_new + end + return _super.link(self, objectfiles, targetkind, targetfile, flags, table.join(opt, {shell = true})) +end diff --git a/xmake/modules/core/tools/cosmocc.lua b/xmake/modules/core/tools/cosmocc.lua index 60f25a3f0..c53f6e1c5 100644 --- a/xmake/modules/core/tools/cosmocc.lua +++ b/xmake/modules/core/tools/cosmocc.lua @@ -32,6 +32,7 @@ end -- link the target file function link(self, objectfiles, targetkind, targetfile, flags, opt) + opt = opt or {} if is_host("windows") then targetfile = targetfile:gsub("\\", "/") local objectfiles_new = {} diff --git a/xmake/modules/detect/tools/find_cosmoar.lua b/xmake/modules/detect/tools/find_cosmoar.lua new file mode 100644 index 000000000..01c9232ce --- /dev/null +++ b/xmake/modules/detect/tools/find_cosmoar.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 find_cosmoar.lua +-- + +-- imports +import("lib.detect.find_program") + +-- find ar +-- +-- @param opt the argument options, e.g. {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local ar = find_cosmoar() +-- +-- @endcode +-- +function main(opt) + opt = opt or {} + opt.shell = true + local program = find_program(opt.program or "cosmoar", opt) + if program and is_host("windows") then + program = program:gsub("\\", "/") + end + return program +end diff --git a/xmake/modules/detect/tools/find_cosmocc.lua b/xmake/modules/detect/tools/find_cosmocc.lua index 102c45284..964b564c8 100644 --- a/xmake/modules/detect/tools/find_cosmocc.lua +++ b/xmake/modules/detect/tools/find_cosmocc.lua @@ -38,12 +38,12 @@ function main(opt) opt = opt or {} opt.shell = true local program = find_program(opt.program or "cosmocc", opt) + if program and is_host("windows") then + program = program:gsub("\\", "/") + end local version = nil if program and opt and opt.version then version = find_programver(program, opt) end - if program and is_host("windows") then - program = program:gsub("\\", "/") - end return program, version end |
