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

Rust: Doesn't build object file #4354

Open
kassane opened this issue Nov 2, 2023 · 4 comments
Open

Rust: Doesn't build object file #4354

kassane opened this issue Nov 2, 2023 · 4 comments
Labels

Comments

@kassane
Copy link

kassane commented Nov 2, 2023

Xmake 版本

2.8.3

操作系统版本和架构

ArchLinux

描述问题

Just build an object file and then choose the linker or pass any custom rules later.
Tried same test on other supported languages: C++, C, Zig and D. No such problem during the build.

期待的结果

I expected xmake to generate just a rust object file. Allow users to choose the linker!

工程配置

add_rules("mode.debug", "mode.release")

target("xmake_rs_demo")
    set_kind("object")
    add_files("src/main.rs")

附加信息和错误日志

build set_kind("object"):

xmake -vvD
checking for platform ... linux
checking for architecture ... x86_64
checking for gcc ... /usr/bin/gcc
checking for zig ... /home/kassane/zig/master/files/zig
checking for rustc ... /usr/bin/rustc
checking for the rust compiler (rc) ... rustc
checking for /usr/bin/rustc ... ok
checking for flags (-C opt-level=3) ... ok
> rustc "-C" "opt-level=3"
error: @programdir/modules/async/runjobs.lua:256: @programdir/rules/rust/build/target.lua:52: bad argument #1 to 'mtime' (string expected, got nil)
stack traceback:
    [C]: in function 'mtime'
    [@programdir/rules/rust/build/target.lua:52]: 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:232]:

stack traceback:
        [C]: in function 'error'
        @programdir/core/base/os.lua:923: in function 'base/os.raiselevel'
        (...tail calls...)
        @programdir/modules/async/runjobs.lua:256: in field 'catch'
        @programdir/core/sandbox/modules/try.lua:123: in global 'try'
        @programdir/modules/async/runjobs.lua:218: in upvalue 'cotask'
        @programdir/core/base/scheduler.lua:404: in function <@programdir/core/base/scheduler.lua:397>
@kassane kassane added the bug label Nov 2, 2023
@waruqi
Copy link
Member

waruqi commented Nov 3, 2023

I tried this a long time ago and failed, it's complicated and doesn't handle links well. rustc also doesn't provide any more interface parameters for me to do this.

@kassane
Copy link
Author

kassane commented Nov 3, 2023

Try rustc -C opt-level=3 --edition 2018 --emit=obj src/main.rs - output in $PWD - xmake need move object file

Please, allow choose rust edition, like c++ version! [edition: 2015|2018|2021] - TODO 2024

@waruqi
Copy link
Member

waruqi commented Nov 3, 2023

Try rustc -C opt-level=3 --edition 2018 --emit=obj src/main.rs - output in $PWD - xmake need move object file

Please, allow choose rust edition, like c++ version! [edition: 2015|2018|2021] - TODO 2024

I know it, but I don't know how to link these objects with rust system libs, modules, packages. But rustc a.rs b.rs ... will do some automatically.

@taooceros
Copy link

taooceros commented Mar 3, 2024

May I ask why by default xmake uses 2018 edition? I don't know how to change it, even though my config toml is using 2021.

nevermind I found it, but it seems not in the docs and pretty hard to figure out how to do 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

3 participants