mirror of https://github.com/xmake-io/xmake.git
Compare commits
49 Commits
0093820554
...
45d3ab4d8e
Author | SHA1 | Date |
---|---|---|
ruki | 45d3ab4d8e | |
ruki | abd15c255c | |
ruki | 796a3b9d50 | |
ruki | dab3f10802 | |
ruki | e193d8adad | |
ririyeye | a1d6f47c88 | |
ririyeye | a99c45e5f4 | |
ruki | 6c2929bf34 | |
ruki | 7a95d412fe | |
ruki | 9ab3585df2 | |
ruki | 82c5c02fdf | |
ruki | 1386ddfe46 | |
ruki | c62ec15e9b | |
ruki | 560195a98b | |
ruki | 5e3238136f | |
ruki | 70a00eb887 | |
ruki | 4dfd87d6ad | |
ruki | 179a663c2a | |
ruki | ecf4f21dd3 | |
ruki | c92b5d009f | |
ruki | deb55641c2 | |
ruki | b805dc5ca9 | |
ruki | c78f1d8a87 | |
ruki | 82aafe2ab3 | |
ruki | 13c88acff1 | |
ruki | b3c6d96824 | |
ruki | d3e46bad60 | |
ruki | d60ca24f63 | |
ririyeye | fcf649a832 | |
ruki | a7aab9dc7e | |
ruki | ddbef7afc5 | |
ruki | 9a7d7d8f5b | |
ruki | 0c0b5c959f | |
ruki | 22b4ab1e37 | |
ruki | 9c42ce00a2 | |
ruki | 89f0479a5d | |
Yc7521 | a1b91de32f | |
Yc7521 | 36c57592f6 | |
ruki | cb6f7672a9 | |
ruki | fc14af5094 | |
ruki | 4d8f21ac73 | |
Yc7521 | e1e4635d31 | |
ruki | 86627f20f8 | |
Jérôme Leclercq | 0af7f027af | |
ruki | 241631f896 | |
ruki | ead634740e | |
ruki | 5951fcc39d | |
ruki | 5da59ed0a5 | |
ruki | 3260d857fb |
10
CHANGELOG.md
10
CHANGELOG.md
|
@ -2,6 +2,8 @@
|
|||
|
||||
## master (unreleased)
|
||||
|
||||
## v2.9.6
|
||||
|
||||
### New features
|
||||
|
||||
* [#5527](https://github.com/xmake-io/xmake/issues/5527): Add `set_policy("compatibility.version", "3.0")` to preview v3.0 features.
|
||||
|
@ -12,6 +14,9 @@
|
|||
* [#5631](https://github.com/xmake-io/xmake/pull/5631): Add `as_needed` for `add_linkgroups`
|
||||
* [#5702](https://github.com/xmake-io/xmake/issues/5702): Improve hash module
|
||||
* [#5688](https://github.com/xmake-io/xmake/pull/5688): Improve hashset module
|
||||
* [#5711](https://github.com/xmake-io/xmake/issues/5711): Support to parse include deps for sdcc
|
||||
* [#5727](https://github.com/xmake-io/xmake/issues/5727): Improve configs for add_requires
|
||||
* [#5762](https://github.com/xmake-io/xmake/pull/5762): Improve bin2c speed
|
||||
|
||||
### Bugs fixed
|
||||
|
||||
|
@ -1892,6 +1897,8 @@
|
|||
|
||||
## master (开发中)
|
||||
|
||||
## v2.9.6
|
||||
|
||||
### 新特性
|
||||
|
||||
* [#5527](https://github.com/xmake-io/xmake/issues/5527): 添加 `set_policy("compatibility.version", "3.0")` 提前预览体验 3.0 特性
|
||||
|
@ -1902,6 +1909,9 @@
|
|||
* [#5631](https://github.com/xmake-io/xmake/pull/5631): 为 `add_linkgroups` 添加 `as_needed`
|
||||
* [#5702](https://github.com/xmake-io/xmake/issues/5702): 改进 hash 模块
|
||||
* [#5688](https://github.com/xmake-io/xmake/pull/5688): 改进 hashset
|
||||
* [#5711](https://github.com/xmake-io/xmake/issues/5711): 为 sdcc 支持解析 include 依赖
|
||||
* [#5727](https://github.com/xmake-io/xmake/issues/5727): 为 add_requires 改进 configs 配置
|
||||
* [#5762](https://github.com/xmake-io/xmake/pull/5762): 改进 bin2c 速度
|
||||
|
||||
### Bugs 修复
|
||||
|
||||
|
|
|
@ -316,6 +316,9 @@ tb_int_t xm_tty_term_mode(lua_State* lua);
|
|||
// the package functions
|
||||
tb_int_t xm_package_loadxmi(lua_State* lua);
|
||||
|
||||
// the utils functions
|
||||
tb_int_t xm_utils_bin2c(lua_State* lua);
|
||||
|
||||
#ifdef XM_CONFIG_API_HAVE_CURSES
|
||||
// register curses functions
|
||||
tb_int_t xm_lua_curses_register(lua_State* lua, tb_char_t const* module);
|
||||
|
@ -600,6 +603,13 @@ static luaL_Reg const g_package_functions[] =
|
|||
, { tb_null, tb_null }
|
||||
};
|
||||
|
||||
// the utils functions
|
||||
static luaL_Reg const g_utils_functions[] =
|
||||
{
|
||||
{ "bin2c", xm_utils_bin2c }
|
||||
, { tb_null, tb_null }
|
||||
};
|
||||
|
||||
// the lua global instance for signal handler
|
||||
static lua_State* g_lua = tb_null;
|
||||
|
||||
|
@ -1364,6 +1374,9 @@ xm_engine_ref_t xm_engine_init(tb_char_t const* name, xm_engine_lni_initalizer_c
|
|||
// bind package functions
|
||||
xm_lua_register(engine->lua, "package", g_package_functions);
|
||||
|
||||
// bind utils functions
|
||||
xm_lua_register(engine->lua, "utils", g_utils_functions);
|
||||
|
||||
#ifdef XM_CONFIG_API_HAVE_CURSES
|
||||
// bind curses
|
||||
xm_lua_curses_register(engine->lua, "curses");
|
||||
|
|
|
@ -0,0 +1,165 @@
|
|||
/*!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 bin2c.c
|
||||
*
|
||||
*/
|
||||
|
||||
/* //////////////////////////////////////////////////////////////////////////////////////
|
||||
* trace
|
||||
*/
|
||||
#define TB_TRACE_MODULE_NAME "bin2c"
|
||||
#define TB_TRACE_MODULE_DEBUG (0)
|
||||
|
||||
/* //////////////////////////////////////////////////////////////////////////////////////
|
||||
* includes
|
||||
*/
|
||||
#include "prefix.h"
|
||||
|
||||
/* //////////////////////////////////////////////////////////////////////////////////////
|
||||
* private implementation
|
||||
*/
|
||||
static __tb_inline__ tb_size_t xm_utils_bin2c_hex2str(tb_char_t str[5], tb_byte_t value)
|
||||
{
|
||||
static tb_char_t const* digits_table = "0123456789ABCDEF";
|
||||
str[0] = ' ';
|
||||
str[1] = '0';
|
||||
str[2] = 'x';
|
||||
str[3] = digits_table[(value >> 4) & 15];
|
||||
str[4] = digits_table[value & 15];
|
||||
return 5;
|
||||
}
|
||||
|
||||
static tb_bool_t xm_utils_bin2c_dump(tb_stream_ref_t istream, tb_stream_ref_t ostream, tb_int_t linewidth, tb_bool_t nozeroend)
|
||||
{
|
||||
tb_bool_t first = tb_true;
|
||||
tb_hong_t i = 0;
|
||||
tb_hong_t left = 0;
|
||||
tb_char_t line[4096];
|
||||
tb_byte_t data[512];
|
||||
tb_size_t linesize = 0;
|
||||
tb_size_t need = 0;
|
||||
tb_assert_and_check_return_val(linewidth < sizeof(data), tb_false);
|
||||
while (!tb_stream_beof(istream))
|
||||
{
|
||||
linesize = 0;
|
||||
left = tb_stream_left(istream);
|
||||
need = (tb_size_t)tb_min(left, linewidth);
|
||||
if (need)
|
||||
{
|
||||
if (!tb_stream_bread(istream, data, need))
|
||||
break;
|
||||
|
||||
if (!nozeroend && tb_stream_beof(istream))
|
||||
{
|
||||
tb_assert_and_check_break(need + 1 < sizeof(data));
|
||||
data[need++] = '\0';
|
||||
}
|
||||
|
||||
tb_assert_and_check_break(linesize + 6 * need < sizeof(line));
|
||||
|
||||
i = 0;
|
||||
if (first)
|
||||
{
|
||||
first = tb_false;
|
||||
line[linesize++] = ' ';
|
||||
}
|
||||
else line[linesize++] = ',';
|
||||
linesize += xm_utils_bin2c_hex2str(line + linesize, data[i]);
|
||||
|
||||
for (i = 1; i < need; i++)
|
||||
{
|
||||
line[linesize++] = ',';
|
||||
linesize += xm_utils_bin2c_hex2str(line + linesize, data[i]);
|
||||
}
|
||||
tb_assert_and_check_break(i == need && linesize && linesize < sizeof(line));
|
||||
|
||||
if (tb_stream_bwrit_line(ostream, line, linesize) < 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return tb_stream_beof(istream);
|
||||
}
|
||||
|
||||
/* //////////////////////////////////////////////////////////////////////////////////////
|
||||
* implementation
|
||||
*/
|
||||
|
||||
/* generate c/c++ code from the binary file
|
||||
*
|
||||
* local ok, errors = utils.bin2c(binaryfile, outputfile, linewidth, nozeroend)
|
||||
*/
|
||||
tb_int_t xm_utils_bin2c(lua_State* lua)
|
||||
{
|
||||
// check
|
||||
tb_assert_and_check_return_val(lua, 0);
|
||||
|
||||
// get the binaryfile
|
||||
tb_char_t const* binaryfile = luaL_checkstring(lua, 1);
|
||||
tb_check_return_val(binaryfile, 0);
|
||||
|
||||
// get the outputfile
|
||||
tb_char_t const* outputfile = luaL_checkstring(lua, 2);
|
||||
tb_check_return_val(outputfile, 0);
|
||||
|
||||
// get line width
|
||||
tb_int_t linewidth = (tb_int_t)lua_tointeger(lua, 3);
|
||||
|
||||
// no zero end?
|
||||
tb_bool_t nozeroend = (tb_bool_t)lua_toboolean(lua, 4);
|
||||
|
||||
// do dump
|
||||
tb_bool_t ok = tb_false;
|
||||
tb_stream_ref_t istream = tb_stream_init_from_file(binaryfile, TB_FILE_MODE_RO);
|
||||
tb_stream_ref_t ostream = tb_stream_init_from_file(outputfile, TB_FILE_MODE_RW | TB_FILE_MODE_CREAT | TB_FILE_MODE_TRUNC);
|
||||
do
|
||||
{
|
||||
if (!tb_stream_open(istream))
|
||||
{
|
||||
lua_pushboolean(lua, tb_false);
|
||||
lua_pushfstring(lua, "bin2c: open %s failed", binaryfile);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!tb_stream_open(ostream))
|
||||
{
|
||||
lua_pushboolean(lua, tb_false);
|
||||
lua_pushfstring(lua, "bin2c: open %s failed", outputfile);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!xm_utils_bin2c_dump(istream, ostream, linewidth, nozeroend))
|
||||
{
|
||||
lua_pushboolean(lua, tb_false);
|
||||
lua_pushfstring(lua, "bin2c: dump data failed");
|
||||
break;
|
||||
}
|
||||
|
||||
ok = tb_true;
|
||||
lua_pushboolean(lua, ok);
|
||||
|
||||
} while (0);
|
||||
|
||||
if (istream) tb_stream_clos(istream);
|
||||
istream = tb_null;
|
||||
|
||||
if (ostream) tb_stream_clos(ostream);
|
||||
ostream = tb_null;
|
||||
|
||||
return ok? 1 : 2;
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
/*!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 prefix.h
|
||||
*
|
||||
*/
|
||||
#ifndef XM_UTILS_PREFIX_H
|
||||
#define XM_UTILS_PREFIX_H
|
||||
|
||||
/* //////////////////////////////////////////////////////////////////////////////////////
|
||||
* includes
|
||||
*/
|
||||
#include "../prefix.h"
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -71,6 +71,7 @@ target "xmake"
|
|||
add_files "semver/*.c"
|
||||
add_files "string/*.c"
|
||||
add_files "tty/*.c"
|
||||
add_files "utils/*.c"
|
||||
if is_plat "mingw"; then
|
||||
add_files "winos/*.c"
|
||||
fi
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
set_project("xmake")
|
||||
|
||||
-- version
|
||||
set_version("2.9.5", {build = "%Y%m%d"})
|
||||
set_version("2.9.6", {build = "%Y%m%d"})
|
||||
|
||||
-- set xmake min version
|
||||
set_xmakever("2.8.5")
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/bin/sh
|
||||
|
||||
set_project "xmake"
|
||||
set_version "2.9.5" "%Y%m%d"
|
||||
set_version "2.9.6" "%Y%m%d"
|
||||
|
||||
# set warning all
|
||||
set_warnings "all"
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#include "add.h"
|
||||
int add(int a, int b) {
|
||||
return a + b;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
#pragma once
|
||||
int add(int a, int b);
|
|
@ -1,20 +1,19 @@
|
|||
#include <linux/init.h>
|
||||
#include <linux/module.h>
|
||||
#include "add.h"
|
||||
|
||||
MODULE_LICENSE("Dual BSD/GPL");
|
||||
MODULE_AUTHOR("Ruki");
|
||||
MODULE_DESCRIPTION("A simple Hello World Module");
|
||||
MODULE_ALIAS("a simplest module");
|
||||
|
||||
int add(int a, int b);
|
||||
|
||||
int hello_init(void)
|
||||
static int hello_init(void)
|
||||
{
|
||||
printk(KERN_INFO "Hello World: %d\n", add(1, 2));
|
||||
return 0;
|
||||
}
|
||||
|
||||
void hello_exit(void)
|
||||
static void hello_exit(void)
|
||||
{
|
||||
printk(KERN_INFO "Goodbye World\n");
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#include "add.h"
|
||||
int add(int a, int b) {
|
||||
return a + b;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
#pragma once
|
||||
int add(int a, int b);
|
|
@ -1,20 +1,18 @@
|
|||
#include <linux/init.h>
|
||||
#include <linux/module.h>
|
||||
|
||||
#include "add.h"
|
||||
MODULE_LICENSE("Dual BSD/GPL");
|
||||
MODULE_AUTHOR("Ruki");
|
||||
MODULE_DESCRIPTION("A simple Hello World Module");
|
||||
MODULE_ALIAS("a simplest module");
|
||||
|
||||
int add(int a, int b);
|
||||
|
||||
int hello_init(void)
|
||||
static int hello_init(void)
|
||||
{
|
||||
printk(KERN_INFO "Hello World: %d\n", add(1, 2));
|
||||
return 0;
|
||||
}
|
||||
|
||||
void hello_exit(void)
|
||||
static void hello_exit(void)
|
||||
{
|
||||
printk(KERN_INFO "Goodbye World\n");
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#include "add.h"
|
||||
int add(int a, int b) {
|
||||
return a + b;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
#pragma once
|
||||
int add(int a, int b);
|
|
@ -1,20 +1,19 @@
|
|||
#include <linux/init.h>
|
||||
#include <linux/module.h>
|
||||
#include "add.h"
|
||||
|
||||
MODULE_LICENSE("Dual BSD/GPL");
|
||||
MODULE_AUTHOR("Ruki");
|
||||
MODULE_DESCRIPTION("A simple Hello World Module");
|
||||
MODULE_ALIAS("a simplest module");
|
||||
|
||||
int add(int a, int b);
|
||||
|
||||
int hello_init(void)
|
||||
static int hello_init(void)
|
||||
{
|
||||
printk(KERN_INFO "Hello World: %d\n", add(1, 2));
|
||||
return 0;
|
||||
}
|
||||
|
||||
void hello_exit(void)
|
||||
static void hello_exit(void)
|
||||
{
|
||||
printk(KERN_INFO "Goodbye World\n");
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ import("core.tool.compiler")
|
|||
import("core.project.depend")
|
||||
import("utils.progress")
|
||||
import("private.utils.batchcmds")
|
||||
import("object", {alias = "add_batchjobs_for_object"})
|
||||
import("object", {alias = "object_target"})
|
||||
import("linkdepfiles", {alias = "get_linkdepfiles"})
|
||||
|
||||
-- do link target
|
||||
|
@ -54,7 +54,7 @@ function _do_link_target(target, opt)
|
|||
end
|
||||
end, {dependfile = target:dependfile(),
|
||||
lastmtime = os.mtime(target:targetfile()),
|
||||
changed = target:is_rebuilt(),
|
||||
changed = target:is_rebuilt() or option.get("linkonly"),
|
||||
values = depvalues, files = depfiles, dryrun = dryrun})
|
||||
end
|
||||
|
||||
|
@ -143,6 +143,6 @@ function main(batchjobs, rootjob, target)
|
|||
--
|
||||
-- unless call set_policy("build.across_targets_in_parallel", false) to disable to build across targets in parallel.
|
||||
--
|
||||
local job_objects = add_batchjobs_for_object(batchjobs, job_link, target)
|
||||
local job_objects = object_target.add_batchjobs_for_object(batchjobs, job_link, target)
|
||||
return target:policy("build.across_targets_in_parallel") == false and job_objects or job_link, job_objects
|
||||
end
|
||||
|
|
|
@ -252,7 +252,22 @@ function add_batchjobs_for_sourcefiles(batchjobs, rootjob, target, sourcebatches
|
|||
end
|
||||
|
||||
-- add batch jobs for building object files
|
||||
function main(batchjobs, rootjob, target)
|
||||
function add_batchjobs_for_object(batchjobs, rootjob, target)
|
||||
return add_batchjobs_for_sourcefiles(batchjobs, rootjob, target, target:sourcebatches())
|
||||
end
|
||||
|
||||
-- add batch jobs for building object target
|
||||
function main(batchjobs, rootjob, target)
|
||||
|
||||
-- add a fake link job
|
||||
local job_link = batchjobs:addjob(target:name() .. "/fakelink", function (index, total, opt)
|
||||
end, {rootjob = rootjob})
|
||||
|
||||
-- we only need to return and depend the link job for each target,
|
||||
-- so we can compile the source files for each target in parallel
|
||||
--
|
||||
-- unless call set_policy("build.across_targets_in_parallel", false) to disable to build across targets in parallel.
|
||||
--
|
||||
local job_objects = add_batchjobs_for_object(batchjobs, job_link, target)
|
||||
return target:policy("build.across_targets_in_parallel") == false and job_objects or job_link, job_objects
|
||||
end
|
||||
|
|
|
@ -26,7 +26,7 @@ import("core.tool.compiler")
|
|||
import("core.project.depend")
|
||||
import("utils.progress")
|
||||
import("private.utils.batchcmds")
|
||||
import("object", {alias = "add_batchjobs_for_object"})
|
||||
import("object", {alias = "object_target"})
|
||||
import("linkdepfiles", {alias = "get_linkdepfiles"})
|
||||
|
||||
-- do link target
|
||||
|
@ -55,7 +55,7 @@ function _do_link_target(target, opt)
|
|||
|
||||
end, {dependfile = target:dependfile(),
|
||||
lastmtime = os.mtime(target:targetfile()),
|
||||
changed = target:is_rebuilt(),
|
||||
changed = target:is_rebuilt() or option.get("linkonly"),
|
||||
values = depvalues, files = depfiles, dryrun = dryrun})
|
||||
end
|
||||
|
||||
|
@ -144,6 +144,6 @@ function main(batchjobs, rootjob, target)
|
|||
--
|
||||
-- unless call set_policy("build.across_targets_in_parallel", false) to disable to build across targets in parallel.
|
||||
--
|
||||
local job_objects = add_batchjobs_for_object(batchjobs, job_link, target)
|
||||
local job_objects = object_target.add_batchjobs_for_object(batchjobs, job_link, target)
|
||||
return target:policy("build.across_targets_in_parallel") == false and job_objects or job_link, job_objects
|
||||
end
|
||||
|
|
|
@ -26,7 +26,7 @@ import("core.tool.compiler")
|
|||
import("core.project.depend")
|
||||
import("utils.progress")
|
||||
import("private.utils.batchcmds")
|
||||
import("object", {alias = "add_batchjobs_for_object"})
|
||||
import("object", {alias = "object_target"})
|
||||
import("linkdepfiles", {alias = "get_linkdepfiles"})
|
||||
|
||||
-- do link target
|
||||
|
@ -55,7 +55,7 @@ function _do_link_target(target, opt)
|
|||
|
||||
end, {dependfile = target:dependfile(),
|
||||
lastmtime = os.mtime(target:targetfile()),
|
||||
changed = target:is_rebuilt(),
|
||||
changed = target:is_rebuilt() or option.get("linkonly"),
|
||||
values = depvalues, files = depfiles, dryrun = dryrun})
|
||||
end
|
||||
|
||||
|
@ -144,6 +144,6 @@ function main(batchjobs, rootjob, target)
|
|||
--
|
||||
-- unless call set_policy("build.across_targets_in_parallel", false) to disable to build across targets in parallel.
|
||||
--
|
||||
local job_objects = add_batchjobs_for_object(batchjobs, job_link, target)
|
||||
local job_objects = object_target.add_batchjobs_for_object(batchjobs, job_link, target)
|
||||
return target:policy("build.across_targets_in_parallel") == false and job_objects or job_link, job_objects
|
||||
end
|
||||
|
|
|
@ -44,6 +44,7 @@ task("build")
|
|||
"Set the number of parallel compilation jobs." }
|
||||
, {nil, "linkjobs", "kv", nil, "Set the number of parallel link jobs." }
|
||||
, {'w', "warning", "k", false , "Enable the warnings output. (deprecated)" }
|
||||
, {nil, "linkonly", "k", false , "Only link targets if object files have been compiled." }
|
||||
, {nil, "files", "kv", nil , "Build the given source files.",
|
||||
"e.g. ",
|
||||
" - xmake --files=src/main.c",
|
||||
|
|
|
@ -30,6 +30,9 @@ local io = require("base/io")
|
|||
local dump = require("base/dump")
|
||||
local text = require("base/text")
|
||||
|
||||
-- save original interfaces
|
||||
utils._bin2c = utils._bin2c or utils.bin2c
|
||||
|
||||
-- dump values
|
||||
function utils.dump(...)
|
||||
if option.get("quiet") then
|
||||
|
@ -318,5 +321,11 @@ function utils.vtable(data, opt)
|
|||
utils.vprintf(text.table(data, opt))
|
||||
end
|
||||
|
||||
-- generate c/c++ code from the binary file
|
||||
function utils.bin2c(binaryfile, outputfile, opt)
|
||||
opt = opt or {}
|
||||
return utils._bin2c(binaryfile, outputfile, opt.linewidth or 32, opt.nozeroend or false)
|
||||
end
|
||||
|
||||
-- return module
|
||||
return utils
|
||||
|
|
|
@ -501,8 +501,12 @@ function project._load_requires()
|
|||
requires_extra = requires_extra or {}
|
||||
for _, requirestr in ipairs(table.wrap(requires_str)) do
|
||||
|
||||
-- get the package name
|
||||
-- get the package name, e.g. packagename[foo,bar] >1.0
|
||||
local packagename = requirestr:split("%s")[1]
|
||||
local packagename_raw, _ = packagename:match("(.-)%[(.*)%]")
|
||||
if packagename_raw and not packagename:find("::", 1, true) then
|
||||
packagename = packagename_raw
|
||||
end
|
||||
|
||||
-- get alias and requireconfs
|
||||
local alias = nil
|
||||
|
|
|
@ -1699,7 +1699,7 @@ function _instance:filerules(sourcefile)
|
|||
if filerules then
|
||||
override = filerules.override
|
||||
for _, rulename in ipairs(table.wrap(filerules)) do
|
||||
local r = target._project().rule(rulename) or rule.rule(rulename)
|
||||
local r = target._project().rule(rulename) or rule.rule(rulename) or self:rule(rulename)
|
||||
if r then
|
||||
table.insert(rules, r)
|
||||
end
|
||||
|
|
|
@ -148,6 +148,16 @@ function sandbox_utils.assert(value, format, ...)
|
|||
return value
|
||||
end
|
||||
|
||||
-- generate c/c++ code from the binary file
|
||||
if utils._bin2c then
|
||||
function sandbox_utils.bin2c(binaryfile, outputfile, opt)
|
||||
local ok, errors = utils.bin2c(binaryfile, outputfile, opt)
|
||||
if not ok then
|
||||
os.raise(errors)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- return module
|
||||
return sandbox_utils
|
||||
|
||||
|
|
|
@ -756,6 +756,12 @@ function _preprocess(program, argv, opt)
|
|||
table.insert(flags, "-fdirectives-only")
|
||||
end
|
||||
|
||||
-- suppress -Wgnu-line-marker warnings
|
||||
-- @see https://github.com/xmake-io/xmake/issues/5737
|
||||
if is_gcc or is_clang then
|
||||
table.insert(flags, "-Wno-gnu-line-marker")
|
||||
end
|
||||
|
||||
-- do preprocess
|
||||
local cppinfo = try {function ()
|
||||
if is_host("windows") then
|
||||
|
|
|
@ -156,6 +156,7 @@ function main(name, opt)
|
|||
else
|
||||
libfiles_native_host = os.files(path.join(librarydir_host, "*.so"))
|
||||
end
|
||||
local libraries_set = {}
|
||||
for _, libraryfile in ipairs(table.join(libfiles or {}, libfiles_native or {}, libfiles_native_host)) do
|
||||
local filename = path.filename(libraryfile)
|
||||
local libraryname = filename:split('-', {plain = true})[1]
|
||||
|
@ -163,11 +164,12 @@ function main(name, opt)
|
|||
if not libraryname:startswith("lib") then
|
||||
libraryname = "lib" .. libraryname
|
||||
end
|
||||
if names:has(libraryname) then
|
||||
if names:has(libraryname) and not libraries_set[libraryname] then
|
||||
frameworkdirs = frameworkdirs or {}
|
||||
frameworks = frameworks or {}
|
||||
table.insert(frameworkdirs, path.directory(libraryfile))
|
||||
table.insert(frameworks, libraryfile)
|
||||
libraries_set[libraryname] = true
|
||||
end
|
||||
end
|
||||
local result
|
||||
|
|
|
@ -20,17 +20,15 @@
|
|||
|
||||
-- imports
|
||||
import("core.base.semver")
|
||||
import("core.package.package", {alias = "core_package"})
|
||||
import("private.action.require.impl.repository")
|
||||
import("private.xrepo.quick_search.cache")
|
||||
|
||||
function _search_package(packages, name, opt)
|
||||
for _, packageinfo in ipairs(cache.find(name, {description = opt.description ~= false})) do
|
||||
local packagename = packageinfo.name
|
||||
local packagedata = packageinfo.data
|
||||
|
||||
-- search package from name
|
||||
function _search_package_from_name(packages, name, opt)
|
||||
for _, packageinfo in ipairs(repository.searchdirs(name)) do
|
||||
local package = core_package.load_from_repository(packageinfo.name, packageinfo.packagedir, {repo = packageinfo.repo})
|
||||
if package then
|
||||
local repo = package:repo()
|
||||
local version
|
||||
local versions = package:versions()
|
||||
local versions = packageinfo.versions
|
||||
if versions then
|
||||
versions = table.copy(versions)
|
||||
table.sort(versions, function (a, b) return semver.compare(a, b) > 0 end)
|
||||
|
@ -44,45 +42,16 @@ function _search_package_from_name(packages, name, opt)
|
|||
version = versions[1]
|
||||
end
|
||||
end
|
||||
if not opt.require_version or version then
|
||||
packages[package:name()] = {name = package:name(), version = version, description = package:get("description"), reponame = repo and repo:name()}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- search package from description
|
||||
function _search_package_from_description(packages, name, opt)
|
||||
for _, packageinfo in ipairs(repository.searchdirs("*")) do
|
||||
if not packages[packageinfo.name] then
|
||||
local package = core_package.load_from_repository(packageinfo.name, packageinfo.packagedir, {repo = packageinfo.repo})
|
||||
if package then
|
||||
local description = package:description()
|
||||
if description and description:find(string.ipattern(name)) then
|
||||
local repo = package:repo()
|
||||
local version
|
||||
local versions = package:versions()
|
||||
if versions then
|
||||
versions = table.copy(versions)
|
||||
table.sort(versions, function (a, b) return semver.compare(a, b) > 0 end)
|
||||
if opt.require_version then
|
||||
for _, ver in ipairs(versions) do
|
||||
if semver.satisfies(ver, opt.require_version) then
|
||||
version = ver
|
||||
end
|
||||
end
|
||||
else
|
||||
version = versions[1]
|
||||
end
|
||||
end
|
||||
local description = packagedata.description
|
||||
if description then
|
||||
description = description:gsub(string.ipattern(name), function (w)
|
||||
return "${bright}" .. w .. "${clear}"
|
||||
end)
|
||||
end
|
||||
|
||||
if not opt.require_version or version then
|
||||
packages[package:name()] = {name = package:name(), version = version, description = description, reponame = repo and repo:name()}
|
||||
end
|
||||
end
|
||||
end
|
||||
packages[packagename] = {name = packagename, version = version, description = description, reponame = packagedata.reponame}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -95,10 +64,7 @@ end
|
|||
function main(name, opt)
|
||||
opt = opt or {}
|
||||
local packages = {}
|
||||
_search_package_from_name(packages, name, opt)
|
||||
if opt.description ~= false then
|
||||
_search_package_from_description(packages, name, opt)
|
||||
end
|
||||
_search_package(packages, name, opt)
|
||||
|
||||
local results = {}
|
||||
for name, info in table.orderpairs(packages) do
|
||||
|
|
|
@ -1158,7 +1158,11 @@ function _get_cmake_generator(package, opt)
|
|||
opt = opt or {}
|
||||
local cmake_generator = opt.cmake_generator
|
||||
if not cmake_generator then
|
||||
if project.policy("package.cmake_generator.ninja") or package:policy("package.cmake_generator.ninja") then
|
||||
local use_ninja = package:policy("package.cmake_generator.ninja")
|
||||
if use_ninja == nil then
|
||||
use_ninja = project.policy("package.cmake_generator.ninja")
|
||||
end
|
||||
if use_ninja then
|
||||
cmake_generator = "Ninja"
|
||||
end
|
||||
if not cmake_generator then
|
||||
|
|
|
@ -32,11 +32,6 @@ import("private.action.require.impl.install_packages")
|
|||
--
|
||||
function enter()
|
||||
|
||||
-- unzip or 7zip is necessary
|
||||
if not is_host("windows") and not find_tool("unzip") and not find_tool("7z") then
|
||||
raise("failed to find unzip or 7zip! please install one of them first")
|
||||
end
|
||||
|
||||
-- enter the environments of git
|
||||
_g._OLDENVS = packagenv.enter("git")
|
||||
|
||||
|
|
|
@ -85,6 +85,11 @@ end
|
|||
--
|
||||
-- {build = true}: always build packages, we do not use the precompiled artifacts
|
||||
--
|
||||
-- simply configs as string:
|
||||
-- add_requires("boost[iostreams,system,thread,key=value] >=1.78.0")
|
||||
-- add_requires("boost[iostreams,thread=n] >=1.78.0")
|
||||
-- add_requires("libplist[shared,debug,codecs=[foo,bar,zoo]]")
|
||||
--
|
||||
function _parse_require(require_str)
|
||||
|
||||
-- split package and version info
|
||||
|
@ -144,6 +149,38 @@ function _load_require(require_str, requires_extra, parentinfo)
|
|||
require_extra = requires_extra[require_str] or {}
|
||||
end
|
||||
|
||||
-- parse configs from package name, and we need to ignore 3rd package name, e.g. vcpkg::boost[core], ...
|
||||
-- @see https://github.com/xmake-io/xmake/issues/5727#issuecomment-2421040107
|
||||
--
|
||||
-- e.g.
|
||||
-- add_requires("boost[iostreams,system,thread,key=value] >=1.78.0")
|
||||
-- add_requires("libplist[shared,debug,codecs=[foo,bar,zoo]]")
|
||||
--
|
||||
local packagename_raw, configs_str = packagename:match("(.-)%[(.*)%]")
|
||||
if packagename_raw and configs_str and not packagename:find("::", 1, true) then
|
||||
configs_str = configs_str:gsub("%[(.*)%]", function (w)
|
||||
return w:replace(",", ":")
|
||||
end)
|
||||
packagename = packagename_raw
|
||||
local splitinfo = configs_str:split(",", {plain = true})
|
||||
for _, v in ipairs(splitinfo) do
|
||||
local parts = v:split("=", {plain = true})
|
||||
local k = parts[1]
|
||||
v = parts[2]
|
||||
require_extra.configs = require_extra.configs or {}
|
||||
local configs = require_extra.configs
|
||||
if v then
|
||||
if v:find(":", 1 ,true) then
|
||||
configs[k] = v:split(":", {plain = true})
|
||||
else
|
||||
configs[k] = option.boolean(v)
|
||||
end
|
||||
else
|
||||
configs[k] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- get required building configurations
|
||||
-- we need to clone a new configs object, because the whole requireinfo will be modified later.
|
||||
-- @see https://github.com/xmake-io/xmake-repo/pull/2067
|
||||
|
|
|
@ -220,25 +220,3 @@ function artifacts_manifest(packagename, version)
|
|||
end
|
||||
end
|
||||
|
||||
-- search package directories from repositories
|
||||
function searchdirs(name)
|
||||
|
||||
-- find the package directories from all repositories
|
||||
local unique = {}
|
||||
local packageinfos = {}
|
||||
for _, repo in ipairs(repositories()) do
|
||||
for _, file in ipairs(os.files(path.join(repo:directory(), "packages", "*", string.ipattern("*" .. name .. "*"), "xmake.lua"))) do
|
||||
local dir = path.directory(file)
|
||||
local subdirname = path.basename(path.directory(dir))
|
||||
if #subdirname == 1 then -- ignore l/luajit/port/xmake.lua
|
||||
local packagename = path.filename(dir)
|
||||
if not unique[packagename] then
|
||||
table.insert(packageinfos, {name = packagename, repo = repo, packagedir = path.directory(file)})
|
||||
unique[packagename] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return packageinfos
|
||||
end
|
||||
|
||||
|
|
|
@ -81,8 +81,8 @@ function _add_target_files(sourcefiles, target)
|
|||
end
|
||||
end
|
||||
|
||||
-- check sourcefile
|
||||
function _check_sourcefile(clang_tidy, sourcefile, opt)
|
||||
-- check sourcefiles
|
||||
function _check_sourcefiles(clang_tidy, sourcefiles, opt)
|
||||
opt = opt or {}
|
||||
local projectdir = project.directory()
|
||||
local argv = {}
|
||||
|
@ -108,10 +108,12 @@ function _check_sourcefile(clang_tidy, sourcefile, opt)
|
|||
if opt.quiet then
|
||||
table.insert(argv, "--quiet")
|
||||
end
|
||||
for _, sourcefile in ipairs(sourcefiles) do
|
||||
if not path.is_absolute(sourcefile) then
|
||||
sourcefile = path.absolute(sourcefile, projectdir)
|
||||
end
|
||||
table.insert(argv, sourcefile)
|
||||
end
|
||||
os.execv(clang_tidy, argv, {curdir = projectdir})
|
||||
end
|
||||
|
||||
|
@ -164,15 +166,7 @@ function _check(clang_tidy, opt)
|
|||
end
|
||||
|
||||
-- check files
|
||||
local jobs = tonumber(opt.jobs or "1")
|
||||
runjobs("check_files", function (index)
|
||||
local sourcefile = sourcefiles[index]
|
||||
if sourcefile then
|
||||
_check_sourcefile(clang_tidy, sourcefile, opt)
|
||||
end
|
||||
end, {total = #sourcefiles,
|
||||
comax = jobs,
|
||||
isolate = true})
|
||||
_check_sourcefiles(clang_tidy, sourcefiles, opt)
|
||||
end
|
||||
|
||||
function main(argv)
|
||||
|
|
|
@ -35,7 +35,7 @@ function _do_dump(binarydata, outputfile, opt)
|
|||
local p = 0
|
||||
local e = binarydata:size()
|
||||
local line = nil
|
||||
local linewidth = opt.linewidth or 0x20
|
||||
local linewidth = opt.linewidth or 32
|
||||
local first = true
|
||||
while p < e do
|
||||
line = ""
|
||||
|
@ -81,7 +81,26 @@ function _do_bin2c(binarypath, outputpath, opt)
|
|||
-- trace
|
||||
print("generating code data file from %s ..", binarypath)
|
||||
|
||||
-- optimize the default linewidth for reading large file
|
||||
if not opt.linewidth then
|
||||
local filesize = os.filesize(binarypath)
|
||||
if filesize > 1024 * 1024 * 1024 then
|
||||
opt.linewidth = 512
|
||||
elseif filesize > 100 * 1024 * 1024 then
|
||||
opt.linewidth = 256
|
||||
elseif filesize > 10 * 1024 * 1024 then
|
||||
opt.linewidth = 128
|
||||
elseif filesize > 1024 * 1024 then
|
||||
opt.linewidth = 64
|
||||
else
|
||||
opt.linewidth = 32
|
||||
end
|
||||
end
|
||||
|
||||
-- do dump
|
||||
if utils.bin2c then
|
||||
utils.bin2c(binarypath, outputpath, opt)
|
||||
else
|
||||
local binarydata = bytes(io.readfile(binarypath, {encoding = "binary"}))
|
||||
local outputfile = io.open(outputpath, 'w')
|
||||
if outputfile then
|
||||
|
@ -91,12 +110,12 @@ function _do_bin2c(binarypath, outputpath, opt)
|
|||
_do_dump(binarydata, outputfile, opt)
|
||||
outputfile:close()
|
||||
end
|
||||
end
|
||||
|
||||
-- trace
|
||||
cprint("${bright}%s generated!", outputpath)
|
||||
end
|
||||
|
||||
-- main entry
|
||||
function main(...)
|
||||
|
||||
-- parse arguments
|
||||
|
|
|
@ -37,7 +37,7 @@ function _list_package_dirs()
|
|||
if #subdirname == 1 then -- ignore l/luajit/port/xmake.lua
|
||||
local packagename = path.filename(dir)
|
||||
if not unique[packagename] then
|
||||
table.insert(packageinfos, {name = packagename, repo = repo, packagedir = path.directory(file)})
|
||||
table.insert(packageinfos, {name = packagename, repo = repo, packagedir = dir})
|
||||
unique[packagename] = true
|
||||
end
|
||||
end
|
||||
|
@ -58,6 +58,7 @@ function update()
|
|||
for _, packageinfo in ipairs(_list_package_dirs()) do
|
||||
local package = core_package.load_from_repository(packageinfo.name, packageinfo.packagedir, {repo = packageinfo.repo})
|
||||
cache:set(packageinfo.name, {
|
||||
reponame = package:repo() and package:repo():name(),
|
||||
description = package:description(),
|
||||
versions = package:versions(),
|
||||
})
|
||||
|
@ -77,13 +78,25 @@ function get()
|
|||
return cache:data()
|
||||
end
|
||||
|
||||
function find(name)
|
||||
-- find package
|
||||
function find(name, opt)
|
||||
_init()
|
||||
opt = opt or {}
|
||||
local list_result = {}
|
||||
for packagename, packagedata in pairs(cache:data()) do
|
||||
if packagename:startswith(name) then
|
||||
local found = false
|
||||
if opt.prefix then
|
||||
found = packagename:startswith(name)
|
||||
else
|
||||
found = packagename:find(name)
|
||||
end
|
||||
if not found and opt.description and packagedata.description and packagedata.description:find(name) then
|
||||
found = true
|
||||
end
|
||||
if found then
|
||||
table.insert(list_result, {name = packagename, data = packagedata})
|
||||
end
|
||||
end
|
||||
return list_result
|
||||
end
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ import("private.xrepo.quick_search.cache")
|
|||
-- complete xrepo packages
|
||||
function _xmake_package_complete(complete, opt)
|
||||
local candidates = {}
|
||||
local found = cache.find(complete)
|
||||
local found = cache.find(complete, {prefix = true})
|
||||
for _, candidate in ipairs(found) do
|
||||
table.insert(candidates, {value = candidate.name, description = candidate.data.description})
|
||||
end
|
||||
|
|
|
@ -43,7 +43,7 @@ function _get_builtinvars(target, installdir)
|
|||
TARGETFILENAME = target:targetfile() and _get_libfile(target, installdir),
|
||||
TARGETKIND = target:is_headeronly() and "INTERFACE" or (target:is_shared() and "SHARED" or "STATIC"),
|
||||
PACKAGE_VERSION = target:get("version") or "1.0.0",
|
||||
TARGET_PTRBYTES = target:is_arch("x86", "i386") and "4" or "8"}
|
||||
TARGET_PTRBYTES = target:is_arch("armeabi", "armeabi-v7a", "x86", "mips", "i386", "armv7", "armv7s", "mipsel", "wasm32") and "4" or "8"}
|
||||
end
|
||||
|
||||
-- install cmake config file
|
||||
|
@ -130,6 +130,16 @@ function _install_cmake_targetfile(target, installdir, filename, opt)
|
|||
local value = builtinvars[variable]
|
||||
return type(value) == "function" and value() or value
|
||||
end)
|
||||
local libfile = path.filename(target:targetfile())
|
||||
local postfix = is_mode("debug") and "DEBUG" or "RELEASE"
|
||||
if target:is_shared() and (_get_libfile(target, installdir) ~= libfile) then
|
||||
-- On DLL platforms, the import library is named differently from the target file
|
||||
content = content:gsub("# IMPORTED_IMPLIB_" .. postfix, "IMPORTED_IMPLIB_" .. postfix)
|
||||
content = content:gsub(
|
||||
"IMPORTED_LOCATION_" .. postfix .. " \"%${_IMPORT_PREFIX}/lib/.-\"",
|
||||
"IMPORTED_LOCATION_" .. postfix .. " \"${_IMPORT_PREFIX}/bin/" .. libfile .. "\""
|
||||
)
|
||||
end
|
||||
io.writefile(importfile_dst, content)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -48,7 +48,7 @@ function _escape_path(filepath)
|
|||
return filepath
|
||||
end
|
||||
|
||||
-- tranlate path
|
||||
-- translate path
|
||||
function _translate_path(filepath, outputdir)
|
||||
filepath = path.translate(filepath)
|
||||
if filepath == "" then
|
||||
|
@ -182,6 +182,14 @@ function _add_rules_for_compiler_windres(ninjafile, sourcekind, program)
|
|||
ninjafile:print("")
|
||||
end
|
||||
|
||||
-- add rules for complier (cuda/nvcc)
|
||||
function _add_rules_for_compiler_nvcc(ninjafile, sourcekind, program)
|
||||
ninjafile:print("rule %s", sourcekind)
|
||||
ninjafile:print(" command = %s -c $ARGS $in -o $out", program)
|
||||
ninjafile:print(" description = compiling.%s $in", config.mode())
|
||||
ninjafile:print("")
|
||||
end
|
||||
|
||||
-- add rules for complier
|
||||
function _add_rules_for_compiler(ninjafile)
|
||||
ninjafile:print("# rules for compiler")
|
||||
|
@ -203,7 +211,8 @@ function _add_rules_for_compiler(ninjafile)
|
|||
ml = _add_rules_for_compiler_msvc_ml,
|
||||
ml64 = _add_rules_for_compiler_msvc_ml,
|
||||
rc = _add_rules_for_compiler_msvc_rc,
|
||||
windres = _add_rules_for_compiler_windres
|
||||
windres = _add_rules_for_compiler_windres,
|
||||
nvcc = _add_rules_for_compiler_nvcc
|
||||
}
|
||||
for sourcekind, _ in pairs(language.sourcekinds()) do
|
||||
local program, toolname = platform.tool(sourcekind)
|
||||
|
|
|
@ -36,16 +36,15 @@ function _add_build_sanitizer(target, sourcekind, checkmode)
|
|||
mxx = "mxflags"
|
||||
}
|
||||
local flagname = flagnames[sourcekind]
|
||||
if flagname and target:has_tool(sourcekind, "cl", "clang", "clangxx", "gcc", "gxx") then
|
||||
target:add(flagname, "-fsanitize=" .. checkmode)
|
||||
if flagname and target:has_tool(sourcekind, "cl", "clang", "clangxx", "clang_cl", "gcc", "gxx") then
|
||||
target:add(flagname, "-fsanitize=" .. checkmode, {force = true})
|
||||
end
|
||||
|
||||
-- add ldflags and shflags
|
||||
if target:has_tool("ld", "link", "clang", "clangxx", "gcc", "gxx") then
|
||||
target:add("ldflags", "-fsanitize=" .. checkmode)
|
||||
target:add("shflags", "-fsanitize=" .. checkmode)
|
||||
target:add("ldflags", "-fsanitize=" .. checkmode, {force = true})
|
||||
target:add("shflags", "-fsanitize=" .. checkmode, {force = true})
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function main(target, sourcekind)
|
||||
|
@ -71,6 +70,17 @@ function main(target, sourcekind)
|
|||
-- we need to load runenvs for msvc
|
||||
-- @see https://github.com/xmake-io/xmake/issues/4176
|
||||
if target:is_plat("windows") and target:is_binary() then
|
||||
if target:has_tool("cxx", "clang_cl") then
|
||||
local clang_cl = target:toolchain("clang-cl")
|
||||
if clang_cl then
|
||||
local envs = clang_cl:runenvs()
|
||||
local vscmd_ver = envs and envs.VSCMD_VER
|
||||
if vscmd_ver and semver.match(vscmd_ver):ge("17.7") then
|
||||
local clang_cl_tool = assert(find_tool("clang-cl", {envs = envs}), "clang-cl not found!")
|
||||
target:add("runenvs", "PATH", path.directory(clang_cl_tool.program))
|
||||
end
|
||||
end
|
||||
else
|
||||
local msvc = target:toolchain("msvc")
|
||||
if msvc then
|
||||
local envs = msvc:runenvs()
|
||||
|
@ -82,4 +92,6 @@ function main(target, sourcekind)
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -300,7 +300,7 @@ function get_stdmodules(target)
|
|||
end
|
||||
end
|
||||
end
|
||||
wprint("std and std.compat modules not found ! disabling them for the build, maybe try to add --sdk=<PATH/TO/LLVM>")
|
||||
wprint("std and std.compat modules not found! maybe try to add --sdk=<PATH/TO/LLVM> or install libc++")
|
||||
end
|
||||
|
||||
function get_bmi_extension()
|
||||
|
|
|
@ -29,8 +29,13 @@ import("private.tools.ccache")
|
|||
-- get linux-headers sdk
|
||||
function _get_linux_headers_sdk(target)
|
||||
local linux_headersdir = target:values("linux.driver.linux-headers")
|
||||
local linux_builddir = target:values("linux.driver.linux-builddir")
|
||||
if linux_headersdir then
|
||||
return {sdkdir = linux_headersdir, includedir = path.join(linux_headersdir, "include")}
|
||||
return {
|
||||
sdkdir = linux_headersdir,
|
||||
builddir = linux_builddir,
|
||||
includedir = path.join(linux_headersdir, "include")
|
||||
}
|
||||
end
|
||||
local linux_headers = assert(target:pkg("linux-headers"), "please add `add_requires(\"linux-headers\", {configs = {driver_modules = true}})` and `add_packages(\"linux-headers\")` to the given target!")
|
||||
local includedirs = linux_headers:get("includedirs") or linux_headers:get("sysincludedirs")
|
||||
|
@ -52,7 +57,7 @@ function _get_linux_headers_sdk(target)
|
|||
end
|
||||
|
||||
-- get cflags from make
|
||||
function _get_cflags_from_make(target, sdkdir)
|
||||
function _get_cflags_from_make(target, sdkdir, builddir)
|
||||
local key = sdkdir .. target:arch()
|
||||
local cflags = memcache.get2("linux.driver", key, "cflags")
|
||||
local ldflags_o = memcache.get2("linux.driver", key, "ldflags_o")
|
||||
|
@ -75,12 +80,12 @@ MODULE_AUTHOR("Ruki");
|
|||
MODULE_DESCRIPTION("A simple Hello World Module");
|
||||
MODULE_ALIAS("a simplest module");
|
||||
|
||||
int hello_init(void) {
|
||||
static int hello_init(void) {
|
||||
printk(KERN_INFO "Hello World\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void hello_exit(void) {
|
||||
static void hello_exit(void) {
|
||||
printk(KERN_INFO "Goodbye World\n");
|
||||
}
|
||||
|
||||
|
@ -88,6 +93,9 @@ module_init(hello_init);
|
|||
module_exit(hello_exit);
|
||||
]])
|
||||
local argv = {"-C", sdkdir, "V=1", "M=" .. tmpdir, "modules"}
|
||||
if builddir then
|
||||
table.insert(argv, "O=" .. builddir)
|
||||
end
|
||||
if not target:is_plat(os.subhost()) then
|
||||
-- e.g. $(MAKE) -C $(KERN_DIR) V=1 ARCH=arm64 CROSS_COMPILE=/mnt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu- M=$(PWD) modules
|
||||
local arch
|
||||
|
@ -139,7 +147,7 @@ module_exit(hello_exit);
|
|||
includedir = cflag:sub(3)
|
||||
end
|
||||
if not path.is_absolute(includedir) then
|
||||
includedir = path.absolute(includedir, sdkdir)
|
||||
includedir = path.absolute(includedir, builddir or sdkdir)
|
||||
end
|
||||
if cflag:startswith("-I") then
|
||||
cflag = "-I" .. includedir
|
||||
|
@ -161,7 +169,7 @@ module_exit(hello_exit);
|
|||
for _, ldflag in ipairs(os.argv(ldflags)) do
|
||||
if ldflag:endswith(".lds") then
|
||||
if not path.is_absolute(ldflag) then
|
||||
ldflag = path.absolute(ldflag, sdkdir)
|
||||
ldflag = path.absolute(ldflag, builddir or sdkdir)
|
||||
end
|
||||
end
|
||||
if ko then
|
||||
|
@ -224,7 +232,7 @@ function config(target)
|
|||
for _, sourcefile in ipairs(target:sourcefiles()) do
|
||||
target:fileconfig_set(sourcefile, {defines = "KBUILD_BASENAME=\"" .. path.basename(sourcefile) .. "\""})
|
||||
end
|
||||
local cflags, ldflags_o, ldflags_ko = _get_cflags_from_make(target, linux_headers.sdkdir)
|
||||
local cflags, ldflags_o, ldflags_ko = _get_cflags_from_make(target, linux_headers.sdkdir, linux_headers.builddir)
|
||||
if cflags then
|
||||
target:add("cflags", cflags, {force = true})
|
||||
target:data_set("linux.driver.ldflags_o", ldflags_o)
|
||||
|
@ -245,7 +253,7 @@ function link(target, opt)
|
|||
local modpost
|
||||
local linux_headers = target:data("linux.driver.linux_headers")
|
||||
if linux_headers then
|
||||
modpost = path.join(linux_headers.sdkdir, "scripts", "mod", "modpost")
|
||||
modpost = path.join(linux_headers.builddir or linux_headers.sdkdir, "scripts", "mod", "modpost")
|
||||
end
|
||||
assert(modpost and os.isfile(modpost), "scripts/mod/modpost not found!")
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ set(CMAKE_IMPORT_FILE_VERSION 1)
|
|||
set_property(TARGET @PROJECTNAME@::@TARGETNAME@ APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
|
||||
set_target_properties(@PROJECTNAME@::@TARGETNAME@ PROPERTIES
|
||||
IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "ASM_NASM;C"
|
||||
# IMPORTED_IMPLIB_DEBUG "${_IMPORT_PREFIX}/lib/@TARGETFILENAME@"
|
||||
IMPORTED_LOCATION_DEBUG "${_IMPORT_PREFIX}/lib/@TARGETFILENAME@"
|
||||
)
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ set(CMAKE_IMPORT_FILE_VERSION 1)
|
|||
set_property(TARGET @PROJECTNAME@::@TARGETNAME@ APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
|
||||
set_target_properties(@PROJECTNAME@::@TARGETNAME@ PROPERTIES
|
||||
IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "ASM_NASM;C"
|
||||
# IMPORTED_IMPLIB_RELEASE "${_IMPORT_PREFIX}/lib/@TARGETFILENAME@"
|
||||
IMPORTED_LOCATION_RELEASE "${_IMPORT_PREFIX}/lib/@TARGETFILENAME@"
|
||||
)
|
||||
|
||||
|
|
|
@ -20,12 +20,9 @@
|
|||
|
||||
-- define toolchain
|
||||
toolchain("zig")
|
||||
|
||||
-- set homepage
|
||||
set_homepage("https://ziglang.org/")
|
||||
set_description("Zig Programming Language Compiler")
|
||||
|
||||
-- on check
|
||||
on_check(function (toolchain)
|
||||
import("lib.detect.find_tool")
|
||||
local paths = {}
|
||||
|
@ -36,25 +33,29 @@ toolchain("zig")
|
|||
end
|
||||
end
|
||||
local zig = get_config("zc")
|
||||
local zig_version
|
||||
if not zig then
|
||||
zig = find_tool("zig", {force = true, paths = paths})
|
||||
zig = find_tool("zig", {force = true, version = true, paths = paths})
|
||||
if zig and zig.program then
|
||||
zig_version = zig.version
|
||||
zig = zig.program
|
||||
end
|
||||
end
|
||||
if zig then
|
||||
toolchain:config_set("zig", zig)
|
||||
toolchain:config_set("zig_version", zig_version)
|
||||
toolchain:configs_save()
|
||||
return true
|
||||
end
|
||||
end)
|
||||
|
||||
-- on load
|
||||
on_load(function (toolchain)
|
||||
import("core.base.semver")
|
||||
|
||||
-- set toolset
|
||||
-- we patch target to `zig cc` to fix has_flags. see https://github.com/xmake-io/xmake/issues/955#issuecomment-766929692
|
||||
local zig = toolchain:config("zig") or "zig"
|
||||
local zig_version = toolchain:config("zig_version")
|
||||
if toolchain:config("zigcc") ~= false then
|
||||
-- we can use `set_toolchains("zig", {zigcc = false})` to disable zigcc
|
||||
-- @see https://github.com/xmake-io/xmake/issues/3251
|
||||
|
@ -75,7 +76,11 @@ toolchain("zig")
|
|||
elseif toolchain:is_arch("arm", "armv7") then
|
||||
arch = "arm"
|
||||
elseif toolchain:is_arch("i386", "x86") then
|
||||
if zig_version and semver.compare(zig_version, "0.11") >= 0 then
|
||||
arch = "x86"
|
||||
else
|
||||
arch = "i386"
|
||||
end
|
||||
elseif toolchain:is_arch("riscv64") then
|
||||
arch = "riscv64"
|
||||
elseif toolchain:is_arch("loong64") then
|
||||
|
|
Loading…
Reference in New Issue