为什么 rustc 没有将 libmariadb 包含到发布二进制文件中?
Why rustc did not include libmariadb into release binary?
我认为 Rust 编译器使用静态绑定并在编译时包含所有依赖库(因此可执行文件大小)。
但是当我尝试在 docker 临时图像中使用已编译的二进制文件时,actix、mysql 客户端和启用了 mysql 功能的柴油会弹出此错误:
error while loading shared libraries: libmariadb.so.3: cannot open shared object file: No such file or director
我的docker文件:
FROM rust:1.43 as builder
WORKDIR /var/app
RUN apt-get update && apt-get install -y libclang-dev clang libmariadb-dev-compat libmariadb-dev
COPY Cargo.toml Cargo.lock diesel.toml ./
COPY src src
RUN cargo install diesel_cli --no-default-features --features mysql
RUN cp /usr/local/cargo/bin/diesel diesel
RUN cargo build --release
FROM ubuntu
USER 1000
WORKDIR /var/app
COPY --from=builder --chown=1000:1000 /var/app/target/release/sniper_api app
COPY --from=builder --chown=1000:1000 /var/app/diesel diesel
CMD ["./app"]
我的货物:
[dependencies]
actix-rt = "1.0.0"
actix-web = "2.0.0"
actix-http = "1.0.1"
serde = { version = "1.0.112", features=["derive"] }
dotenv = "0.15.0"
config = "0.10.1"
diesel = { version = "1.4.2", features = ["mysql","r2d2"]}
futures = "0.3.5"
r2d2 = "0.8.8"
r2d2_mysql = "18.0.0"
env_logger = "0.7.1"
但是如果我使用ubuntu/debian/etc。图像作为运行时并安装 libmariadb-dev-compat libmariadb-dev
一切都很好。有没有办法在 Rust 中使用 mysql 连接器获得真正的单个二进制文件?
I thought rust compiler uses static binding and includes all the dependent libraries at compile time (hence executable size).
这仅适用于 Rust 库。对于其他语言,rustc 通常能做的很少。
特别是在这种情况下,diesel
通过 mysqlclient-sys
crate for which there currently is an issue and an accompanying PR open 提供 mysql
/mariadb
支持以支持此库的静态链接。但是他们还没有合并。
我认为 Rust 编译器使用静态绑定并在编译时包含所有依赖库(因此可执行文件大小)。
但是当我尝试在 docker 临时图像中使用已编译的二进制文件时,actix、mysql 客户端和启用了 mysql 功能的柴油会弹出此错误:
error while loading shared libraries: libmariadb.so.3: cannot open shared object file: No such file or director
我的docker文件:
FROM rust:1.43 as builder
WORKDIR /var/app
RUN apt-get update && apt-get install -y libclang-dev clang libmariadb-dev-compat libmariadb-dev
COPY Cargo.toml Cargo.lock diesel.toml ./
COPY src src
RUN cargo install diesel_cli --no-default-features --features mysql
RUN cp /usr/local/cargo/bin/diesel diesel
RUN cargo build --release
FROM ubuntu
USER 1000
WORKDIR /var/app
COPY --from=builder --chown=1000:1000 /var/app/target/release/sniper_api app
COPY --from=builder --chown=1000:1000 /var/app/diesel diesel
CMD ["./app"]
我的货物:
[dependencies]
actix-rt = "1.0.0"
actix-web = "2.0.0"
actix-http = "1.0.1"
serde = { version = "1.0.112", features=["derive"] }
dotenv = "0.15.0"
config = "0.10.1"
diesel = { version = "1.4.2", features = ["mysql","r2d2"]}
futures = "0.3.5"
r2d2 = "0.8.8"
r2d2_mysql = "18.0.0"
env_logger = "0.7.1"
但是如果我使用ubuntu/debian/etc。图像作为运行时并安装 libmariadb-dev-compat libmariadb-dev
一切都很好。有没有办法在 Rust 中使用 mysql 连接器获得真正的单个二进制文件?
I thought rust compiler uses static binding and includes all the dependent libraries at compile time (hence executable size).
这仅适用于 Rust 库。对于其他语言,rustc 通常能做的很少。
特别是在这种情况下,diesel
通过 mysqlclient-sys
crate for which there currently is an issue and an accompanying PR open 提供 mysql
/mariadb
支持以支持此库的静态链接。但是他们还没有合并。