diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6c3cf2a..ddc8f0b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -36,6 +36,7 @@ jobs: - aarch64 - arm - riscv64gc + - xuantie steps: - name: ⬇️ checkout @@ -44,7 +45,11 @@ jobs: submodules: true - name: ⬇️ install xmake - uses: xmake-io/github-action-setup-xmake@v1 + shell: bash + run: | + wget -q https://github.com/xmake-io/xmake/releases/download/v2.8.7/xmake-v2.8.7.gz.run + sudo chmod 777 ./xmake-v2.8.7.gz.run + ./xmake-v2.8.7.gz.run - name: 👷 build shell: bash @@ -85,7 +90,8 @@ jobs: export XMAKE_ROOT=y # Only need to use "--root" in CI xmake --version source env.sh - pushd apps/${{ matrix.app }} + pushd apps + echo "includes(path.join(path.join(os.scriptdir(), \"${{ matrix.app }}\"), \"xmake.lua\"))" > xmake.lua xmake f -a x86_64 --target_os=linux -vyD xmake -j$(nproc) -vyD -P . popd diff --git a/README.md b/README.md index 0b301e6..85d6b37 100644 --- a/README.md +++ b/README.md @@ -55,8 +55,10 @@ xmake 是一个基于 Lua 的轻量级跨平台构建工具,使用 xmake.lua xmake f -a aarch64 # 配置为 aarch64平台,如果不执行该条指令进行配置,则默认为 aarch64 xmake -j$(nproc) ``` - - 目前支持的平台:arm、aarch64、riscv64gc。 +> 如果使用其他平台,只需修改上述的配置命令,然后再执行编译命令,这里以xuantie平台为例: +> `xmake f -a xuantie` +> 目前支持的平台:arm、aarch64、riscv64gc、xuantie。 +> 注:目前xuantie平台只验证了busybox ![image-20230531173059551](./assets/image-20230531173059551.png) diff --git a/apps/xmake.lua b/apps/xmake.lua index 45627af..ef44d15 100644 --- a/apps/xmake.lua +++ b/apps/xmake.lua @@ -1,6 +1,25 @@ -for _, packagedir in ipairs(os.dirs(path.join(os.scriptdir(), "*"))) do - local packagefile = path.join(packagedir, "xmake.lua") - if os.isfile(packagefile) then - includes(packagefile) +local arch = get_config("arch") +if arch == "xuantie" then + local run_apps = { + "busybox", + "cpp", + "hello", + "shm_ping", + "shm_pong", + "smart-fetch", + "zlib", + } + for _, packagedir in ipairs(run_apps) do + local packagefile = path.join(path.join(os.scriptdir(), packagedir), "xmake.lua") + if os.isfile(packagefile) then + includes(packagefile) + end + end +else + for _, packagedir in ipairs(os.dirs(path.join(os.scriptdir(), "*"))) do + local packagefile = path.join(packagedir, "xmake.lua") + if os.isfile(packagefile) then + includes(packagefile) + end end end diff --git a/repo/packages/f/ffmpeg/xmake.lua b/repo/packages/f/ffmpeg/xmake.lua index c2c685f..a7bc1c6 100644 --- a/repo/packages/f/ffmpeg/xmake.lua +++ b/repo/packages/f/ffmpeg/xmake.lua @@ -66,7 +66,7 @@ do if package:config("shared") then table.insert(configs, "--enable-shared") end - + table.insert(configs, "--disable-doc") local buildenvs = import("package.tools.autoconf").buildenvs(package, {ldflags = ldflags, packagedeps = packagedeps}) import("package.tools.autoconf").configure(package, configs, {envs = buildenvs}) diff --git a/repo/packages/x/xuantie-900-gcc-musl/xmake.lua b/repo/packages/x/xuantie-900-gcc-musl/xmake.lua new file mode 100644 index 0000000..264f2b7 --- /dev/null +++ b/repo/packages/x/xuantie-900-gcc-musl/xmake.lua @@ -0,0 +1,57 @@ +-- 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) 2023-2023 RT-Thread Development Team +-- +-- @author xqyjlj +-- @file xmake.lua +-- +-- Change Logs: +-- Date Author Notes +-- ------------ ---------- ----------------------------------------------- +-- 2023-05-12 xqyjlj initial version +-- +package("xuantie-900-gcc-musl") +do + set_kind("toolchain") + set_homepage("https://www.xrvm.cn/") + set_description("riscv64 xuantie embedded compiler for rt-smart.") + + local version = os.getenv("RT_XMAKE_TOOLCHAIN_XUANTIE_VERSION") + local sha256 = os.getenv("RT_XMAKE_TOOLCHAIN_XUANTIE_SHA256") + + if is_host("linux") then + add_urls( + "https://github.com/RT-Thread/toolchains-ci/releases/download/v1.9/Xuantie-900-gcc-linux-6.6.0-musl64-x86_64-V$(version).tar.gz") + + if (version and sha256) then + add_versions(version, sha256) + else + add_versions("3.0.2", "26b338747a10cc32c8b83f340ce1980b786e7a0445380a70544867b6ed10199b") + end + end + + on_install("@windows", "@linux|x86_64", function(package) + os.vcp("*", package:installdir(), {rootdir = ".", symlink = true}) + package:addenv("PATH", "bin") + end) + + on_test(function(package) + local gcc = "riscv64-unknown-linux-musl-gcc" + if is_host("windows") then + gcc = gcc .. ".exe" + end + local file = os.tmpfile() .. ".c" + io.writefile(file, "int main(int argc, char** argv) {return 0;}") + os.vrunv(gcc, {"-c", file}) + end) +end diff --git a/sdk/lib/risc-v/rv64gc/libcxx.a b/sdk/lib/risc-v/rv64gc/lp64/libcxx.a similarity index 100% rename from sdk/lib/risc-v/rv64gc/libcxx.a rename to sdk/lib/risc-v/rv64gc/lp64/libcxx.a diff --git a/sdk/lib/risc-v/rv64gc/libcxx.so b/sdk/lib/risc-v/rv64gc/lp64/libcxx.so similarity index 100% rename from sdk/lib/risc-v/rv64gc/libcxx.so rename to sdk/lib/risc-v/rv64gc/lp64/libcxx.so diff --git a/sdk/lib/risc-v/rv64gc/lp64d/libcxx.a b/sdk/lib/risc-v/rv64gc/lp64d/libcxx.a new file mode 100644 index 0000000..610a56b Binary files /dev/null and b/sdk/lib/risc-v/rv64gc/lp64d/libcxx.a differ diff --git a/sdk/lib/risc-v/rv64gc/lp64d/libcxx.so b/sdk/lib/risc-v/rv64gc/lp64d/libcxx.so new file mode 100755 index 0000000..f9b524f Binary files /dev/null and b/sdk/lib/risc-v/rv64gc/lp64d/libcxx.so differ diff --git a/sdk/rt-thread/lib/risc-v/rv64gc/librtthread.a b/sdk/rt-thread/lib/risc-v/rv64gc/lp64/librtthread.a similarity index 100% rename from sdk/rt-thread/lib/risc-v/rv64gc/librtthread.a rename to sdk/rt-thread/lib/risc-v/rv64gc/lp64/librtthread.a diff --git a/sdk/rt-thread/lib/risc-v/rv64gc/librtthread.so b/sdk/rt-thread/lib/risc-v/rv64gc/lp64/librtthread.so similarity index 100% rename from sdk/rt-thread/lib/risc-v/rv64gc/librtthread.so rename to sdk/rt-thread/lib/risc-v/rv64gc/lp64/librtthread.so diff --git a/sdk/rt-thread/lib/risc-v/rv64gc/lp64d/librtthread.a b/sdk/rt-thread/lib/risc-v/rv64gc/lp64d/librtthread.a new file mode 100644 index 0000000..ec09139 Binary files /dev/null and b/sdk/rt-thread/lib/risc-v/rv64gc/lp64d/librtthread.a differ diff --git a/sdk/rt-thread/lib/risc-v/rv64gc/lp64d/librtthread.so b/sdk/rt-thread/lib/risc-v/rv64gc/lp64d/librtthread.so new file mode 100755 index 0000000..4571e3c Binary files /dev/null and b/sdk/rt-thread/lib/risc-v/rv64gc/lp64d/librtthread.so differ diff --git a/tools/scripts/modules/rt/private/build/rtflags.lua b/tools/scripts/modules/rt/private/build/rtflags.lua index b16bb9e..df9f12d 100644 --- a/tools/scripts/modules/rt/private/build/rtflags.lua +++ b/tools/scripts/modules/rt/private/build/rtflags.lua @@ -69,9 +69,11 @@ function get_sdk() elseif arch == "aarch64" then arch = "aarch64/cortex-a" elseif arch == "riscv64gc" then - arch = "risc-v/rv64gc" + arch = "risc-v/rv64gc/lp64" elseif arch == "riscv64gcv" then - arch = "risc-v/rv64gcv" + arch = "risc-v/rv64gcv/lp64" + elseif arch == "xuantie" then + arch = "risc-v/rv64gc/lp64d" end table.insert(cxflags, "-DHAVE_CCONFIG_H") diff --git a/tools/scripts/tasks/smart-rootfs/on_run.lua b/tools/scripts/tasks/smart-rootfs/on_run.lua index 45305f3..0f88030 100644 --- a/tools/scripts/tasks/smart-rootfs/on_run.lua +++ b/tools/scripts/tasks/smart-rootfs/on_run.lua @@ -133,16 +133,9 @@ function deploy_target(rootfs) end end -function deploy_syslib(toolchains, rootfs) +function deploy_syslib(rootfs) local sdkdir = rt_utils.sdk_dir() local arch = config.arch() - local pkg = project:required_packages()[toolchains] - - if string.startswith(toolchains, "riscv64") then - toolchains = "riscv64-unknown-smart-musl" - end - - toolchains = string.gsub(toolchains, "smart", "linux") -- TODO: should replace, when toolchains renamed if arch == "arm64" then arch = "aarch64" @@ -152,6 +145,12 @@ function deploy_syslib(toolchains, rootfs) arch = "arm/cortex-a" elseif arch == "aarch64" then arch = "aarch64/cortex-a" + elseif arch == "riscv64gc" then + arch = "risc-v/rv64gc/lp64" + elseif arch == "riscv64gcv" then + arch = "risc-v/rv64gcv/lp64" + elseif arch == "xuantie" then + arch = "risc-v/rv64gc/lp64d" end local rtlibdir = path.join(sdkdir, "rt-thread", "lib", arch) @@ -164,6 +163,16 @@ function deploy_syslib(toolchains, rootfs) local filename = path.filename(filepath) rt_utils.cp_with_symlink(filepath, path.join(rootfs, "lib", filename)) end +end + +function deploy_toolchainlib(toolchains, rootfs) + local pkg = project:required_packages()[toolchains] + + if string.startswith(toolchains, "riscv64") then + toolchains = "riscv64-unknown-smart-musl" + end + + toolchains = string.gsub(toolchains, "smart", "linux") -- TODO: should replace, when toolchains renamed for _, filepath in ipairs(os.files(path.join(pkg:installdir(), toolchains) .. "/*/lib*.so*")) do if path.extension(filepath) ~= ".py" then @@ -178,6 +187,31 @@ function deploy_syslib(toolchains, rootfs) end end +function deploy_xuantietoolchainlib(toolchains, rootfs) + local pkg = project:required_packages()[toolchains] + local path_root = "sysroot" + local lib_path = { + "usr/lib64/lp64d", + "lib64/lp64d", + } + + for _, filepath_lib in ipairs(lib_path) do + for _, filepath in ipairs(os.files(path.join(pkg:installdir(), path_root, filepath_lib) .. "/lib*.so*")) do + if path.extension(filepath) ~= ".py" then + local filename = path.filename(filepath) + os.tryrm(path.join(rootfs, "lib", filename)) + os.vcp(filepath, path.join(rootfs, "lib", filename)) + end + end + end + + for _, filepath in ipairs(os.files(path.join(pkg:installdir(), path_root) .. "/*/ld-musl-*.so.*")) do + local filename = path.filename(filepath) + os.tryrm(path.join(rootfs, "lib", filename)) + os.vcp(filepath, path.join(rootfs, "lib", filename)) + end +end + function copy_packages() local name = option.get("export") if name == "all" then @@ -216,7 +250,7 @@ function main() local target = project.targets()[targetname] local toolchains = string.gsub(target:get("toolchains"), "@", "") local rootfs = option.get("output") or rt_utils.rootfs_dir() - + local arch = config.arch() if (option.get("no-symlink")) then os.setenv("--rt-xmake-no-symlink", "true") end @@ -224,7 +258,14 @@ function main() create_rootfs(rootfs) deploy_package(rootfs) deploy_target(rootfs) - deploy_syslib(toolchains, rootfs) + deploy_syslib(rootfs) + + if arch == "xuantie" then + deploy_xuantietoolchainlib(toolchains, rootfs) + else + deploy_toolchainlib(toolchains, rootfs) + end + local size = rt_utils.dirsize(rootfs) cprint("${green}> rootfs: %s", rootfs) diff --git a/tools/scripts/toolchains/xuantie-900-gcc-musl.lua b/tools/scripts/toolchains/xuantie-900-gcc-musl.lua new file mode 100644 index 0000000..05bdad6 --- /dev/null +++ b/tools/scripts/toolchains/xuantie-900-gcc-musl.lua @@ -0,0 +1,47 @@ +-- 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) 2022-2023 RT-Thread Development Team +-- +-- @author xqyjlj +-- @file riscv64gc-unknown-smart-musl.lua +-- +-- Change Logs: +-- Date Author Notes +-- ------------ ---------- ----------------------------------------------- +-- 2023-03-08 xqyjlj initial version +-- +set_xmakever("2.7.2") + +toolchain("xuantie-900-gcc-musl") -- add toolchain +do + set_kind("cross") -- set toolchain kind + set_description("riscv64 xuantie embedded compiler for rt-smart") + on_load(function(toolchain) + import("rt.private.build.rtflags") + toolchain:load_cross_toolchain() + + toolchain:set("toolset", "cxx", "riscv64-unknown-linux-musl-g++") + + toolchain:add("cxflags", "-mcmodel=medany", "-march=rv64imafdc", "-mabi=lp64d ", "-Wno-return-mismatch", {force = true}) + + local link_type = os.getenv("RT_XMAKE_LINK_TYPE") or "shared" + if link_type == "static" then + local ldscript = rtflags.get_ldscripts(false) + toolchain:add("ldflags", ldscript.ldflags, {force = true}) + else + local ldscript = rtflags.get_ldscripts(true) + toolchain:add("ldflags", ldscript.ldflags, {force = true}) + end + end) +end +toolchain_end() diff --git a/tools/scripts/xmake.lua b/tools/scripts/xmake.lua index f1f2e2d..c8f7885 100644 --- a/tools/scripts/xmake.lua +++ b/tools/scripts/xmake.lua @@ -52,7 +52,8 @@ end local archs = { aarch64 = "aarch64-smart-musleabi", arm = "arm-smart-musleabi", - riscv64gc = "riscv64gc-unknown-smart-musl" + riscv64gc = "riscv64gc-unknown-smart-musl", + xuantie = "xuantie-900-gcc-musl" } if not get_config("target_os") then