tu6ge
September 15, 2024, 3:32am
1
My dockerfile is:
FROM rust:1.80.0-alpine3.20
LABEL com.github.actions.name="auto publish"
LABEL com.github.actions.icon="package"
LABEL com.github.actions.color="blue"
LABEL version="0.1.0"
LABEL repository="http://github.com/tu6ge/publish-action"
LABEL homepage="http://github.com/tu6ge/publish-action"
LABEL maintainer="tu6ge <772364230@qq.com>"
RUN apk update
RUN apk add libc-dev openssl-dev build-base musl-dev pkgconfig
#openssl-dev
WORKDIR /publish
COPY . /publish
#RUN export RUSTFLAGS='-C target-feature=-crt-static'
#RUN export RUSTFLAGS="-C link-arg=-static"
RUN cargo build
and my Cargo.toml
[package]
authors = ["tu6ge <772364230@qq.com>"]
description = "Auto Publish Cargo with Github Action"
edition = "2021"
keywords = ["github-action", "cargo", "CI-CD", "publish"]
license = "MIT"
name = "publish-action"
repository = "https://github.com/tu6ge/publish-action"
version = "0.4.0"
[[bin]]
name = "publish-action"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
build = "build.rs"
[dependencies]
[dev-dependencies]
dotenv = "0.15.0"
tempfile = "3.5.0"
[build-dependencies]
cc = "1.0"
and my build.rs file is
fn main(){
println!("cargo:rustc-link-search=native=/usr/lib");
println!("cargo:rustc-link-lib=ssl");
println!("cargo:rustc-link-lib=crypto");
}
and main.rs is
fn main() {
//list_top_dependencies();
println!("hello world");
}
Result is link lssl
error
/usr/lib/gcc/aarch64-alpine-linux-musl/13.2.1/../../../../aarch64-alpine-linux-musl/bin/ld: cannot find -lssl: No such file or directory
/usr/lib/gcc/aarch64-alpine-linux-musl/13.2.1/../../../../aarch64-alpine-linux-musl/bin/ld: cannot find -lcrypto: No such file or directory
kornel
September 15, 2024, 2:08pm
2
Don't print your own linking directives. Use the openssl-sys crate. It has ability to find the correct package on the system:
2 Likes
tu6ge
September 15, 2024, 11:09pm
3
I tried use it in alpine,it have other error
tu6ge
September 17, 2024, 8:38am
5
My project relies on the cargo library, and when cargo turns on the vendored-openssl feature, it indirectly relies on openssl-sys, which results in an error.
cargo = {version = "0.82.0", features = ["vendored-openssl"]}
error:
error: failed to run custom build command for `openssl-sys v0.9.103`
18.59
18.59 Caused by:
18.59 process didn't exit successfully: `/publish/target/debug/build/openssl-sys-c4a4608f95339019/build-script-main` (exit status: 101)
18.59 --- stdout
18.59 cargo:rustc-check-cfg=cfg(osslconf, values("OPENSSL_NO_OCB", "OPENSSL_NO_SM4", "OPENSSL_NO_SEED", "OPENSSL_NO_CHACHA", "OPENSSL_NO_CAST", "OPENSSL_NO_IDEA", "OPENSSL_NO_CAMELLIA", "OPENSSL_NO_RC4", "OPENSSL_NO_BF", "OPENSSL_NO_PSK", "OPENSSL_NO_DEPRECATED_3_0", "OPENSSL_NO_SCRYPT", "OPENSSL_NO_SM3", "OPENSSL_NO_RMD160", "OPENSSL_NO_EC2M", "OPENSSL_NO_OCSP", "OPENSSL_NO_CMS", "OPENSSL_NO_COMP", "OPENSSL_NO_SOCK", "OPENSSL_NO_STDIO"))
18.59 cargo:rustc-check-cfg=cfg(openssl)
18.59 cargo:rustc-check-cfg=cfg(libressl)
18.59 cargo:rustc-check-cfg=cfg(boringssl)
18.59 cargo:rustc-check-cfg=cfg(libressl250)
18.59 cargo:rustc-check-cfg=cfg(libressl251)
18.59 cargo:rustc-check-cfg=cfg(libressl252)
18.59 cargo:rustc-check-cfg=cfg(libressl261)
18.59 cargo:rustc-check-cfg=cfg(libressl270)
18.59 cargo:rustc-check-cfg=cfg(libressl271)
18.59 cargo:rustc-check-cfg=cfg(libressl273)
18.59 cargo:rustc-check-cfg=cfg(libressl280)
18.59 cargo:rustc-check-cfg=cfg(libressl281)
18.59 cargo:rustc-check-cfg=cfg(libressl291)
18.59 cargo:rustc-check-cfg=cfg(libressl310)
18.59 cargo:rustc-check-cfg=cfg(libressl321)
18.59 cargo:rustc-check-cfg=cfg(libressl332)
18.59 cargo:rustc-check-cfg=cfg(libressl340)
18.59 cargo:rustc-check-cfg=cfg(libressl350)
18.59 cargo:rustc-check-cfg=cfg(libressl360)
18.59 cargo:rustc-check-cfg=cfg(libressl361)
18.59 cargo:rustc-check-cfg=cfg(libressl370)
18.59 cargo:rustc-check-cfg=cfg(libressl380)
18.59 cargo:rustc-check-cfg=cfg(libressl381)
18.59 cargo:rustc-check-cfg=cfg(libressl382)
18.59 cargo:rustc-check-cfg=cfg(libressl390)
18.59 cargo:rustc-check-cfg=cfg(libressl400)
18.59 cargo:rustc-check-cfg=cfg(ossl101)
18.59 cargo:rustc-check-cfg=cfg(ossl102)
18.59 cargo:rustc-check-cfg=cfg(ossl102f)
18.59 cargo:rustc-check-cfg=cfg(ossl102h)
18.59 cargo:rustc-check-cfg=cfg(ossl110)
18.59 cargo:rustc-check-cfg=cfg(ossl110f)
18.59 cargo:rustc-check-cfg=cfg(ossl110g)
18.59 cargo:rustc-check-cfg=cfg(ossl110h)
18.59 cargo:rustc-check-cfg=cfg(ossl111)
18.59 cargo:rustc-check-cfg=cfg(ossl111b)
18.59 cargo:rustc-check-cfg=cfg(ossl111c)
18.59 cargo:rustc-check-cfg=cfg(ossl111d)
18.59 cargo:rustc-check-cfg=cfg(ossl300)
18.59 cargo:rustc-check-cfg=cfg(ossl310)
18.59 cargo:rustc-check-cfg=cfg(ossl320)
18.59 cargo:rustc-check-cfg=cfg(ossl330)
18.59 cargo:rerun-if-env-changed=AARCH64_UNKNOWN_LINUX_MUSL_OPENSSL_NO_VENDOR
18.59 AARCH64_UNKNOWN_LINUX_MUSL_OPENSSL_NO_VENDOR unset
18.59 cargo:rerun-if-env-changed=OPENSSL_NO_VENDOR
18.59 OPENSSL_NO_VENDOR unset
18.59 cargo:rerun-if-env-changed=AARCH64_UNKNOWN_LINUX_MUSL_OPENSSL_CONFIG_DIR
18.59 AARCH64_UNKNOWN_LINUX_MUSL_OPENSSL_CONFIG_DIR unset
18.59 cargo:rerun-if-env-changed=OPENSSL_CONFIG_DIR
18.59 OPENSSL_CONFIG_DIR unset
18.59 OUT_DIR = Some(/publish/target/debug/build/openssl-sys-cd76d88bff820429/out)
18.59 cargo:rerun-if-env-changed=CC_aarch64-unknown-linux-musl
18.59 CC_aarch64-unknown-linux-musl = None
18.59 cargo:rerun-if-env-changed=CC_aarch64_unknown_linux_musl
18.59 CC_aarch64_unknown_linux_musl = None
18.59 cargo:rerun-if-env-changed=HOST_CC
18.59 HOST_CC = None
18.59 cargo:rerun-if-env-changed=CC
18.59 CC = None
18.59 cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT
18.59 RUSTC_WRAPPER = None
18.59 cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
18.59 CRATE_CC_NO_DEFAULTS = None
18.59 DEBUG = Some(true)
18.59 CARGO_CFG_TARGET_FEATURE = Some(neon)
18.59 cargo:rerun-if-env-changed=CFLAGS_aarch64-unknown-linux-musl
18.59 CFLAGS_aarch64-unknown-linux-musl = None
18.59 cargo:rerun-if-env-changed=CFLAGS_aarch64_unknown_linux_musl
18.59 CFLAGS_aarch64_unknown_linux_musl = None
18.59 cargo:rerun-if-env-changed=HOST_CFLAGS
18.59 HOST_CFLAGS = None
18.59 cargo:rerun-if-env-changed=CFLAGS
18.59 CFLAGS = None
18.59 cargo:rerun-if-env-changed=AR_aarch64-unknown-linux-musl
18.59 AR_aarch64-unknown-linux-musl = None
18.59 cargo:rerun-if-env-changed=AR_aarch64_unknown_linux_musl
18.59 AR_aarch64_unknown_linux_musl = None
18.59 cargo:rerun-if-env-changed=HOST_AR
18.59 HOST_AR = None
18.59 cargo:rerun-if-env-changed=AR
18.59 AR = None
18.59 cargo:rerun-if-env-changed=ARFLAGS_aarch64-unknown-linux-musl
18.59 ARFLAGS_aarch64-unknown-linux-musl = None
18.59 cargo:rerun-if-env-changed=ARFLAGS_aarch64_unknown_linux_musl
18.59 ARFLAGS_aarch64_unknown_linux_musl = None
18.59 cargo:rerun-if-env-changed=HOST_ARFLAGS
18.59 HOST_ARFLAGS = None
18.59 cargo:rerun-if-env-changed=ARFLAGS
18.59 ARFLAGS = None
18.59 cargo:rerun-if-env-changed=RANLIB_aarch64-unknown-linux-musl
18.59 RANLIB_aarch64-unknown-linux-musl = None
18.59 cargo:rerun-if-env-changed=RANLIB_aarch64_unknown_linux_musl
18.59 RANLIB_aarch64_unknown_linux_musl = None
18.59 cargo:rerun-if-env-changed=HOST_RANLIB
18.59 HOST_RANLIB = None
18.59 cargo:rerun-if-env-changed=RANLIB
18.59 RANLIB = None
18.59 cargo:rerun-if-env-changed=RANLIBFLAGS_aarch64-unknown-linux-musl
18.59 RANLIBFLAGS_aarch64-unknown-linux-musl = None
18.59 cargo:rerun-if-env-changed=RANLIBFLAGS_aarch64_unknown_linux_musl
18.59 RANLIBFLAGS_aarch64_unknown_linux_musl = None
18.59 cargo:rerun-if-env-changed=HOST_RANLIBFLAGS
18.59 HOST_RANLIBFLAGS = None
18.59 cargo:rerun-if-env-changed=RANLIBFLAGS
18.59 RANLIBFLAGS = None
18.59 running cd "/publish/target/debug/build/openssl-sys-cd76d88bff820429/out/openssl-build/build/src" && env -u CROSS_COMPILE AR="ar" CC="cc" RANLIB="ranlib" "perl" "./Configure" "--prefix=/publish/target/debug/build/openssl-sys-cd76d88bff820429/out/openssl-build/install" "--openssldir=/usr/local/ssl" "no-dso" "no-shared" "no-ssl3" "no-tests" "no-comp" "no-zlib" "no-zlib-dynamic" "--libdir=lib" "no-md2" "no-rc5" "no-weak-ssl-ciphers" "no-camellia" "no-idea" "no-seed" "no-engine" "no-async" "linux-aarch64" "-O2" "-ffunction-sections" "-fdata-sections" "-fPIC" "-gdwarf-4" "-fno-omit-frame-pointer" "-DOPENSSL_NO_SECURE_MEMORY"
18.59
18.59 --- stderr
18.59 thread 'main' panicked at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/openssl-src-300.3.2+3.3.2/src/lib.rs:633:9:
18.59
18.59
18.59
18.59 Error configuring OpenSSL build:
18.59 Command: cd "/publish/target/debug/build/openssl-sys-cd76d88bff820429/out/openssl-build/build/src" && env -u CROSS_COMPILE AR="ar" CC="cc" RANLIB="ranlib" "perl" "./Configure" "--prefix=/publish/target/debug/build/openssl-sys-cd76d88bff820429/out/openssl-build/install" "--openssldir=/usr/local/ssl" "no-dso" "no-shared" "no-ssl3" "no-tests" "no-comp" "no-zlib" "no-zlib-dynamic" "--libdir=lib" "no-md2" "no-rc5" "no-weak-ssl-ciphers" "no-camellia" "no-idea" "no-seed" "no-engine" "no-async" "linux-aarch64" "-O2" "-ffunction-sections" "-fdata-sections" "-fPIC" "-gdwarf-4" "-fno-omit-frame-pointer" "-DOPENSSL_NO_SECURE_MEMORY"
18.59 Failed to execute: No such file or directory (os error 2)
bjorn3
September 17, 2024, 12:18pm
6
It looks like you haven't installed perl. Building OpenSSL requires perl.
tu6ge
September 17, 2024, 12:41pm
7
Thank you very mush . Maybe my problem is solved
kornel
September 18, 2024, 4:17pm
8
I hate the these low-quality build errors. Cargo should really try better here:
opened 02:24PM - 04 Dec 21 UTC
C-bug
A-diagnostics
A-build-scripts
A-console-output
S-accepted
### Problem
When a custom build script fails, Cargo prints a very verbose outpu… t. It's often difficult to find the actual error message from the build script among all other debugging information printed just in case.
For example, it's common for pkg-config crate to fail, but the name of the library that user needs to install is buried under 30 other lines (and even worse with RUST_BACKTRACE=1)
```text
error: failed to run custom build command for `tst v0.1.0 (/private/tmp/tst)`
Caused by:
process didn't exit successfully: `/private/tmp/tst/target/debug/build/tst-2429227eb6585f3e/build-script-build` (exit status: 101)
--- stdout
cargo:rerun-if-env-changed=IDONTEXIST_NO_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG_aarch64-apple-darwin
cargo:rerun-if-env-changed=PKG_CONFIG_aarch64_apple_darwin
cargo:rerun-if-env-changed=HOST_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG
cargo:rerun-if-env-changed=IDONTEXIST_STATIC
cargo:rerun-if-env-changed=IDONTEXIST_DYNAMIC
cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
cargo:rerun-if-env-changed=PKG_CONFIG_PATH_aarch64-apple-darwin
cargo:rerun-if-env-changed=PKG_CONFIG_PATH_aarch64_apple_darwin
cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
cargo:rerun-if-env-changed=PKG_CONFIG_PATH
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_aarch64-apple-darwin
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_aarch64_apple_darwin
cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_aarch64-apple-darwin
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_aarch64_apple_darwin
cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
--- stderr
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: `"pkg-config" "--libs" "--cflags" "idontexist"` did not exit successfully: exit status: 1
--- stderr
Package idontexist was not found in the pkg-config search path.
Perhaps you should add the directory containing `idontexist.pc'
to the PKG_CONFIG_PATH environment variable
No package 'idontexist' found
', build.rs:2:45
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```
It would be nice to trim this output and perhaps extract the error message from the build script and present it like "native" Cargo/Rust errors.
### Steps
```rust
fn main() {
pkg_config::probe_library("idontexist").unwrap();
}
```
### Possible Solution(s)
It needs multiple steps:
* Cargo could hide valid directives like `cargo:rerun-if-env-changed=` from the stdout output, unless run with `--verbose` (with a note about it, similar to how backtrace is hidden).
* It would be nice if Cargo could recognize when a build script panics, and present such information as an explicit build error. Instead of printing "--- stderr thread 'main' panicked at 'called \`Result::unwrap()\` on an \`Err\` value: \`oops\`" print just "error: oops" at the top with other Cargo/Rust errors. I'm not sure what the communication protocol for this could look like. Just parsing stderr for "thread 'main' panicked" might work, but feels inelegant.
* Perhaps support `cargo:error=` directive, similar to `cargo:warning=`, but also support it in stderr output, so that errors printed due to `.unwrap()` can use it.
### Notes
_No response_
### Version
```text
cargo 1.58.0
```
It's also unfortunate that Debug
print of Command
is so verbose it's hard to see the command name. I'm trying to work around that here:
alexcrichton:main
← kornelski:big-cmd
opened 10:17PM - 17 Sep 24 UTC
Because [Cargo's formatting of build errors is very noisy](https://github.com/ru… st-lang/cargo/issues/10159) users struggle to understand what is causing the build to fail.
Here's a [recent case where the failure reason was simple, but the user could not see it](https://users.rust-lang.org/t/in-alpine-rust-can-not-link-ssl-library/117576/5) through all the noise.
----
```diff
Compiling openssl-sys v0.9.103 (~/openssl-sys/openssl-sys)
+The following warnings were emitted during compilation:
+
+warning: openssl-sys@0.9.103: configuring OpenSSL build: Command 'perl' not found. Is perl installed?
+
error: failed to run custom build command for `openssl-sys v0.9.103 (~/openssl-sys/openssl-sys)`
note: To improve backtraces for build dependencies, set the CARGO_PROFILE_DEV_BUILD_OVERRIDE_DEBUG=true environment variable to enable debug information generation.
Caused by:
process didn't exit successfully: `~/openssl-sys/target/debug/build/openssl-sys-60b6752181d583d2/build-script-main` (exit status: 101)
[...]
--- stderr
- thread 'main' panicked at ~/openssl-src-rs/src/lib.rs:578:14:
+ thread 'main' panicked at ~/openssl-sys/build/find_vendored.rs:18:39:
Error configuring OpenSSL build:
- Command: cd "~/openssl-sys/target/debug/build/openssl-sys-8f90d3753aa6037e/out/openssl-build/build/src" && env -u CROSS_COMPILE AR="ar" CC="cc" RANLIB="ranlib" "perl" "./Configure" "--prefix=~/openssl-sys/target/debug/build/openssl-sys-8f90d3753aa6037e/out/openssl-build/install" "--openssldir=/usr/local/ssl" "no-dso" "no-shared" "no-ssl3" "no-tests" "no-comp" "no-zlib" "no-zlib-dynamic" "--libdir=lib" "no-md2" "no-rc5" "no-weak-ssl-ciphers" "no-camellia" "no-idea" "no-seed" "darwin64-arm64-cc" "-nologo" "-MD" "-O2" "-Z7" "-Brepro" "-mmacosx-version-min=11.0"
- Failed to execute: No such file or directory (os error 2)
+ Command 'perl' not found. Is perl installed?
+ Command failed: cd "~/openssl-sys/target/debug/build/openssl-sys-3ae48db4843d8fdf/out/openssl-build/build/src" && env -u CROSS_COMPILE AR="ar" CC="cc" RANLIB="ranlib" "perl" "./Configure" "--prefix=~/openssl-sys/target/debug/build/openssl-sys-3ae48db4843d8fdf/out/openssl-build/install" "--openssldir=/usr/local/ssl" "no-shared" "no-ssl3" "no-tests" "no-comp" "no-zlib" "no-zlib-dynamic" "--libdir=lib" "no-md2" "no-rc5" "no-weak-ssl-ciphers" "no-camellia" "no-idea" "no-seed" "darwin64-arm64-cc" "-nologo" "-MD" "-O2" "-Z7" "-Brepro" "-mmacosx-version-min=11.0"
```
* Cleverness of the `Debug` impl of `Command` obscures the command name that has been run. This change prints the command name alone.
* NotFound error is handled with a dedicated message.
* Uses `cargo:warning` to also print the message above the stdout and stderr dumps.
3 Likes
system
Closed
December 17, 2024, 4:18pm
9
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.