fix(ci): static compilation
ci/woodpecker/push/build Pipeline was successful Details
ci/woodpecker/push/clippy Pipeline failed Details
ci/woodpecker/push/lint Pipeline failed Details

pull/11/head
Jef Roosens 2024-07-07 12:47:28 +02:00
parent 7546ec9c5f
commit c13b823682
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
2 changed files with 13 additions and 38 deletions

View File

@ -10,12 +10,19 @@ steps:
image: 'rust:1.79-alpine3.19' image: 'rust:1.79-alpine3.19'
environment: environment:
- 'LIBARCHIVE_STATIC=1' - 'LIBARCHIVE_STATIC=1'
- 'LIBARCHIVE_LIB_DIR=/usr/lib'
- 'LIBARCHIVE_INCLUDE_DIR=/usr/include'
- 'LIBARCHIVE_LDFLAGS=-lssl -lcrypto -L/lib -lz -lbz2 -llzma -lexpat -lzstd -llz4'
- 'LIBARCHIVE_LDFLAGS=-L/usr/lib -lz -lbz2 -llzma -lexpat -lzstd -llz4 -lsqlite3'
commands: commands:
- apk add --no-cache build-base libarchive-static libarchive-dev # Dependencies required to statically compile libarchive and libsqlite3
- >
apk add --no-cache build-base
libarchive-static libarchive-dev
zlib-static
openssl-libs-static
bzip2-static
xz-static
expat-static
zstd-static
lz4-static
acl-static
- cargo build --verbose - cargo build --verbose
# Binaries, even debug ones, should be statically compiled # Binaries, even debug ones, should be statically compiled
- '[ "$(readelf -d target/debug/rieterd | grep NEEDED | wc -l)" = 0 ]' - '[ "$(readelf -d target/debug/rieterd | grep NEEDED | wc -l)" = 0 ]'

View File

@ -1,35 +1,3 @@
extern crate pkg_config;
use std::env;
fn main() { fn main() {
let lib_dir = env::var("LIBARCHIVE_LIB_DIR").ok(); pkg_config::Config::new().atleast_version("3").probe("libarchive").unwrap();
let include_dir = env::var("LIBARCHIVE_INCLUDE_DIR").ok();
if lib_dir.is_some() && include_dir.is_some() {
println!("cargo:rustc-flags=-L native={}", lib_dir.unwrap());
println!("cargo:include={}", include_dir.unwrap());
let mode = match env::var_os("LIBARCHIVE_STATIC") {
Some(_) => "static",
None => "dylib",
};
println!("cargo:rustc-flags=-l {0}=archive", mode);
if mode == "static" {
if let Ok(ldflags) = env::var("LIBARCHIVE_LDFLAGS") {
for token in ldflags.split_whitespace() {
if token.starts_with("-L") {
println!("cargo:rustc-flags=-L native={}", token.replace("-L", ""));
} else if token.starts_with("-l") {
println!("cargo:rustc-flags=-l static={}", token.replace("-l", ""));
}
}
}
}
} else {
match pkg_config::find_library("libarchive") {
Ok(_) => (),
Err(msg) => panic!("Unable to locate libarchive, err={:?}", msg),
}
}
} }