Skip to content

add xuantie toolchain #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
- aarch64
- arm
- riscv64gc
- xuantie

steps:
- name: ⬇️ checkout
Expand All @@ -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
Expand Down Expand Up @@ -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
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
27 changes: 23 additions & 4 deletions apps/xmake.lua
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion repo/packages/f/ffmpeg/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
57 changes: 57 additions & 0 deletions repo/packages/x/xuantie-900-gcc-musl/xmake.lua
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
File renamed without changes.
Binary file added sdk/lib/risc-v/rv64gc/lp64d/libcxx.a
Binary file not shown.
Binary file added sdk/lib/risc-v/rv64gc/lp64d/libcxx.so
Binary file not shown.
Binary file not shown.
Binary file not shown.
6 changes: 4 additions & 2 deletions tools/scripts/modules/rt/private/build/rtflags.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
61 changes: 51 additions & 10 deletions tools/scripts/tasks/smart-rootfs/on_run.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -216,15 +250,22 @@ 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

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)
Expand Down
47 changes: 47 additions & 0 deletions tools/scripts/toolchains/xuantie-900-gcc-musl.lua
Original file line number Diff line number Diff line change
@@ -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()
3 changes: 2 additions & 1 deletion tools/scripts/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down