Rust 打包成 .deb 文件。

huangapple go评论96阅读模式
英文:

Rust packaged in .deb

问题

我想将我的Rust代码创建成一个.deb软件包。它包括一个库(crate),被另一个库crate和一个二进制crate使用。所以类似于

- core_lib
- pam_lib(使用core_lib
- cli_binary(使用core_lib

问题1

问题是解决依赖关系,当然了 Rust 打包成 .deb 文件。 我尝试过两种方法:

动态链接

在编译代码时,我可以强制它期望在哪里找到共享库,例如cargo rustc -r -- -C link-args='-Wl,-rpath,/usr/lib/x86_64-linux-gnu/mylib'。然而,当我这样做并且dpkg build软件包时,lintian返回一个错误:custom-library-search-path

添加到ldconfig

我还可以在/etc/ld.so.conf.d/目录中添加一个新的配置文件,并设置路径到/usr/lib/x86_64-linux-gnu/mylib目录,然后在postinst脚本中执行sudo ldconfig以更新值。但**这是否是正确的方法?**我不想遵循任何反模式。

问题2

我遇到的另一个问题是,当我编译任何一个“最终”二进制文件时,它也会在target/release文件夹中编译core_lib。到目前为止,一切都很好。但是libcore_lib.so在我编译pam_libcli_binary时不同(甚至字节大小也有点不同),我不能互换使用它们。即使我独立编译core_lib并使用该构件,运行任何一个二进制文件都会返回unknown symbol,后面跟着一个来自core_lib的函数引用。

一个可能的解决方案是将libcore_lib.so复制两次到不同的目录(分别为每个二进制文件从它们自己的target/release目录),但由于它应该是一个共享引用,这似乎是明显的... 愚蠢。

有什么想法,请?

核心库的Cargo.toml

[package]
name = "core-lib"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["dylib"]

[dependencies]
...

和二进制文件的Cargo.toml

[package]
name = "cli-binary"
version = "0.1.0"
edition = "2021"

[dependencies]
core-lib = { path = "../../Rust core/core-lib" }
...

(Note: The code portions are not translated as per your request.)

英文:

I want to create a .deb package out of my Rust code. It consists of a library (crate) that is used by another library crate and a binary crate. So something like

- core_lib
- pam_lib (uses core_lib)
- cli_binary (uses core_lib)

Question 1

The issue is resolving dependencies, of course Rust 打包成 .deb 文件。 I have tried two approaches:

Dynamic linking

When compiling the code, I can force where it should expect shared libraries to be found, as cargo rustc -r -- -C link-args='-Wl,-rpath,/usr/lib/x86_64-linux-gnu/mylib'. However, when I do this and dpkg build the package, lintian returns an error: custom-library-search-path.

Adding to ldconfig

I can also add a new config file to /etc/ld.so.conf.d/ and set a path to my /usr/lib/x86_64-linux-gnu/mylib dir, and execute sudo ldconfig in a postinst script to update the values. But is this the right way to go? I wouldn't like to follow any antipatterns.

Question 2

The other issue I'm having with these dependencies is that when I compile either of the 'final' binaries, it also compiles the core_lib in the target/release folder. So far, so good. But libcore_lib.so is not the same when I compile pam_lib or cli_binary (even byte size is somewhat different), and I cannot use them interchangeably. Not even when I compile core_lib independently and use that artifact; running either binary returns unknown symbol followed by a reference to a function from core_lib.

One possible solution would be to copy libcore_lib.so twice to different dirs (once for each binary from their own target/release dir), but since it is supposed to be a shared reference, that seems to be outright... stupid.

Any ideas, please?

Core library Cargo.toml:

[package]
name = "core-lib"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["dylib"]

[dependencies]
...

and binaries Cargo.toml:

[package]
name = "cli-binary"
version = "0.1.0"
edition = "2021"

[dependencies]
core-lib = { path = "../../Rust core/core-lib" }
...

答案1

得分: 0

好的,以下是翻译好的内容:

"Okay, the dumb part was... me Rust 打包成 .deb 文件。

I was also browsing Rust forum and stumbled upon a topic that resembled mine - and sure enough, when I changed the core_lib type from dylib to lib, it all started working. I just imposed a lot of headache upon me by using dylib for no real reason (switched to that long time ago for reasons I no longer remember... sigh).

Anyway, hope it helps someone else, too.

英文:

Okay, the dumb part was... me Rust 打包成 .deb 文件。

I was also browsing Rust forum and stumbled upon a topic that resembled mine - and sure enough, when I changed the core_lib type from dylib to lib, it all started working. I just imposed a lot of headache upon me by using dylib for no real reason (switched to that long time ago for reasons I no longer remember... sigh).

Anyway, hope it helps someone else, too.

huangapple
  • 本文由 发表于 2023年6月5日 20:44:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76406546.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定