Skip to content
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

无法构建no_std的rust项目 #4929

Closed
Yangff opened this issue Apr 3, 2024 · 48 comments
Closed

无法构建no_std的rust项目 #4929

Yangff opened this issue Apr 3, 2024 · 48 comments
Labels
Milestone

Comments

@Yangff
Copy link

Yangff commented Apr 3, 2024

Xmake 版本

xmake v2.8.9+20240321

操作系统版本和架构

linux 6.7.3

描述问题

我试图在一个C+rust的项目里使用no_std/nostdlib(可以先忽略C的这部分) 进行编译。
rust项目在独自的rsystem目录下,有自己的xmake.lua。
我使用add_requires("cargo::rsystem", {...}) 为它添加 std = false, main = false 并使用toml管理它的cargo依赖。
这个库应该被编译为静态库并可以被c链接。

遇到的问题首先 rsystem 这个目标似乎会被编译成可执行文件,xmake为它生成的Cargo.toml并不会包含[lib] ,并且xmake会为它会生成一个main.rs(里面似乎还包含一些panic handler之类的东西,但这不应该是我自己添加吗?)而不是lib.rs进行编译。

其次,xmake无法正确安装编译产物,在提示 copy /home/dell/Projects/test-proj/build/.packages/c/cargo_rsystem/latest/cache/source/target/x86_64-unknown-none/release/deps to /home/dell/Projects/test-proj/build/.packages/c/cargo_rsystem/latest/934c937479bb4bedb432f28382ca4aaa/lib 之后,复制并没有成功,在目标路径并不存在,尽管源文件的路径确实存在。

仔细看了一下,在installdir.failed/lib 里面是有这些文件的

/home/dell/Projects/test-proj/build/.packages/c/cargo_rsystem/latest/cache/source/target/x86_64-unknown-none/release/deps
├── liblock_api-70c54cea3a452b9f.rlib
├── liblock_api-70c54cea3a452b9f.rmeta
├── libscopeguard-3d0ca9c8812a4568.rlib
├── libscopeguard-3d0ca9c8812a4568.rmeta
├── libspin-96d84987d673a355.rlib
├── libspin-96d84987d673a355.rmeta
├── libtalc-67643e2a36d56baa.rlib
├── libtalc-67643e2a36d56baa.rmeta
├── lock_api-70c54cea3a452b9f.d
├── rsystem-d84e228a06a48752
├── rsystem-d84e228a06a48752.d
├── scopeguard-3d0ca9c8812a4568.d
├── spin-96d84987d673a355.d
└── talc-67643e2a36d56baa.d

ls /home/dell/Projects/test-proj/build/.packages/c/cargo_rsystem/latest/934c937479bb4bedb432f28382ca4aaa/lib
ls: cannot access '/home/dell/Projects/test-proj/build/.packages/c/cargo_rsystem/latest/934c937479bb4bedb432f28382ca4aaa/lib': No such file or 

ls /home/dell/Projects/test-proj/build/.packages/c/cargo_rsystem/latest/
cache

另外有一个疑问是,我预期的行为是整个项目被cargo原封不动地进行编译,然后和项目的其他部分进行链接,但是似乎xmake会创建一个额外的cargo项目然后只包含我add_files("src/lib.rs")添加的lib.rs

期待的结果

编译得到一个static library并可以被添加为其它c项目的依赖项(这里没有使用 bindgen,因为我打算手写头文件)

工程配置

rsystem
├── Cargo.lock
├── Cargo.toml
├── src
│   ├── alloc.rs
│   ├── extlib.rs
│   └── lib.rs
└── xmake.lua

rsystem/xmake.lua

add_requires("cargo::rsystem", {
    configs = {
        std = false,
        main = false,
        cargo_toml = path.join(os.projectdir(), "rsystem", "Cargo.toml"),
    }
})

target("rsystem")
    set_kind("static")
    add_files("src/lib.rs")
    set_values("rust.cratetype", "staticlib")
    add_packages("cargo::rsystem")

其中cargo.toml的内容为

[package]
name = "rsystem"
version = "0.1.0"
edition = "2021"

[dependencies]
talc = "4.3.1"
spin = "0.9.8"

根目录的xmake.lua

add_rules("mode.debug", "mode.release")
set_arch("x86_64-unknown-none")
set_languages("clatest", "cxx20")
includes("rsystem")
target("test")
    set_kind("shared")
    add_files("src/*.c")
    add_deps("rsystem")

lib.rs

#![no_main]
#![no_std]
mod alloc;

// 后面是导出C的一些函数

alloc.rs

use talc::*;

static mut ARENA: [u8; 10000] = [0; 10000];

#[global_allocator]
static ALLOCATOR: Talck<spin::Mutex<()>, ClaimOnOom> = Talc::new(unsafe {
    ClaimOnOom::new(Span::from_const_array(core::ptr::addr_of!(ARENA)))
}).lock();

附加信息和错误日志

error: .../modules/private/action/require/impl/actions/install.lua:398: fetch cargo::rsystem-latest failed!
stack traceback:
    [C]: in function 'error'
    [@programdir/core/base/os.lua:957]: in function 'raiselevel'
    [@programdir/core/sandbox/modules/utils.lua:143]: in function 'assert'
    [.../modules/private/action/require/impl/actions/install.lua:398]:

  => install cargo::rsystem latest .. failed

.../modules/private/action/require/impl/actions/install.lua:398: fetch cargo::rsystem-latest failed!
stack traceback:
    [C]: in function 'error'
    [@programdir/core/base/os.lua:957]: in function 'raiselevel'
    [@programdir/core/sandbox/modules/utils.lua:143]: in function 'assert'
    [.../modules/private/action/require/impl/actions/install.lua:398]:
if you want to get more verbose errors, please see:
  -> /home/dell/Projects/test-proj/build/.packages/c/cargo_rsystem/latest/cache/installdir.failed/logs/install.txt
error: @programdir/core/main.lua:329: @programdir/core/sandbox/modules/import/core/base/task.lua:65: @programdir/modules/async/runjobs.lua:338: .../modules/private/action/require/impl/actions/install.lua:474: install failed!
stack traceback:
    [C]: in function 'error'
    [@programdir/core/base/os.lua:957]:
    [.../modules/private/action/require/impl/actions/install.lua:474]: in function 'catch'
    [@programdir/core/sandbox/modules/try.lua:123]: in function 'try'
    [.../modules/private/action/require/impl/actions/install.lua:333]:
    [...modules/private/action/require/impl/install_packages.lua:487]: in function 'jobfunc'
    [@programdir/modules/async/runjobs.lua:256]:

stack traceback:
        [C]: in function 'error'
        @programdir/core/base/os.lua:957: in function 'os.raiselevel'
        (...tail calls...)
        @programdir/core/main.lua:329: in upvalue 'cotask'
        @programdir/core/base/scheduler.lua:406: in function <@programdir/core/base/scheduler.lua:399>

另外单独安装cargo package也是失败的
例如:

add_requires("cargo::talc 4.3.1", {
    configs = {
        std = false,
        main = false,
    }
})
add_requires("cargo::spin 4.3.1", {
    configs = {
        std = false,
        main = false,
    }
})

target("rsystem")
    set_kind("static")
    add_files("src/lib.rs")
    set_values("rust.cratetype", "staticlib")
    add_packages("cargo::talc", "cargo::spin")

错误是一样的,都是拷贝之后提示error: .../modules/private/action/require/impl/actions/install.lua:398:

@Yangff Yangff added the bug label Apr 3, 2024
@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Title: Unable to build no_std rust project

@Yangff
Copy link
Author

Yangff commented Apr 3, 2024

实际上的话会有两个问题,如果我使用 x86_64-unknown-linux-gnu 作为target,然后在cargo.toml里面加

[profile.release]
panic = "abort"

因为xmake会使用main.rs编译可执行文件,因为找不到 __libc_start_main的符号而失败,尽管在这里就不应该有 __libc_start_main.

然后,如果试图用 x86_64-unknown-none 作为target,在package.lua里面fetch package的时候会因为

    else

        print(system)
        print(self:is_thirdparty())
        print(self:is_cross())
        print(self:plat(), self:arch())
        -- only fetch it from the xmake repository first
        if not fetchinfo and system ~= true and not self:is_thirdparty() then
            fetchinfo = self:_fetch_library({require_version = self:version_str(), external = external, force = opt.force})
            if fetchinfo then
                is_system = self._is_system
            end
        end

        -- fetch it from the system and external package sources (disabled for cross-compilation)
        if not fetchinfo and system ~= false and not self:is_cross() then
            fetchinfo = self:_fetch_library({system = true, require_version = require_ver, external = external, force = opt.force})
            if fetchinfo then
                is_system = true
            end
        end

    end

这里is_cross()会为真,但是这个是cargo的源而不是xmake的package manager所以两个分支都不会执行。

@Yangff
Copy link
Author

Yangff commented Apr 3, 2024

去掉 is_cross() 的话,在编译实际的rust代码的时候,似乎不会带上arch,导致cargo和rustc使用不同的arch tuple。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


If is_cross() is removed, it seems that arch will not be included when compiling the actual rust code, causing cargo and rustc to use different arch tuples.

@waruqi
Copy link
Member

waruqi commented Apr 3, 2024

等节后我看下,最近忙不过来

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


I'll check it out after the holidays, I've been too busy lately

@mentalonigiri
Copy link

I had similar problems with fetch *** failed, and I can tell now it was github server side problem. It is not xmake bug. It is github, probably their web server, drops git clone connection randomly. A little weird workaround is to use git over ssh. You have to create git script somewhere and prepend it to your PATH. Script is here:

#!/bin/bash

cmd=("$@") # Copy original arguments into an array
for i in "${!cmd[@]}"; do
if [[ "${cmd[$i]}" =~ ^https://github.com ]]; then
    cmd[$i]=${cmd[$i]//https:\/\/github.com/ssh:\/\/git@github.com}
fi
done
/bin/git "${cmd[@]}" # Execute the git command with the possibly modified arguments

Basically it changes https://github* to ssh://git@github* . That way your git clone connection is authorized by your ssh key (dont forget to setup ssh key for your github account!). And those weird connection drops stop happening for me.

@waruqi
Copy link
Member

waruqi commented May 24, 2024

遇到的问题首先 rsystem 这个目标似乎会被编译成可执行文件,xmake为它生成的Cargo.toml并不会包含[lib] ,并且xmake会为它会生成一个main.rs(里面似乎还包含一些panic handler之类的东西,但这不应该是我自己添加吗?)而不是lib.rs进行编译。

这个只是个空 wrapper ,仅仅只是为了借助 cargo 拉取到对应的依赖库,而这个编译生成的二进制产物 不会去使用。

其次,xmake无法正确安装编译产物,在提示 copy /home/dell/Projects/test-proj/build/.packages/c/cargo_rsystem/latest/cache/source/target/x86_64-unknown-none/release/deps to /home/dell/Projects/test-proj/build/.packages/c/cargo_rsystem/latest/934c937479bb4bedb432f28382ca4aaa/lib 之后,复制并没有成功,在目标路径并不存在,尽管源文件的路径确实存在。

能否给个完整的 project demo ,我调试下

另外有一个疑问是,我预期的行为是整个项目被cargo原封不动地进行编译,然后和项目的其他部分进行链接,但是似乎xmake会创建一个额外的cargo项目然后只包含我add_files("src/lib.rs")添加的lib.rs?

xmake 里 rust 项目不是用 cargo 编译的,是 xmake 自己直接调用 rustc 编译的。。调用 cargo 仅仅只是为了拉依赖库

如果都直接调用 cargo 去编译项目了,那就没 xmake 啥事了,你直接用 cargo 去编译就完事了,没必要去用 xmake

或者可以看下这个 https://docs.rs/xmake/latest/xmake/,在 cargo 里调用 xmake

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Problems encountered: First, the rsystem target seems to be compiled into an executable file. The Cargo.toml generated by xmake does not contain [lib], and xmake generates a main.rs for it (which seems to also contain Some panic handler stuff, but shouldn't that be something I add myself?) instead of lib.rs for compilation.

This is just an empty wrapper, just to use cargo to pull the corresponding dependent library, and the binary product generated by this compilation will not be used.

Secondly, xmake cannot correctly install the compiled product and prompts copy /home/dell/Projects/test-proj/build/.packages/c/cargo_rsystem/latest/cache/source/target/x86_64-unknown-none/release/deps to /home/dell/Projects/test-proj/build/.packages/c/cargo_rsystem/latest/934c937479bb4bedb432f28382ca4aaa/lib, the copy does not succeed, the destination path does not exist, although the path to the source file does exist.

Can you give me a complete project demo so I can debug it?

Another question is that the expected behavior is that the entire project is compiled intact by cargo and then linked with other parts of the project, but it seems that xmake will create an additional cargo project and then only include my add_files("src /lib.rs") added lib.rs?

The rust project in xmake is not compiled with cargo, but is compiled by xmake itself directly calling rustc. . Calling cargo is just to pull dependent libraries

If you call cargo directly to compile the project, then there is no need for xmake. You can just use cargo to compile it. There is no need to use xmake.

Or you can take a look at this https://docs.rs/xmake/latest/xmake/ and call xmake in cargo

@Yangff
Copy link
Author

Yangff commented May 24, 2024

能否给个完整的 project demo ,我调试下

我又想了一下应该是编译出来了,x86_64-unknown-none的主要问题可能是x86_64-unknown-none和x86_64-linux-gnu会被xmake认为是两个架构没法链接在一起,等我去看的时候他已经把东西删了。所以就算强行install了之后编译rust项目的时候用的tuple还是错的。

https://github.com/Yangff/xmake_rust_no_std

但是,如果去掉 set_arch,xmake在编译提取依赖的空项目的时候会失败,会提示

  = note: /usr/sbin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../lib/Scrt1.o: in function `_start':
          (.text+0x1b): undefined reference to `main'
          /usr/sbin/ld: (.text+0x21): undefined reference to `__libc_start_main'
          collect2: error: ld returned 1 exit status

不知道为什么他会尝试链接main,明明我设置了 main = false,

https://github.com/Yangff/xmake_rust_no_std/tree/linux-no-std

@Yangff
Copy link
Author

Yangff commented May 24, 2024

没必要去用 xmake

rust那边我可以生成正常的.a,主要是为了c/c++那边可以把它链接上,类似cmake那边corrosion的用法。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


No need to use xmake

I can generate normal .a on the rust side, mainly so that the c/c++ side can link it, similar to the usage of corrosion on the cmake side.

@waruqi
Copy link
Member

waruqi commented May 26, 2024

这边试了下,似乎编译 talc 就报错了,是我这 ructc 版本太低了?

warning: `lock_api` (lib) generated 1 warning
error[E0554]: `#![feature]` may not be used on the stable release channel
  --> /Users/ruki/.cargo/registry/src/index.crates.io-6f17d22bba15001f/talc-4.4.1/src/lib.rs:12
:44
   |
12 | #![cfg_attr(feature = "allocator", feature(allocator_api))]
   |                                            ^^^^^^^^^^^^^

error[E0554]: `#![feature]` may not be used on the stable release channel
  --> /Users/ruki/.cargo/registry/src/index.crates.io-6f17d22bba15001f/talc-4.4.1/src/lib.rs:13
:46
   |
13 | #![cfg_attr(feature = "nightly_api", feature(slice_ptr_len))]
   |                                              ^^^^^^^^^^^^^

error[E0554]: `#![feature]` may not be used on the stable release channel
  --> /Users/ruki/.cargo/registry/src/index.crates.io-6f17d22bba15001f/talc-4.4.1/src/lib.rs:14
:46
   |
14 | #![cfg_attr(feature = "nightly_api", feature(const_slice_ptr_len))]
   |                                              ^^^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0554`.
error: could not compile `talc` (lib) due to 3 previous errors

xmake 在提取 dep 时候会自动生成一个 stub 项目。你可以直接把这个 project 搬出来,看看执行 cargo build 能否编译过。。

cd ./build//.packages/c/cargo_rsystem/latest/cache/source/
cargo build -vv
$ cat ./Cargo.toml
[package]
name = "rsystem"
version = "0.1.0"
edition = "2021"

[dependencies]
talc = "4.3.1"
spin = "0.9.8"
[workspace]
$ tree .
.
├── Cargo.lock
├── Cargo.toml
├── src
│   └── main.rs

@Yangff
Copy link
Author

Yangff commented May 26, 2024

是我这 ructc 版本太低了

应该是,allocator api还是nightly。你可以
在features 里把 "allocator" and "nightly_api" 关掉或者把这些代码都删了随便塞个什么东西给allocator…… 因为用不用这个包不重要,我只是从我自己的项目里复制了一下。
……不过删了还是有点麻烦,建议还是直接nightly吧

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


My ructc version is too low

It should be, allocator api or nightly. you can
Turn off "allocator" and "nightly_api" in features or delete all these codes... Because it doesn't matter whether you use this package or not, I just copied it from my own project.

@Yangff
Copy link
Author

Yangff commented May 26, 2024

可能要把

#[panic_handler]
#[cfg(not(test))]
fn panic(_info: &core::panic::PanicInfo) -> ! {
    loop {}
}

// rust_eh_personality
#[no_mangle]
#[cfg(not(test))]
extern fn rust_eh_personality() {}

这个加上

@Yangff
Copy link
Author

Yangff commented May 26, 2024

不过就算不加,用了nightly的话我这里也可以进到这一步
linux-no-std:

xmake f
note: install or modify (m) these packages (pass -y to skip confirm)?
in cargo:
  -> cargo::rsystem latest [main:n, std:n, cargo_toml:"/home/yangff/Project/xmake_rust_no_std/rsystem/Cargo.toml"]
please input: y (y/n/m)
y
  => install cargo::rsystem latest .. failed

    Updating crates.io index
   Compiling autocfg v1.3.0
   Compiling scopeguard v1.2.0
   Compiling lock_api v0.4.12
   Compiling spin v0.9.8
   Compiling talc v4.4.1
   Compiling rsystem v0.1.0 (/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source)
error: linking with `cc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/yangff/.cargo/bin:/home/yangff/.local/bin:/home/yangff/.vscode-server-insiders/bin/fd518e4db7bcf89d7e19bf29522786d0cd16a9a6/bin/remote-cli:/home/yangff/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/Program Files/7-Zip/:/mnt/c/Program Files/OpenSSH/:/mnt/c/Windows/system32:/mnt/c/Windows:/mnt/c/Windows/System32/Wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0/:/mnt/c/Windows/System32/OpenSSH/:/mnt/c/Program Files/dotnet/:/mnt/c/Program Files (x86)/Windows Kits/10/Windows Performance Toolkit/:/mnt/c/Program Files/Git/cmd:/mnt/c/Program Files (x86)/GnuPG/bin:/mnt/c/Program Files/ojdkbuild/java-11-openjdk-11.0.15-1/bin:/mnt/c/Program Files/usbipd-win/:/mnt/c/Program Files/Tailscale/:/mnt/c/Program Files/CMake/bin:/mnt/c/Program Files/PowerShell/7/:/mnt/c/Users/yangf/.cargo/bin:/mnt/c/Users/yangf/AppData/Local/Programs/Python/Python311/Scripts/:/mnt/c/Users/yangf/AppData/Local/Programs/Python/Python311/:/mnt/c/Users/yangf/AppData/Local/Programs/Python/Launcher/:/mnt/c/Users/yangf/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/yangf/AppData/Local/Programs/Microsoft VS Code Insiders/bin:/mnt/c/Users/yangf/.dotnet/tools:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/usr/lib/rustup/bin" VSLANG="1033" "cc" "-m64" "/tmp/rustcoYXGXC/symbols.o" "/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/deps/rsystem-e866488660525c89.rsystem.b5cea79d2011d969-cgu.0.rcgu.o" "-Wl,--as-needed" "-L" "/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/deps" "-L" "/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-9686387289eaa322.rlib" "/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-632ae0f28c5e55ff.rlib" "/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-3166674eacfcf914.rlib" "-Wl,-Bdynamic" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/deps/rsystem-e866488660525c89" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-Wl,-O1" "-Wl,--strip-debug" "-nodefaultlibs"
  = note: /usr/sbin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/14.1.1/../../../../lib/Scrt1.o: in function `_start':
          (.text+0x1b): undefined reference to `main'
          /usr/sbin/ld: (.text+0x21): undefined reference to `__libc_start_main'
          collect2: error: ld returned 1 exit status
          
  = note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
if you want to get more verbose errors, please see:
  -> /home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/installdir.failed/logs/install.txt
error: install failed!
warning: the arch "x86_64" is NOT a valid target triple, will be IGNORED and may cause compilation errors, please check it again
warning: add -v for getting more warnings ..

master (这里因为我改了install的逻辑):

Switched to branch 'master'
Your branch is up to date with 'origin/master'.
❯ xmake f
❯ xmake
[ 57%]: cache compiling.release src/main.c
[ 57%]: linking.release librsystem.a
error: error[E0461]: couldn't find crate `talc` with expected target triple x86_64-unknown-linux-gnu
 --> rsystem/src/lib.rs:4:5
  |
4 | use talc::*;
  |     ^^^^
  |
  = note: the following crate versions were found:
          crate `talc`, target triple x86_64-unknown-none: /home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/3b3b216f73ab4cf18b281eb62ffd4dc9/lib/libtalc-cbdfd3e84a1fc0b1.rlib

error[E0461]: couldn't find crate `spin` with expected target triple x86_64-unknown-linux-gnu
 --> rsystem/src/lib.rs:9:25
  |
9 | static ALLOCATOR: Talck<spin::Mutex<()>, ClaimOnOom> = Talc::new(unsafe {
  |                         ^^^^
  |
  = note: the following crate versions were found:
          crate `spin`, target triple x86_64-unknown-none: /home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/3b3b216f73ab4cf18b281eb62ffd4dc9/lib/libspin-8c4e5bc78fa6842c.rlib

error[E0412]: cannot find type `Talck` in this scope
 --> rsystem/src/lib.rs:9:19
  |
9 | static ALLOCATOR: Talck<spin::Mutex<()>, ClaimOnOom> = Talc::new(unsafe {
  |                   ^^^^^ not found in this scope

error[E0412]: cannot find type `ClaimOnOom` in this scope
 --> rsystem/src/lib.rs:9:42
  |
9 | static ALLOCATOR: Talck<spin::Mutex<()>, ClaimOnOom> = Talc::new(unsafe {
  |                                          ^^^^^^^^^^ not found in this scope

error: `#[panic_handler]` function required, but not found

error: unwinding panics are not supported without std
  |
  = help: using nightly cargo, use -Zbuild-std with panic="abort" to avoid unwinding
  = note: since the core library is usually precompiled with panic="unwind", rebuilding your crate with panic="abort" may not be enough to fix the problem

error[E0433]: failed to resolve: use of undeclared type `Talc`
 --> rsystem/src/lib.rs:9:56
  |
9 | static ALLOCATOR: Talck<spin::Mutex<()>, ClaimOnOom> = Talc::new(unsafe {
  |                                                        ^^^^ use of undeclared type `Talc`

error[E0433]: failed to resolve: use of undeclared type `ClaimOnOom`
  --> rsystem/src/lib.rs:10:5
   |
10 |     ClaimOnOom::new(Span::from_const_array(core::ptr::addr_of!(ARENA)))
   |     ^^^^^^^^^^ use of undeclared type `ClaimOnOom`

error[E0433]: failed to resolve: use of undeclared type `Span`
  --> rsystem/src/lib.rs:10:21
   |
10 |     ClaimOnOom::new(Span::from_const_array(core::ptr::addr_of!(ARENA)))
   |                     ^^^^ use of undeclared type `Span`

error: aborting due to 9 previous errors

Some errors have detailed explanations: E0412, E0433, E0461.
For more information about an error, try `rustc --explain E0412`.

@waruqi
Copy link
Member

waruqi commented May 28, 2024

我更新到 nightly 并且用了你那个 main demo,报了其他错误,直接 cargo build 时候

$ rustc --version
rustc 1.80.0-nightly (84b40fc90 2024-05-27)
$ cargo --version
cargo 1.80.0-nightly (a8d72c675 2024-05-24)
$ cargo build -vv
error[E0152]: found duplicate lang item `panic_impl`
 --> src/main.rs:3:1
  |
3 | / fn panic(_info: &core::panic::PanicInfo) -> ! {
4 | |     loop {}
5 | | }
  | |_^
  |
  = note: the lang item is first defined in crate `std` (which `rsystem` depends on)
  = note: first definition in `std` loaded from /Users/ruki/.rustup/toolchains/nightly-x86_64-a
pple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libstd-376bcbded3bf48cc.dylib, /Users/ruki/.rus
tup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libstd-376bcbded
3bf48cc.rlib
  = note: second definition in the local crate (`rsystem`)

@Yangff
Copy link
Author

Yangff commented May 28, 2024

cargo build

master 分支请使用

❯ cargo build --target x86_64-unknown-none
   Compiling autocfg v1.3.0
   Compiling scopeguard v1.2.0
   Compiling lock_api v0.4.12
   Compiling spin v0.9.8
   Compiling talc v4.4.1
   Compiling rsystem v0.1.0 (/home/yangff/Project/xmake_rust_no_std/rsystem)
    Finished dev [unoptimized + debuginfo] target(s) in 1.44s

linux-no-std分支请使用:

Switched to branch 'linux-no-std'
Your branch is up to date with 'origin/linux-no-std'.
❯ cargo build
   Compiling scopeguard v1.2.0
   Compiling lock_api v0.4.12
   Compiling talc v4.4.1
   Compiling spin v0.9.8
   Compiling rsystem v0.1.0 (/home/yangff/Project/xmake_rust_no_std/rsystem)
    Finished dev [unoptimized + debuginfo] target(s) in 0.26s

@Yangff
Copy link
Author

Yangff commented May 28, 2024

master分支是演示如果将目标的arch设置成x86_64-unknown-none的情况,在xmake.lua里有
https://github.com/Yangff/xmake_rust_no_std/blob/master/xmake.lua#L2C11-L2C30

不过我不是很确定的一点是无论如何也不应该出现 the lang item is first defined in crate std , 因为lib.rs里使用了 #![no_std]..

我试了一下加不加panic函数我这里都是能编译的才对。。

❯ cargo build -vv
       Fresh autocfg v1.3.0
       Fresh scopeguard v1.2.0
       Fresh lock_api v0.4.12
       Fresh spin v0.9.8
       Fresh talc v4.4.1
       Dirty rsystem v0.1.0 (/home/yangff/Project/xmake_rust_no_std/rsystem): the file `src/lib.rs` has changed (1716895687.631892204s, 6m 7s after last build at 1716895320.811891700s)
   Compiling rsystem v0.1.0 (/home/yangff/Project/xmake_rust_no_std/rsystem)
     Running `CARGO=/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo CARGO_CRATE_NAME=rsystem CARGO_MANIFEST_DIR=/home/yangff/Project/xmake_rust_no_std/rsystem CARGO_PKG_AUTHORS='' CARGO_PKG_DESCRIPTION='' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=rsystem CARGO_PKG_README='' CARGO_PKG_REPOSITORY='' CARGO_PKG_RUST_VERSION='' CARGO_PKG_VERSION=0.1.0 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=1 CARGO_PKG_VERSION_PATCH=0 CARGO_PKG_VERSION_PRE='' CARGO_PRIMARY_PACKAGE=1 CARGO_RUSTC_CURRENT_DIR=/home/yangff/Project/xmake_rust_no_std/rsystem LD_LIBRARY_PATH='/home/yangff/Project/xmake_rust_no_std/rsystem/target/debug/deps:/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib:/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib' /home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --crate-name rsystem --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=148 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=b8e623b17977c8fe -C extra-filename=-b8e623b17977c8fe --out-dir /home/yangff/Project/xmake_rust_no_std/rsystem/target/debug/deps -C incremental=/home/yangff/Project/xmake_rust_no_std/rsystem/target/debug/incremental -L dependency=/home/yangff/Project/xmake_rust_no_std/rsystem/target/debug/deps --extern spin=/home/yangff/Project/xmake_rust_no_std/rsystem/target/debug/deps/libspin-cad3619a2508f025.rmeta --extern talc=/home/yangff/Project/xmake_rust_no_std/rsystem/target/debug/deps/libtalc-e11b9f5e18faf34d.rmeta`
    Finished dev [unoptimized + debuginfo] target(s) in 0.48s
❯ git checkout master
M       src/main.c
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
❯ cargo build -vv
       Fresh autocfg v1.3.0
       Fresh scopeguard v1.2.0
       Fresh lock_api v0.4.12
       Fresh spin v0.9.8
       Fresh talc v4.4.1
       Dirty rsystem v0.1.0 (/home/yangff/Project/xmake_rust_no_std/rsystem): the file `src/lib.rs` has changed (1716895703.361888229s, 14s after last build at 1716895689.141892029s)
   Compiling rsystem v0.1.0 (/home/yangff/Project/xmake_rust_no_std/rsystem)
     Running `CARGO=/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo CARGO_CRATE_NAME=rsystem CARGO_MANIFEST_DIR=/home/yangff/Project/xmake_rust_no_std/rsystem CARGO_PKG_AUTHORS='' CARGO_PKG_DESCRIPTION='' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=rsystem CARGO_PKG_README='' CARGO_PKG_REPOSITORY='' CARGO_PKG_RUST_VERSION='' CARGO_PKG_VERSION=0.1.0 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=1 CARGO_PKG_VERSION_PATCH=0 CARGO_PKG_VERSION_PRE='' CARGO_PRIMARY_PACKAGE=1 CARGO_RUSTC_CURRENT_DIR=/home/yangff/Project/xmake_rust_no_std/rsystem LD_LIBRARY_PATH='/home/yangff/Project/xmake_rust_no_std/rsystem/target/debug/deps:/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib:/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib' /home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --crate-name rsystem --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=148 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=b8e623b17977c8fe -C extra-filename=-b8e623b17977c8fe --out-dir /home/yangff/Project/xmake_rust_no_std/rsystem/target/debug/deps -C incremental=/home/yangff/Project/xmake_rust_no_std/rsystem/target/debug/incremental -L dependency=/home/yangff/Project/xmake_rust_no_std/rsystem/target/debug/deps --extern spin=/home/yangff/Project/xmake_rust_no_std/rsystem/target/debug/deps/libspin-cad3619a2508f025.rmeta --extern talc=/home/yangff/Project/xmake_rust_no_std/rsystem/target/debug/deps/libtalc-e11b9f5e18faf34d.rmeta`
    Finished dev [unoptimized + debuginfo] target(s) in 0.06s

@Yangff
Copy link
Author

Yangff commented May 28, 2024

而且不管怎么说我配置的也是main=false

add_requires("cargo::rsystem", {
    configs = {
        std = false,
        main = false,
        cargo_toml = path.join(os.projectdir(), "rsystem", "Cargo.toml"),
    }
})

不应该出现main吧?

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


And no matter what, I configured it with main=false

add_requires("cargo::rsystem", {
    configs = {
        std = false,
        main = false,
        cargo_toml = path.join(os.projectdir(), "rsystem", "Cargo.toml"),
    }
})

Main shouldn't appear, right?

@Yangff
Copy link
Author

Yangff commented May 28, 2024

linux-no-std分支在configure的时候失败

 xmake f -v -D
checking for gcc ... /usr/sbin/gcc
checking for zig ... /usr/sbin/zig
checkinfo: cannot runv(nim --version), No such file or directory
checking for nim ... no
checkinfo: cannot runv(nim --version), No such file or directory
checking for nim ... no
checking for unzip ... /usr/sbin/unzip
checking for git ... /usr/sbin/git
checking for gzip ... /usr/sbin/gzip
checking for tar ... /usr/sbin/tar
finding rsystem from cargo ..
checking for cargo::rsystem ... no
note: install or modify (m) these packages (pass -y to skip confirm)?
in cargo:
  -> cargo::rsystem latest [cargo_toml:"/home/yangff/Project/xmake_rust_no_std/rsystem/Cargo.toml", main:n, std:n]
please input: y (y/n/m)
y
installing rsystem from cargo ..
checking for cargo ... /usr/sbin/cargo
checking for rustc ... /usr/sbin/rustc
/usr/sbin/cargo build --release -vv
    Updating crates.io index
   Compiling autocfg v1.3.0
   Compiling scopeguard v1.2.0
     Running `CARGO=/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo CARGO_CRATE_NAME=autocfg CARGO_MANIFEST_DIR=/home/yangff/.cargo/registry/src/index.crates.io-6f17d22bba15001f/autocfg-1.3.0 CARGO_PKG_AUTHORS='Josh Stone <cuviper@gmail.com>' CARGO_PKG_DESCRIPTION='Automatic cfg for Rust compiler features' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='Apache-2.0 OR MIT' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=autocfg CARGO_PKG_README=README.md CARGO_PKG_REPOSITORY='https://github.com/cuviper/autocfg' CARGO_PKG_RUST_VERSION=1.0 CARGO_PKG_VERSION=1.3.0 CARGO_PKG_VERSION_MAJOR=1 CARGO_PKG_VERSION_MINOR=3 CARGO_PKG_VERSION_PATCH=0 CARGO_PKG_VERSION_PRE='' CARGO_RUSTC_CURRENT_DIR=/home/yangff/.cargo/registry/src/index.crates.io-6f17d22bba15001f/autocfg-1.3.0 LD_LIBRARY_PATH='/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/deps:/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib:/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib' /home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --crate-name autocfg /home/yangff/.cargo/registry/src/index.crates.io-6f17d22bba15001f/autocfg-1.3.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=148 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debug-assertions=off -C metadata=dcad2e25b06436ad -C extra-filename=-dcad2e25b06436ad --out-dir /home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/deps -C strip=debuginfo -L dependency=/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/deps --cap-lints warn`
     Running `CARGO=/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo CARGO_CRATE_NAME=scopeguard CARGO_MANIFEST_DIR=/home/yangff/.cargo/registry/src/index.crates.io-6f17d22bba15001f/scopeguard-1.2.0 CARGO_PKG_AUTHORS=bluss CARGO_PKG_DESCRIPTION='A RAII scope guard that will run a given closure when it goes out of scope,
even if the code between panics (assuming unwinding panic).

Defines the macros `defer'\!'`, `defer_on_unwind'\!'`, `defer_on_success'\!'` as
shorthands for guards with one of the implemented strategies.
' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='MIT OR Apache-2.0' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=scopeguard CARGO_PKG_README=README.md CARGO_PKG_REPOSITORY='https://github.com/bluss/scopeguard' CARGO_PKG_RUST_VERSION='' CARGO_PKG_VERSION=1.2.0 CARGO_PKG_VERSION_MAJOR=1 CARGO_PKG_VERSION_MINOR=2 CARGO_PKG_VERSION_PATCH=0 CARGO_PKG_VERSION_PRE='' CARGO_RUSTC_CURRENT_DIR=/home/yangff/.cargo/registry/src/index.crates.io-6f17d22bba15001f/scopeguard-1.2.0 LD_LIBRARY_PATH='/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/deps:/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib:/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib' /home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --crate-name scopeguard /home/yangff/.cargo/registry/src/index.crates.io-6f17d22bba15001f/scopeguard-1.2.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=148 --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C panic=abort -C embed-bitcode=no -C metadata=9583a679f0bd9953 -C extra-filename=-9583a679f0bd9953 --out-dir /home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/deps -C strip=debuginfo -L dependency=/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/deps --cap-lints warn`
   Compiling lock_api v0.4.12
     Running `CARGO=/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo CARGO_CRATE_NAME=build_script_build CARGO_MANIFEST_DIR=/home/yangff/.cargo/registry/src/index.crates.io-6f17d22bba15001f/lock_api-0.4.12 CARGO_PKG_AUTHORS='Amanieu d'\''Antras <amanieu@gmail.com>' CARGO_PKG_DESCRIPTION='Wrappers to create fully-featured Mutex and RwLock types. Compatible with no_std.' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='MIT OR Apache-2.0' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=lock_api CARGO_PKG_README='' CARGO_PKG_REPOSITORY='https://github.com/Amanieu/parking_lot' CARGO_PKG_RUST_VERSION=1.56.0 CARGO_PKG_VERSION=0.4.12 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=4 CARGO_PKG_VERSION_PATCH=12 CARGO_PKG_VERSION_PRE='' CARGO_RUSTC_CURRENT_DIR=/home/yangff/.cargo/registry/src/index.crates.io-6f17d22bba15001f/lock_api-0.4.12 LD_LIBRARY_PATH='/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/deps:/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib:/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib' /home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --crate-name build_script_build --edition=2021 /home/yangff/.cargo/registry/src/index.crates.io-6f17d22bba15001f/lock_api-0.4.12/build.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=148 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debug-assertions=off --cfg 'feature="atomic_usize"' --cfg 'feature="default"' -C metadata=393b6054428b8239 -C extra-filename=-393b6054428b8239 --out-dir /home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/build/lock_api-393b6054428b8239 -C strip=debuginfo -L dependency=/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/deps --extern autocfg=/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/deps/libautocfg-dcad2e25b06436ad.rlib --cap-lints warn`
     Running `CARGO=/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo CARGO_CFG_OVERFLOW_CHECKS='' CARGO_CFG_PANIC=unwind CARGO_CFG_RELOCATION_MODEL=pic CARGO_CFG_TARGET_ABI='' CARGO_CFG_TARGET_ARCH=x86_64 CARGO_CFG_TARGET_ENDIAN=little CARGO_CFG_TARGET_ENV=gnu CARGO_CFG_TARGET_FAMILY=unix CARGO_CFG_TARGET_FEATURE=fxsr,sse,sse2 CARGO_CFG_TARGET_HAS_ATOMIC=16,32,64,8,ptr CARGO_CFG_TARGET_HAS_ATOMIC_EQUAL_ALIGNMENT=16,32,64,8,ptr CARGO_CFG_TARGET_HAS_ATOMIC_LOAD_STORE=16,32,64,8,ptr CARGO_CFG_TARGET_OS=linux CARGO_CFG_TARGET_POINTER_WIDTH=64 CARGO_CFG_TARGET_THREAD_LOCAL='' CARGO_CFG_TARGET_VENDOR=unknown CARGO_CFG_UNIX='' CARGO_ENCODED_RUSTFLAGS='' CARGO_FEATURE_ATOMIC_USIZE=1 CARGO_FEATURE_DEFAULT=1 CARGO_MANIFEST_DIR=/home/yangff/.cargo/registry/src/index.crates.io-6f17d22bba15001f/lock_api-0.4.12 CARGO_PKG_AUTHORS='Amanieu d'\''Antras <amanieu@gmail.com>' CARGO_PKG_DESCRIPTION='Wrappers to create fully-featured Mutex and RwLock types. Compatible with no_std.' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='MIT OR Apache-2.0' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=lock_api CARGO_PKG_README='' CARGO_PKG_REPOSITORY='https://github.com/Amanieu/parking_lot' CARGO_PKG_RUST_VERSION=1.56.0 CARGO_PKG_VERSION=0.4.12 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=4 CARGO_PKG_VERSION_PATCH=12 CARGO_PKG_VERSION_PRE='' DEBUG=false HOST=x86_64-unknown-linux-gnu LD_LIBRARY_PATH='/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/deps:/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release:/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib:/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib' NUM_JOBS=16 OPT_LEVEL=3 OUT_DIR=/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/build/lock_api-080d2c25e7ac652e/out PROFILE=release RUSTC=/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc RUSTDOC=/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustdoc TARGET=x86_64-unknown-linux-gnu /home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/build/lock_api-393b6054428b8239/build-script-build`
[lock_api 0.4.12] cargo:rustc-cfg=has_const_fn_trait_bound
     Running `CARGO=/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo CARGO_CRATE_NAME=lock_api CARGO_MANIFEST_DIR=/home/yangff/.cargo/registry/src/index.crates.io-6f17d22bba15001f/lock_api-0.4.12 CARGO_PKG_AUTHORS='Amanieu d'\''Antras <amanieu@gmail.com>' CARGO_PKG_DESCRIPTION='Wrappers to create fully-featured Mutex and RwLock types. Compatible with no_std.' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='MIT OR Apache-2.0' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=lock_api CARGO_PKG_README='' CARGO_PKG_REPOSITORY='https://github.com/Amanieu/parking_lot' CARGO_PKG_RUST_VERSION=1.56.0 CARGO_PKG_VERSION=0.4.12 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=4 CARGO_PKG_VERSION_PATCH=12 CARGO_PKG_VERSION_PRE='' CARGO_RUSTC_CURRENT_DIR=/home/yangff/.cargo/registry/src/index.crates.io-6f17d22bba15001f/lock_api-0.4.12 LD_LIBRARY_PATH='/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/deps:/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib:/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib' OUT_DIR=/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/build/lock_api-080d2c25e7ac652e/out /home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --crate-name lock_api --edition=2021 /home/yangff/.cargo/registry/src/index.crates.io-6f17d22bba15001f/lock_api-0.4.12/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=148 --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C panic=abort -C embed-bitcode=no --cfg 'feature="atomic_usize"' --cfg 'feature="default"' -C metadata=a56c8eccb77c3ad4 -C extra-filename=-a56c8eccb77c3ad4 --out-dir /home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/deps -C strip=debuginfo -L dependency=/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/deps --extern scopeguard=/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/deps/libscopeguard-9583a679f0bd9953.rmeta --cap-lints warn --cfg has_const_fn_trait_bound`
warning: field `0` is never read
   --> /home/yangff/.cargo/registry/src/index.crates.io-6f17d22bba15001f/lock_api-0.4.12/src/lib.rs:103:24
    |
103 | pub struct GuardNoSend(*mut ());
    |            ----------- ^^^^^^^
    |            |
    |            field in this struct
    |
    = note: `#[warn(dead_code)]` on by default
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
    |
103 | pub struct GuardNoSend(());
    |                        ~~

   Compiling spin v0.9.8
   Compiling talc v4.4.1
     Running `CARGO=/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo CARGO_CRATE_NAME=spin CARGO_MANIFEST_DIR=/home/yangff/.cargo/registry/src/index.crates.io-6f17d22bba15001f/spin-0.9.8 CARGO_PKG_AUTHORS='Mathijs van de Nes <git@mathijs.vd-nes.nl>:John Ericson <git@JohnEricson.me>:Joshua Barretto <joshua.s.barretto@gmail.com>' CARGO_PKG_DESCRIPTION='Spin-based synchronization primitives' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE=MIT CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=spin CARGO_PKG_README=README.md CARGO_PKG_REPOSITORY='https://github.com/mvdnes/spin-rs.git' CARGO_PKG_RUST_VERSION=1.38 CARGO_PKG_VERSION=0.9.8 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=9 CARGO_PKG_VERSION_PATCH=8 CARGO_PKG_VERSION_PRE='' CARGO_RUSTC_CURRENT_DIR=/home/yangff/.cargo/registry/src/index.crates.io-6f17d22bba15001f/spin-0.9.8 LD_LIBRARY_PATH='/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/deps:/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib:/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib' /home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --crate-name spin /home/yangff/.cargo/registry/src/index.crates.io-6f17d22bba15001f/spin-0.9.8/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=148 --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C panic=abort -C embed-bitcode=no --cfg 'feature="barrier"' --cfg 'feature="default"' --cfg 'feature="lazy"' --cfg 'feature="lock_api"' --cfg 'feature="lock_api_crate"' --cfg 'feature="mutex"' --cfg 'feature="once"' --cfg 'feature="rwlock"' --cfg 'feature="spin_mutex"' -C metadata=c2bf51933e6c0668 -C extra-filename=-c2bf51933e6c0668 --out-dir /home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/deps -C strip=debuginfo -L dependency=/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/deps --extern lock_api_crate=/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/deps/liblock_api-a56c8eccb77c3ad4.rmeta --cap-lints warn`
     Running `CARGO=/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo CARGO_CRATE_NAME=talc CARGO_MANIFEST_DIR=/home/yangff/.cargo/registry/src/index.crates.io-6f17d22bba15001f/talc-4.4.1 CARGO_PKG_AUTHORS='Shaun Beautement' CARGO_PKG_DESCRIPTION='A fast and flexible allocator for no_std and WebAssembly' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE=MIT CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=talc CARGO_PKG_README=README.md CARGO_PKG_REPOSITORY='https://github.com/SFBdragon/talc' CARGO_PKG_RUST_VERSION=1.67.1 CARGO_PKG_VERSION=4.4.1 CARGO_PKG_VERSION_MAJOR=4 CARGO_PKG_VERSION_MINOR=4 CARGO_PKG_VERSION_PATCH=1 CARGO_PKG_VERSION_PRE='' CARGO_RUSTC_CURRENT_DIR=/home/yangff/.cargo/registry/src/index.crates.io-6f17d22bba15001f/talc-4.4.1 LD_LIBRARY_PATH='/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/deps:/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib:/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib' /home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --crate-name talc --edition=2021 /home/yangff/.cargo/registry/src/index.crates.io-6f17d22bba15001f/talc-4.4.1/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=148 --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C panic=abort -C embed-bitcode=no --cfg 'feature="allocator"' --cfg 'feature="default"' --cfg 'feature="lock_api"' --cfg 'feature="nightly_api"' -C metadata=0a03620f1ae6954f -C extra-filename=-0a03620f1ae6954f --out-dir /home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/deps -C strip=debuginfo -L dependency=/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/deps --extern lock_api=/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/deps/liblock_api-a56c8eccb77c3ad4.rmeta --cap-lints warn`
warning: `lock_api` (lib) generated 1 warning
   Compiling rsystem v0.1.0 (/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source)
     Running `CARGO=/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo CARGO_BIN_NAME=rsystem CARGO_CRATE_NAME=rsystem CARGO_MANIFEST_DIR=/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source CARGO_PKG_AUTHORS='' CARGO_PKG_DESCRIPTION='' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=rsystem CARGO_PKG_README='' CARGO_PKG_REPOSITORY='' CARGO_PKG_RUST_VERSION='' CARGO_PKG_VERSION=0.1.0 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=1 CARGO_PKG_VERSION_PATCH=0 CARGO_PKG_VERSION_PRE='' CARGO_PRIMARY_PACKAGE=1 CARGO_RUSTC_CURRENT_DIR=/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source LD_LIBRARY_PATH='/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/deps:/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib:/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib' /home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --crate-name rsystem --edition=2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=148 --crate-type bin --emit=dep-info,link -C opt-level=3 -C panic=abort -C embed-bitcode=no -C metadata=e866488660525c89 -C extra-filename=-e866488660525c89 --out-dir /home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/deps -C strip=debuginfo -L dependency=/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/deps --extern spin=/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/deps/libspin-c2bf51933e6c0668.rlib --extern talc=/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/deps/libtalc-0a03620f1ae6954f.rlib`
error: linking with `cc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/yangff/.cargo/bin:/home/yangff/.local/bin:/home/yangff/.vscode-server-insiders/bin/fd518e4db7bcf89d7e19bf29522786d0cd16a9a6/bin/remote-cli:/home/yangff/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/Program Files/7-Zip/:/mnt/c/Program Files/OpenSSH/:/mnt/c/Windows/system32:/mnt/c/Windows:/mnt/c/Windows/System32/Wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0/:/mnt/c/Windows/System32/OpenSSH/:/mnt/c/Program Files/dotnet/:/mnt/c/Program Files (x86)/Windows Kits/10/Windows Performance Toolkit/:/mnt/c/Program Files/Git/cmd:/mnt/c/Program Files (x86)/GnuPG/bin:/mnt/c/Program Files/ojdkbuild/java-11-openjdk-11.0.15-1/bin:/mnt/c/Program Files/usbipd-win/:/mnt/c/Program Files/Tailscale/:/mnt/c/Program Files/CMake/bin:/mnt/c/Program Files/PowerShell/7/:/mnt/c/Users/yangf/.cargo/bin:/mnt/c/Users/yangf/AppData/Local/Programs/Python/Python311/Scripts/:/mnt/c/Users/yangf/AppData/Local/Programs/Python/Python311/:/mnt/c/Users/yangf/AppData/Local/Programs/Python/Launcher/:/mnt/c/Users/yangf/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/yangf/AppData/Local/Programs/Microsoft VS Code Insiders/bin:/mnt/c/Users/yangf/.dotnet/tools:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/usr/lib/rustup/bin" VSLANG="1033" "cc" "-m64" "/tmp/rustclWyXZT/symbols.o" "/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/deps/rsystem-e866488660525c89.rsystem.b5cea79d2011d969-cgu.0.rcgu.o" "-Wl,--as-needed" "-L" "/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/deps" "-L" "/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-9686387289eaa322.rlib" "/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-632ae0f28c5e55ff.rlib" "/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-3166674eacfcf914.rlib" "-Wl,-Bdynamic" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/deps/rsystem-e866488660525c89" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-Wl,-O1" "-Wl,--strip-debug" "-nodefaultlibs"
  = note: /usr/sbin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/14.1.1/../../../../lib/Scrt1.o: in function `_start':
          (.text+0x1b): undefined reference to `main'
          /usr/sbin/ld: (.text+0x21): undefined reference to `__libc_start_main'
          collect2: error: ld returned 1 exit status
          
  = note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)

error: could not compile `rsystem` (bin "rsystem") due to 1 previous error

Caused by:
  process didn't exit successfully: `CARGO=/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo CARGO_BIN_NAME=rsystem CARGO_CRATE_NAME=rsystem CARGO_MANIFEST_DIR=/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source CARGO_PKG_AUTHORS='' CARGO_PKG_DESCRIPTION='' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=rsystem CARGO_PKG_README='' CARGO_PKG_REPOSITORY='' CARGO_PKG_RUST_VERSION='' CARGO_PKG_VERSION=0.1.0 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=1 CARGO_PKG_VERSION_PATCH=0 CARGO_PKG_VERSION_PRE='' CARGO_PRIMARY_PACKAGE=1 CARGO_RUSTC_CURRENT_DIR=/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source LD_LIBRARY_PATH='/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/deps:/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib:/home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib' /home/yangff/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --crate-name rsystem --edition=2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=148 --crate-type bin --emit=dep-info,link -C opt-level=3 -C panic=abort -C embed-bitcode=no -C metadata=e866488660525c89 -C extra-filename=-e866488660525c89 --out-dir /home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/deps -C strip=debuginfo -L dependency=/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/deps --extern spin=/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/deps/libspin-c2bf51933e6c0668.rlib --extern talc=/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/source/target/release/deps/libtalc-0a03620f1ae6954f.rlib` (exit status: 1)
error: @programdir/core/sandbox/modules/os.lua:378: execv(/usr/sbin/cargo build --release -vv) failed(101)
stack traceback:
    [C]: in function 'error'
    [@programdir/core/base/os.lua:973]:
    [@programdir/core/sandbox/modules/os.lua:378]:
    [@programdir/core/sandbox/modules/os.lua:291]: in function 'vrunv'
    [...ramdir/modules/package/manager/cargo/install_package.lua:159]:
    [@programdir/modules/package/manager/install_package.lua:111]:
    [@programdir/core/package/package.lua:2762]: in function 'script'
    [...dir/modules/private/action/require/impl/utils/filter.lua:114]: in function 'call'
    [.../modules/private/action/require/impl/actions/install.lua:379]:

  => install cargo::rsystem latest .. failed

@programdir/core/sandbox/modules/os.lua:378: execv(/usr/sbin/cargo build --release -vv) failed(101)
stack traceback:
    [C]: in function 'error'
    [@programdir/core/base/os.lua:973]:
    [@programdir/core/sandbox/modules/os.lua:378]:
    [@programdir/core/sandbox/modules/os.lua:291]: in function 'vrunv'
    [...ramdir/modules/package/manager/cargo/install_package.lua:159]:
    [@programdir/modules/package/manager/install_package.lua:111]:
    [@programdir/core/package/package.lua:2762]: in function 'script'
    [...dir/modules/private/action/require/impl/utils/filter.lua:114]: in function 'call'
    [.../modules/private/action/require/impl/actions/install.lua:379]:
if you want to get more verbose errors, please see:
  -> /home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/cache/installdir.failed/logs/install.txt
error: @programdir/core/main.lua:329: @programdir/modules/async/runjobs.lua:322: .../modules/private/action/require/impl/actions/install.lua:506: install failed!
stack traceback:
    [C]: in function 'error'
    [@programdir/core/base/os.lua:973]:
    [.../modules/private/action/require/impl/actions/install.lua:506]: in function 'catch'
    [@programdir/core/sandbox/modules/try.lua:123]: in function 'try'
    [.../modules/private/action/require/impl/actions/install.lua:370]:
    [...modules/private/action/require/impl/install_packages.lua:487]: in function 'jobfunc'
    [@programdir/modules/async/runjobs.lua:238]:

stack traceback:
        [C]: in function 'error'
        @programdir/core/base/os.lua:973: in function 'os.raiselevel'
        (...tail calls...)
        @programdir/core/main.lua:329: in upvalue 'cotask'
        @programdir/core/base/scheduler.lua:406: in function <@programdir/core/base/scheduler.lua:399>
warning: the arch "x86_64" is NOT a valid target triple, will be IGNORED and may cause compilation errors, please check it again
warning: the arch "x86_64" is NOT supported by rustc, will be IGNORED and may cause compilation errors, please check it again

master分支似乎可以正常xmake f了(不确定是不是我改了什么代码的结果),但是xmake报的错误是

❯ xmake -v -D
checking for gcc ... /usr/sbin/gcc
checking for zig ... /usr/sbin/zig
checkinfo: cannot runv(nim --version), No such file or directory
checking for nim ... no
checkinfo: cannot runv(nim --version), No such file or directory
checking for nim ... no
checking for unzip ... /usr/sbin/unzip
checking for git ... /usr/sbin/git
checking for gzip ... /usr/sbin/gzip
checking for tar ... /usr/sbin/tar
finding rsystem from cargo ..
checking for cargo::rsystem ... rsystem latest
checking for zig ... /usr/sbin/zig
checkinfo: cannot runv(nim --version), No such file or directory
checking for nim ... no
checkinfo: cannot runv(nim --version), No such file or directory
checking for nim ... no
checking for gcc ... /usr/sbin/gcc
checking for the c compiler (cc) ... gcc
checking for /usr/sbin/gcc ... ok
checking for rustc ... /usr/sbin/rustc
checking for the rust compiler (rc) ... rustc
checking for flags (-fPIC) ... ok
> gcc "-fPIC"
checking for flags (-O3) ... ok
> gcc "-O3"
checking for flags (-std=c2x) ... ok
> gcc "-std=c2x"
checking for flags (-DNDEBUG) ... ok
> gcc "-DNDEBUG"
checking for /usr/sbin/rustc ... ok
checking for flags (-C opt-level=3) ... ok
> rustc "-C" "opt-level=3"
[ 57%]: linking.release librsystem.a
checking for rustc ... /usr/sbin/rustc
checking for the rust static library archiver (rcar) ... rustc
checking for flags (--crate-type=staticlib) ... ok
> rustc "--crate-type=staticlib"
/usr/sbin/rustc -C opt-level=3 --edition 2018 -L dependency=/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/3b3b216f73ab4cf18b281eb62ffd4dc9/lib --extern talc=/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/3b3b216f73ab4cf18b281eb62ffd4dc9/lib/libtalc-cbdfd3e84a1fc0b1.rlib --extern spin=/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/3b3b216f73ab4cf18b281eb62ffd4dc9/lib/libspin-8c4e5bc78fa6842c.rlib --crate-type=staticlib -o build/linux/x86_64-unknown-none/release/librsystem.a rsystem/src/lib.rs
error: @programdir/core/main.lua:329: @programdir/actions/build/main.lua:148: @programdir/modules/async/runjobs.lua:322: @programdir/rules/rust/build/target.lua:67: @programdir/core/sandbox/modules/os.lua:273: error[E0461]: couldn't find crate `talc` with expected target triple x86_64-unknown-linux-gnu
 --> rsystem/src/lib.rs:4:5
  |
4 | use talc::*;
  |     ^^^^
  |
  = note: the following crate versions were found:
          crate `talc`, target triple x86_64-unknown-none: /home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/3b3b216f73ab4cf18b281eb62ffd4dc9/lib/libtalc-cbdfd3e84a1fc0b1.rlib

error[E0461]: couldn't find crate `spin` with expected target triple x86_64-unknown-linux-gnu
 --> rsystem/src/lib.rs:9:25
  |
9 | static ALLOCATOR: Talck<spin::Mutex<()>, ClaimOnOom> = Talc::new(unsafe {
  |                         ^^^^
  |
  = note: the following crate versions were found:
          crate `spin`, target triple x86_64-unknown-none: /home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/3b3b216f73ab4cf18b281eb62ffd4dc9/lib/libspin-8c4e5bc78fa6842c.rlib

error[E0412]: cannot find type `Talck` in this scope
 --> rsystem/src/lib.rs:9:19
  |
9 | static ALLOCATOR: Talck<spin::Mutex<()>, ClaimOnOom> = Talc::new(unsafe {
  |                   ^^^^^ not found in this scope

error[E0412]: cannot find type `ClaimOnOom` in this scope
 --> rsystem/src/lib.rs:9:42
  |
9 | static ALLOCATOR: Talck<spin::Mutex<()>, ClaimOnOom> = Talc::new(unsafe {
  |                                          ^^^^^^^^^^ not found in this scope

error: unwinding panics are not supported without std
  |
  = help: using nightly cargo, use -Zbuild-std with panic="abort" to avoid unwinding
  = note: since the core library is usually precompiled with panic="unwind", rebuilding your crate with panic="abort" may not be enough to fix the problem

error[E0433]: failed to resolve: use of undeclared type `Talc`
 --> rsystem/src/lib.rs:9:56
  |
9 | static ALLOCATOR: Talck<spin::Mutex<()>, ClaimOnOom> = Talc::new(unsafe {
  |                                                        ^^^^ use of undeclared type `Talc`

error[E0433]: failed to resolve: use of undeclared type `ClaimOnOom`
  --> rsystem/src/lib.rs:10:5
   |
10 |     ClaimOnOom::new(Span::from_const_array(core::ptr::addr_of!(ARENA)))
   |     ^^^^^^^^^^ use of undeclared type `ClaimOnOom`

error[E0433]: failed to resolve: use of undeclared type `Span`
  --> rsystem/src/lib.rs:10:21
   |
10 |     ClaimOnOom::new(Span::from_const_array(core::ptr::addr_of!(ARENA)))
   |                     ^^^^ use of undeclared type `Span`

error: aborting due to 8 previous errors

Some errors have detailed explanations: E0412, E0433, E0461.
For more information about an error, try `rustc --explain E0412`.

stack traceback:
    [C]: in function 'error'
    [@programdir/core/base/os.lua:973]:
    [@programdir/core/sandbox/modules/os.lua:273]: in function 'runv'
    [@programdir/modules/core/tools/rustc.lua:123]:
    [C]: in function 'xpcall'
    [@programdir/core/base/utils.lua:275]:
    [@programdir/rules/rust/build/target.lua:67]: in function 'build_sourcefiles'
    [@programdir/rules/rust/build/target.lua:83]:
    [@programdir/actions/build/build.lua:52]: in function 'jobfunc'
    [@programdir/modules/async/runjobs.lua:238]:
    [C]: in function 'xpcall'
    [@programdir/core/base/utils.lua:275]: in function 'trycall'
    [@programdir/core/sandbox/modules/try.lua:117]: in function 'try'
    [@programdir/modules/async/runjobs.lua:220]: in function 'cotask'
    [@programdir/core/base/scheduler.lua:406]:

stack traceback:
        [C]: in function 'error'
        @programdir/core/base/os.lua:973: in function 'os.raiselevel'
        (...tail calls...)
        @programdir/core/main.lua:329: in upvalue 'cotask'
        @programdir/core/base/scheduler.lua:406: in function <@programdir/core/base/scheduler.lua:399>

加上add_rcflags("--target", "x86_64-unknown-none", {force = true}) 后可以链接(这个需要加上panic函数)

@waruqi
Copy link
Member

waruqi commented May 29, 2024

master分支似乎可以正常xmake f了(不确定是不是我改了什么代码的结果),但是xmake报的错误是

master 我这也可以了

加上add_rcflags("--target", "x86_64-unknown-none", {force = true}) 后可以链接(这个需要加上panic函数

target 这个我加上了,你可以再试试 #5164

xmake update -s github:xmake-io/xmake#rust

panic 这个需要用户手动自己加上吧,那这边就不管了。。我加上后也能编译

不过我这 macOS 上 link 的时候,还有一个 error 正在看。

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++
-o build/macosx/x86_64-unknown-none/release/libtest.dylib build/.objs/test/macosx/x86_64-unknow
n-none/release/src/main.c.o -shared -target x86_64-unknown-none-apple-macos14.0 -isysroot /Appl
ications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk -
lz -fPIC -Lbuild/macosx/x86_64-unknown-none/release -Wl,-x -Wl,-dead_strip -lrsystem -install_n
ame @rpath/libtest.dylib
ld: archive member '/' not a mach-o file in '/Users/ruki/Downloads/xmake_rust_no_std/build/maco
sx/x86_64-unknown-none/release/librsystem.a'

@waruqi
Copy link
Member

waruqi commented May 29, 2024

linux-no-std分支在configure的时候失败

我单独拎出来用 cargo build 也一样失败,因为你配置了 no main ,所以内部那个 stub rs 里面,自动加了

#![no_main]
$ cargo build --release -vv
defaultlibs"
  = note: ld: Undefined symbols:
            _main, referenced from:
                <initial-undefines>
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

没有 main 就 link 失败了。。所以,我刚提 cargo deps 的那个 stub wrapper 改成 staticlib 了,这样里面就不会走到 link ,反正也只是为了提取 cargo 下载的依赖用。。

#5164

再试试,至少 main link 那个问题,应该能过掉了。

@Yangff
Copy link
Author

Yangff commented May 29, 2024

mater可以正常编译了

linux-no-std那边还需要加上 add_rcflags("-C", "panic=abort", {force = true})。 对于一般使用cargo定义的项目来说这是在Cargo.toml里定义的,因为xmake实际上只是提取依赖的话,在xmake里手动添加这个好像也是合理的。

还有一个 error 正在看

看起来c项目的target和rust的target不一致,链接的时候选择的target是 -target x86_64-unknown-none-apple-macos14.0 (我猜是在set_arch之后强行拼接了mac的target后缀 -apple-macos14.0),而rust是 x86_64-unknown-none
之所以我 set_archx86_64-unknown-none 而不是 x86_64 是因为rust需要的是前者,如果只写 x86_64 的话传递给rust的target会只有 x86_64, 这个会被rust无视掉。

warning: the arch "x86_64" is NOT a valid target triple, will be IGNORED and may cause compilation errors, please check it again
warning: add -v for getting more warnings ..

不过LLVM的triple太乱了,rust的更乱,感觉这里除了一坨if下来没啥特别好的拼接方法其实。

@waruqi
Copy link
Member

waruqi commented May 29, 2024

linux-no-std那边还需要加上 add_rcflags("-C", "panic=abort", {force = true})。 对于一般使用cargo定义的项目来说这是在Cargo.toml里定义的,因为xmake实际上只是提取依赖的话,在xmake里手动添加这个好像也是合理的。

linux-no-std 你这新 patch 还是不行么,什么错误? panic=abort 这个是全局加,还是仅仅 no std 时候加? 我这看加不加 好像都没啥影响么。。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


linux-no-std also needs to add add_rcflags("-C", "panic=abort", {force = true}). For projects that are generally defined using cargo, this is defined in Cargo.toml. Because xmake actually only extracts dependencies, it seems reasonable to add this manually in xmake.

linux-no-std Is your new patch still not working? What is the error? Is panic=abort added globally or only when there is no std? I don't think it makes any difference if I add it or not. .

@waruqi
Copy link
Member

waruqi commented May 29, 2024

还有一个 error 正在看

看起来c项目的target和rust的target不一致,链接的时候选择的target是 -target x86_64-unknown-none-apple-macos14.0 (我猜是在set_arch之后强行拼接了mac的target后缀 -apple-macos14.0),而rust是 x86_64-unknown-none 。 之所以我 set_archx86_64-unknown-none 而不是 x86_64 是因为rust需要的是前者,如果只写 x86_64 的话传递给rust的target会只有 x86_64, 这个会被rust无视掉。

warning: the arch "x86_64" is NOT a valid target triple, will be IGNORED and may cause compilation errors, please check it again
warning: add -v for getting more warnings ..

不过LLVM的triple太乱了,rust的更乱,感觉这里除了一坨if下来没啥特别好的拼接方法其实。

arch 拼错这个问题,主要是你这 set_arch 全局配置导致的,会对 test target 也生效,但是 test target 里面只有 .c 文件,属于 c 项目,走的 xcode toolchain ,这个时候设置的 arch 应该得用默认的 x86_64 ,而不是 rust 那个 x86_64-unknown-none

你只能单独对 rust 那个 target ,和它的 package 配置 x86_64-unknown-none

add_requires("cargo::rsystem", {
    arch = "x86_64-unknown-none",
    configs = {
        std = false,
        main = false,
        cargo_toml = path.join(os.projectdir(), "rsystem", "Cargo.toml"),
    }
})

target("rsystem")
    set_kind("static")
    add_files("src/lib.rs")
    set_values("rust.cratetype", "staticlib")
    add_packages("cargo::rsystem")
    set_arch("x86_64-unknown-none")

这样,arch 就不会拼错了,但是我这那个 error 还不是这个 arch 导致,问题还是存在

@Yangff
Copy link
Author

Yangff commented May 29, 2024

linux-no-std那边还需要加上 add_rcflags("-C", "panic=abort", {force = true})。 对于一般使用cargo定义的项目来说这是在Cargo.toml里定义的,因为xmake实际上只是提取依赖的话,在xmake里手动添加这个好像也是合理的。

linux-no-std 你这新 patch 还是不行么,什么错误? panic=abort 这个是全局加,还是仅仅 no std 时候加? 我这看加不加 好像都没啥影响么。。

可以,只是要自己加上这个-C panic=abort

一般如果整个项目都是 no_std 的且目标是 x86_64-unknown-linux-gnu 这种情况, panic=abort 是要加的。因为没有std就没有unwind,默认的panic使用 unwind 就无法工作。但是,对于 x86_64-unknown-none 这样的目标默认的panic就是abort所以没有问题,所以master直接就过了。

这里的问题是,cargo.toml里面的定义只是对crate而言的,也就是说crate是no_std而项目本身链接std是完全可能的(一些库用不到std的东西就可以加上这个)。所以应该是没没办法简单根据crate的情况来决定是不是要加这行。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


linux-no-std also needs to add add_rcflags("-C", "panic=abort", {force = true}). For projects that are generally defined using cargo, this is defined in Cargo.toml. Because xmake actually only extracts dependencies, it seems reasonable to add this manually in xmake.

linux-no-std Is your new patch still not working? What is the error? Is panic=abort added globally or only when there is no std? I don't think it makes any difference if I add it or not. .

Yes, you just need to add this -C panic=abort yourself

Generally, if the entire project is no_std and the target is x86_64-unknown-linux-gnu, panic=abort should be added. Because there is no unwind without std, the default panic cannot work using unwind. However, for targets like x86_64-unknown-none, the default panic is abort, so there is no problem, so the master can pass it directly.

The problem here is that the definition in cargo.toml is only for crate, which means that the crate is no_std and it is entirely possible for the project itself to link to std (some libraries can add this if they do not use std). So there should be no way to simply decide whether to add this line based on the crate situation.

@Yangff
Copy link
Author

Yangff commented May 29, 2024

如果不加的话会这样

[ 57%]: linking.release librsystem.a
checking for rustc ... /usr/sbin/rustc
checking for the rust static library archiver (rcar) ... rustc
checking for flags (--crate-type=staticlib) ... ok
/usr/sbin/rustc -C opt-level=3 --edition 2018 -L dependency=/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/bfdf9174d3744681b41cf2a5b221e47e/lib --extern spin=/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/bfdf9174d3744681b41cf2a5b221e47e/lib/libspin-c2bf51933e6c0668.rlib --extern talc=/home/yangff/Project/xmake_rust_no_std/build/.packages/c/cargo_rsystem/latest/bfdf9174d3744681b41cf2a5b221e47e/lib/libtalc-0a03620f1ae6954f.rlib --crate-type=staticlib -o build/linux/x86_64/release/librsystem.a rsystem/src/lib.rs
error: error: unwinding panics are not supported without std
  |
  = help: using nightly cargo, use -Zbuild-std with panic="abort" to avoid unwinding
  = note: since the core library is usually precompiled with panic="unwind", rebuilding your crate with panic="abort" may not be enough to fix the problem

error: aborting due to 1 previous error

@waruqi
Copy link
Member

waruqi commented May 29, 2024

linux-no-std那边还需要加上 add_rcflags("-C", "panic=abort", {force = true})。 对于一般使用cargo定义的项目来说这是在Cargo.toml里定义的,因为xmake实际上只是提取依赖的话,在xmake里手动添加这个好像也是合理的。

linux-no-std 你这新 patch 还是不行么,什么错误? panic=abort 这个是全局加,还是仅仅 no std 时候加? 我这看加不加 好像都没啥影响么。。

可以,只是要自己加上这个-C panic=abort

一般如果整个项目都是 no_std 的且目标是 x86_64-unknown-linux-gnu 这种情况, panic=abort 是要加的。因为没有std就没有unwind,默认的panic使用 unwind 就无法工作。但是,对于 x86_64-unknown-none 这样的目标默认的panic就是abort所以没有问题,所以master直接就过了。

这里的问题是,cargo.toml里面的定义只是对crate而言的,也就是说crate是no_std而项目本身链接std是完全可能的(一些库用不到std的东西就可以加上这个)。所以应该是没没办法简单根据crate的情况来决定是不是要加这行。

既然默认也是 abort ,那我就全局加了。。你再试试那个 patch ,看看还有啥问题,没得话,我先 merge 了

@Yangff
Copy link
Author

Yangff commented May 29, 2024

默认也是 abort

啊不是的, x86_64-unknown-none 这种默认是abort的不需要加也不会有问题。只有 x86_64-unknown-linux-gnu 这种默认是 unwind的需要在no_std的情况下加。

但是如果只是根据说cargo包是no std就说整个项目也是no std好像是不大对劲的。。但也不好说,毕竟xmake这里似乎就是把这个cargo包当成是项目本身的cargo.toml来用那好像又没问题。。反正我是不大确定这里到底是咋回事了(

@Yangff
Copy link
Author

Yangff commented May 29, 2024

你再试试那个 patch

这个patch是能用了,不过是否加panic的条件我觉得可以考虑一下,或者单独给一个配置项?至少正常的项目是不应该加这个的,全加上应该会坏事…… 只有真正的no_std项目需要这个(不包括那些只是某个包需要no_std的,比如会不会有人add_requires哪个crate的时候拉进来一个no_std的包).

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


linux-no-std also needs to add add_rcflags("-C", "panic=abort", {force = true}). For projects that are generally defined using cargo, this is defined in Cargo.toml. Because xmake actually only extracts dependencies, it seems reasonable to add this manually in xmake.

linux-no-std Is your new patch still not working? What is the error? Is panic=abort added globally or only when there is no std? I don't think it makes any difference if I add it or not. .

Yes, just add this -C panic=abort yourself

Generally, if the entire project is no_std and the target is x86_64-unknown-linux-gnu, panic=abort should be added. Because there is no unwind without std, the default panic cannot work using unwind. However, for targets like x86_64-unknown-none, the default panic is abort, so there is no problem, so the master can pass it directly.

The problem here is that the definition in cargo.toml is only for crate, which means that crate is no_std and it is entirely possible for the project itself to link to std (some libraries can add this if they do not use std). So there should be no way to simply decide whether to add this line based on the crate situation.

Since the default is also abort, I will add it globally. . You can try that patch again and see if there are any problems. If it doesn't work, I'll merge it first.

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Try that patch again

This patch can be used, but I think we can consider whether to add panic conditions, or provide a separate configuration item?

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


The default is also abort

Ah, no, x86_64-unknown-none is aborted by default. There is no need to add it and there will be no problem. Only x86_64-unknown-linux-gnu, which defaults to unwind, needs to be added in the case of no_std.

But it seems wrong to say that the entire project is also no std just based on the cargo package being no std. . But it’s hard to say. After all, xmake seems to use this cargo package as the cargo.toml of the project itself, so there seems to be no problem. . Anyway, I’m not quite sure what’s going on here (

@waruqi
Copy link
Member

waruqi commented May 29, 2024

你再试试那个 patch

这个patch是能用了,不过是否加panic的条件我觉得可以考虑一下,或者单独给一个配置项?至少正常的项目是不应该加这个的,全加上应该会坏事…… 只有真正的no_std项目需要这个(不包括那些只是某个包需要no_std的,比如会不会有人add_requires哪个crate的时候拉进来一个no_std的包).

关键是这边没法判断当前项目是否 no_std,只有某个包有这个配置,target 里面判断不出来,除非根据 arch 判断是否交叉编译,如果交叉编译就加。。

再不行,就只能用户自己 add_rcflags 自己加了

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Try that patch again

This patch can be used, but I think we can consider whether to add panic conditions, or provide a separate configuration item? At least normal projects shouldn't add this. Adding it all should be bad... Only real no_std projects need this (excluding those that just require no_std for a certain package. For example, will someone pull it in when adding_requires which crate a no_std package).

The key is that there is no way to determine whether the current project is no_std. Only a certain package has this configuration. It cannot be determined in the target unless it is judged according to arch whether to cross-compile. If it is cross-compiled, add it. .

If it doesn't work, the user can only add it by himself using add_rcflags.

@Yangff
Copy link
Author

Yangff commented May 29, 2024

如果交叉编译就加

尴尬的是交叉编译的那个情况反而不用加就行了,因为走的是-none的triple,rustc自动就是abort。

我觉得在target这个范围内好像没有特别好的条件来判断。。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


If cross-compiling, add

The embarrassing thing is that in the case of cross compilation, there is no need to add it, because using the -none triple, rustc automatically aborts.

I feel like there are no particularly good conditions to judge within the scope of target. .

@waruqi
Copy link
Member

waruqi commented May 29, 2024

如果交叉编译就加

尴尬的是交叉编译的那个情况反而不用加就行了,因为走的是-none的triple,rustc自动就是abort。

我觉得在target这个范围内好像没有特别好的条件来判断。。

我改进过了,再试试,现在直接解析 .rs 里面的 [no_std] 来判断是否 no_std 了。

@waruqi waruqi added this to the v2.9.3 milestone May 29, 2024
@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


If cross-compiling, add

The embarrassing thing is that in the case of cross compilation, there is no need to add it, because using the -none triple, rustc automatically aborts.

I feel like there are no particularly good conditions to judge within the scope of target. .

I have improved it and will try again. Now I can directly parse [no_std] in .rs to determine whether it is no_std.

@waruqi
Copy link
Member

waruqi commented May 29, 2024

我 merge 了,先这样吧,有问题再开

@waruqi waruqi closed this as completed May 29, 2024
@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


I have merged. Let’s leave it like this for now. If there are any problems, we’ll open it again.

@Yangff
Copy link
Author

Yangff commented May 29, 2024

如果交叉编译就加

尴尬的是交叉编译的那个情况反而不用加就行了,因为走的是-none的triple,rustc自动就是abort。
我觉得在target这个范围内好像没有特别好的条件来判断。。

我改进过了,再试试,现在直接解析 .rs 里面的 [no_std] 来判断是否 no_std 了。

可以了

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


If cross-compiling, add

The embarrassing thing is that in the case of cross compilation, there is no need to add it, because using the -none triple, rustc automatically aborts.
I feel that there are no particularly good conditions to judge within the scope of target. .

I have improved it and will try again. Now it directly parses [no_std] in .rs to determine whether it is no_std.

That's it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants