Skip to content

fix: rust static and shared library failing to find extern crate in windows-msvc#6606

Merged
waruqi merged 7 commits intoxmake-io:devfrom
IMXEren:rust-fix
Jul 10, 2025
Merged

fix: rust static and shared library failing to find extern crate in windows-msvc#6606
waruqi merged 7 commits intoxmake-io:devfrom
IMXEren:rust-fix

Conversation

@IMXEren
Copy link
Contributor

@IMXEren IMXEren commented Jul 5, 2025

  • Before adding new features and new modules, please go to issues to submit the relevant feature description first.
  • Write good commit messages and use the same coding conventions as the rest of the project.
  • Please commit code to dev branch and we will merge into master branch in feature
  • Ensure your edited codes with four spaces instead of TAB.

  • 增加新特性和新模块之前,请先到issues提交相关特性说明,经过讨论评估确认后,再进行相应的代码提交,避免做无用工作。
  • 编写友好可读的提交信息,并使用与工程代码相同的代码规范,代码请用4个空格字符代替tab缩进。
  • 请提交代码到dev分支,如果通过,我们会在特定时间合并到master分支上。
  • 为了规范化提交日志的格式,commit消息,不要用中文,请用英文描述。

target("foo")
    set_kind("static")
    add_files("src/foo.rs")
    -- set_values("rust.cratetype", "staticlib")
    -- set_values("rust.cratetype", "cdylib")

target("test1_demo")
    set_kind("binary")
    add_deps("foo")
    add_files("src/main.rs")
target("foo")
    set_kind("shared")
    add_files("src/foo.rs")
    set_values("rust.cratename", "bar")

target("test2_demo")
    set_kind("binary")
    add_deps("foo")
    add_files("src/main.rs") -- extern crate bar as foo;

    -- Incase of dylib, rule("rust") on_config ensures libstd shared library is available when running

IMXEren added 2 commits July 6, 2025 05:00
…indows-msvc

1. rustc requires lib*.rlib, *.dll but produces *.rlib, *.dll.
2. shared library are `foo.dll`, `foo.dll.lib` and it links for
`foo.dll`.
- built using -C prefer-dynamic hence, requires libstd-*.[so|dll|dylib]

add DYLD_LIBRARY_PATH to search libstd
- In non-windows, it's located at <sysroot>/lib
@waruqi waruqi added this to the v3.0.1 milestone Jul 9, 2025
@waruqi waruqi merged commit 8a63251 into xmake-io:dev Jul 10, 2025
11 of 22 checks passed
@IMXEren IMXEren deleted the rust-fix branch July 10, 2025 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] fails to build rust's static library

2 participants