-
-
Notifications
You must be signed in to change notification settings - Fork 814
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项目时,cargo的编译期依赖没有被正确安装 #5156
Comments
Title: When cross-compiling a Rust project, the compile-time dependencies of cargo are not installed correctly. |
好的,等下,我先把之前那个 #4929 处理了,再看这个。有点忙 |
Okay, wait a minute, I'll take care of the previous #4929 first, and then look at this one. a little busy |
https://github.com/Yangff/xmake_rust_macro 我试着弄一个MRE但是我不大确定弄错了什么,在install的时候就失败了, UE4SS那边至少我还能install的上……
不过只拷贝了目标平台的依赖的问题是一样的,比如下面这些就没有拷贝,至于这个install为啥failed我就不知道了。。
这里用了zig来提供win/linux交叉编译时候的链接,不然得带上一堆Linux的依赖。不过这个失败在Linux下也是一样的,好像设置了 |
|
|
目前没区分,可以走安装,但是不要安装到 lib 目录下,那个用于目标库依赖查找的。。 可以安装到 比如这样,可以试试,#5173 不过我没验证过。或者你可以根据这个 patch 调整下试试 |
There is currently no distinction. You can install it, but do not install it in the lib directory, which is used to find target library dependencies. . Can be installed into the |
似乎这里不会去找host路径下的文件
看起来应该这样? 我不确定mac下的扩展名是什么,windows应该是.dll (或者用 |
另外之前给rcflags加的target好像也有点问题 就是这个,在链接的时候如果用了rust作为链接器(不大确定这是怎么决定的,可能和
|
In addition, there seems to be some problem with the target added to rcflags before. That's it. If you use rust as the linker when linking, it will use both rcflags and rcldflags, resulting in such a compilation instruction.
|
如果找到,不是要 host 的库也得 link 进去?arch 对的上么。。
之前你不是说只需要加 -L 么。。刚那个 patch ,应该会加 -L 。。 但是前提是有对应 target 的库先被找到,但是你那个demo,除了一个 dep1 的host 依赖。。bind 本身再也没 target arch 的库依赖了,导致找不到任何库,所以 这个 host linkdir 也不会被附带进来 |
If found, doesn’t it mean that the host library also needs to be linked in? Is arch right? .
Didn't you say before that you only need to add -L? . For the patch just now, -L should be added. . But the premise is that a library corresponding to the target is found first, but your demo has only one dep1 host dependency. . bind itself no longer depends on the library of target arch, so no library can be found, so the host linkdir will not be included. |
是这样的,xmake提示find package失败,我看了一下它试图找到dep1这个依赖(就是红框这个),然后dep1是编译期的依赖,在lib目录里找不到,然后xmake好像就觉得这个cargo::bind找不到了。 我看了一下Windows下交叉编译的时候cargo生成的命令
他确实是 在我把
ue4ss那边确实没有把这些host的依赖加入bind里面,不管是cargo的
对,这就是下面这个错误的原因
所以我给他加进去那个路径了…… |
我想应该是这样的,ue4ss的项目里syn那些用了proc macro的库是patternsleuth的依赖(甚至是依赖的依赖)。 我的复现简化了这一步,bind直接依赖dep1,所以哪怕把dep1添加到 |
I think it should be like this. In the ue4ss project, syn libraries that use proc macro are dependent on patternsleuth. My reproduction simplifies this step. Bind directly depends on dep1, so even if dep1 is added to |
那现在这个 patch ,按理应该对 us4ss 仅仅加 -L 可以 work 的,你试试呢,还是不行?
等于当前没任何 target arch 的依赖库,仅仅只有一个 host dep1 库。。 它要是 link dep1 进去了,岂不是跪了,尽管当前你这个 demo 没去 link。所以我还是不确定是否安装进去 参与 link 一定可靠。 |
我改了下,再试试, |
So the current patch should work just by adding -L to us4ss. Have you tried it, or does it still not work?
It means that there is currently no dependent library of target arch, only one host dep1 library. . If it had link dep1 in, wouldn't it be a disaster, even though your demo is currently not linked. So I'm still not sure whether installing it and participating in the link must be reliable. |
I changed it and tried again, |
行
对于rust来说只是意味着指定这个crate的搜索路径就算你不加
是否最后和生成的二进制link是rustc根据它的类型决定的。 https://doc.rust-lang.org/reference/linkage.html
|
这个没问题了 |
This is no problem |
那就是我即使无脑 copy 安装过去,走 extern + link 也没啥问题咯?如果没啥影响的话,那我就直接把 host 也 copy 过去了。 |
That is, even if I install it without a brain copy and use extern + link, there will be no problem? If there is no impact, then I will copy the host directly. |
我觉得应该是没有影响的,不过xmake那边检查是否安装成功的时候可能还是要
就可能是这样的? |
I think there should be no impact, but xmake may still need to check
Is that possible? |
再试试,#5173 |
Linux 下可以了,win上搜索lib的时候前缀会有另一个问题 |
This problem seems to have nothing to do with the current issue, and it also exists when cross-compiling is not done. Here I turned off cross-compilation and it can’t be found when I compile Windows for Windows alone. |
lib前缀这个应该是单独的问题,我看了一下 Windows上使用msvc时dll和staticlib应该是都不带lib前缀的 https://github.com/rust-lang/rust/blob/1.78.0/compiler/rustc_target/src/spec/base/windows_msvc.rs 在Windows上使用gnu时,staticlib是带lib前缀的,而dll还是不带 rlib无论如何都带lib前缀 拿gnu做windows的libc的应该比较少吧,再加上拿staticlib做rust内部依赖的应该就更少了,主要是得判断target的类型,如果没有明确set_arch的话得去获得工具链的默认target有点麻烦的。 dll应该是无论如何都不带lib,所以检查的时候应该可以无脑给dll加上lib来做判断。 |
The lib prefix should be a separate issue. I took a look. When using msvc on Windows, dll and staticlib should not have the lib prefix. https://github.com/rust-lang/rust/blob/1.78.0/compiler/rustc_target/src/spec/base/windows_msvc.rs When using gnu, staticlib is prefixed with lib, but dll still does not. rlib is prefixed with lib anyway There should be relatively few people who use gnu as libc for windows, and even fewer people use staticlib as rust's internal dependency. The main thing is to determine the target type. If set_arch is not specified, it is a bit difficult to obtain the default target of the tool chain. Troublesome. The dll should not have lib in any case, so when checking, you should be able to add lib to the dll to make a judgment without thinking. |
再试试,xmake update -s dev |
Try again, xmake update -s dev |
这次虽然找到了,但是编译的时候不会加载这个依赖
查看了一下有两个问题导致的这点 首先, 其次,
于是匹配不到名字这个依赖项就被跳过了。 强行让他加载.dll并且加了一个fallback之后它能成功编译,就是不知道会不会有其它的问题……
不过到这影响不是很大了,反正依赖是cp都复制完了,不在xmake里直接import需要proc macro的项目应该就行…… 一般做binding的话应该可能也就用用普通的macro就好了。。 |
Although it was found this time, the dependency will not be loaded during compilation.
After checking, there are two problems causing this. First of all, Secondly, the regular expression used to match
Therefore, the dependency that does not match the name is skipped. |
再试试那个 cargo branch patch |
cargo branch 加上 5e4bbe9 这个就可以了 |
Try that cargo branch patch again |
这个在 dev 上,我已经 merge 了。再试试 |
cargo branch plus 5e4bbe9 This will do it |
This is on dev and I have merged it. try again |
Xmake 版本
xmake v2.9.2+master.d8818c5b0
操作系统版本和架构
all
描述问题
当前,xmake通过编译一个空的项目来复制cargo解析的rust项目依赖,并将产生的所有编译结果安装到目标路径。
#4049 解决了交叉编译时不能正确拷贝目标平台库文件的问题。
但是,在交叉编译时,rust会将需要在主机运行的编译期依赖,例如过程宏编译为可以在主机平台运行的文件,例如.dlls。这些目标文件不会被存放在
target/arch/release/deps
, 而是target/release/deps
.Cargo会在产生rustc指令时同时将这两个目录放进
-L
中,从而产生正确的编译结果。但是,通过add_files添加的rs文件只会在xmake复制后的安装路径中寻找依赖,这使得rustc无法在
use
对应包的时候提示找不到这个包,实际上,是找不到对应的在主机上运行的依赖。产生类似如下的错误
期待的结果
项目应该正常编译,调用应该为
工程配置
我手上没有合适的复现但是原理上来说
加上第二行复制之后就可以正确编译了 (我测试也是可以的)。
但是,我不认为将主机依赖复制到安装路径下是正确的行为。。 我不大确定额xmake是怎么区分编译期依赖和项目依赖的安装路径的。
另外我也遇到了 #4049 (comment) 这里提到的不会自动添加
的问题,这似乎与我之前编译no_std的时候遇到的问题是一样的,和这里的问题无关,只是如果修复上述代码之后交叉编译还是失败的话可能是这个导致的。
附加信息和错误日志
无
The text was updated successfully, but these errors were encountered: