From de114d5d225483578b6a7633bce228b791c0268c Mon Sep 17 00:00:00 2001 From: Orne Brocaar Date: Thu, 25 May 2023 17:05:53 +0100 Subject: [PATCH] Implement fully static AMD64 build. --- .cargo/config.toml | 3 ++ .dockerignore | 5 ++- Cargo.lock | 13 ------- Cross.toml | 2 + chirpstack/Cargo.toml | 7 ++-- chirpstack/src/main.rs | 2 + cross/Dockerfile.x86_64-unknown-linux-musl | 43 ++++++++++++++++++++++ docker-compose.yml | 12 ------ rust-toolchain.toml | 6 +-- 9 files changed, 58 insertions(+), 35 deletions(-) create mode 100644 Cross.toml create mode 100644 cross/Dockerfile.x86_64-unknown-linux-musl diff --git a/.cargo/config.toml b/.cargo/config.toml index e2f942b5..c795d50a 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -3,3 +3,6 @@ linker = "arm-linux-gnueabihf-gcc" [target.aarch64-unknown-linux-gnu] linker = "aarch64-linux-gnu-gcc" + +[target.x86_64-unknown-linux-musl] +rustflags = ["-C", "target-feature=+crt-static", "-C", "link-arg=-s", "-C", "link-arg=-lc", "-C", "link-arg=-lgcc"] \ No newline at end of file diff --git a/.dockerignore b/.dockerignore index 3a544f0e..492f0974 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,9 @@ .git .cargo .rust -**/target +api/rust/target +backend/target +lrwn/target +lrwn/filters/target **/node_modules Dockerfile diff --git a/Cargo.lock b/Cargo.lock index 9271a1fd..b297c4ca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -968,7 +968,6 @@ dependencies = [ "pbkdf2", "petgraph", "pin-project", - "pq-sys", "prometheus-client", "prost", "prost-types", @@ -2748,15 +2747,6 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" -[[package]] -name = "openssl-src" -version = "111.25.3+1.1.1t" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "924757a6a226bf60da5f7dd0311a34d2b52283dd82ddeb103208ddc66362f80c" -dependencies = [ - "cc", -] - [[package]] name = "openssl-sys" version = "0.9.87" @@ -2765,7 +2755,6 @@ checksum = "8e17f59264b2809d77ae94f0e1ebabc434773f370d6ca667bd223ea10e06cc7e" dependencies = [ "cc", "libc", - "openssl-src", "pkg-config", "vcpkg", ] @@ -3144,7 +3133,6 @@ version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "31c0052426df997c0cbd30789eb44ca097e3541717a7b8fa36b1c464ee7edebd" dependencies = [ - "pkg-config", "vcpkg", ] @@ -3369,7 +3357,6 @@ checksum = "87ac9d87c3aba1748e3112318459f2ac8bff80bfff7359e338e0463549590249" dependencies = [ "cmake", "libc", - "libz-sys", "num_enum", "pkg-config", ] diff --git a/Cross.toml b/Cross.toml new file mode 100644 index 00000000..e632c543 --- /dev/null +++ b/Cross.toml @@ -0,0 +1,2 @@ +[target.x86_64-unknown-linux-musl] +dockerfile="cross/Dockerfile.x86_64-unknown-linux-musl" \ No newline at end of file diff --git a/chirpstack/Cargo.toml b/chirpstack/Cargo.toml index b4ce0bdf..dacfd8d0 100644 --- a/chirpstack/Cargo.toml +++ b/chirpstack/Cargo.toml @@ -36,7 +36,6 @@ diesel_migrations = { version = "2.0" } r2d2 = "0.8" bigdecimal = "0.3" redis = { version = "0.23", features = ["r2d2", "cluster", "tls-rustls"] } -pq-sys = { version = "0.4", features = ["pkg-config"] } # Logging tracing = "0.1" @@ -69,7 +68,7 @@ gcp_auth = "0.8" lapin = "2.1" tokio-executor-trait = "2.1" tokio-reactor-trait = "1.1" -rdkafka = { version = "0.29", features = ["cmake-build"] } +rdkafka = { version = "0.29", default-features = false, features = ["tokio", "cmake-build"] } # gRPC and Protobuf tonic = "0.9" @@ -100,11 +99,11 @@ anyhow = "1.0" pbkdf2 = { version = "0.12", features = ["simple"] } rand_core = { version = "0.6", features = ["std"] } jsonwebtoken = "8.2" -openssl = { version = "0.10", features = ["vendored"] } +openssl = { version = "0.10" } openidconnect = { version = "3.0", features = ["accept-rfc3339-timestamps"] } # MQTT -paho-mqtt = { version = "0.12", features = ["vendored-ssl"] } +paho-mqtt = { version = "0.12", features = ["ssl"] } hex = "0.4" # Codecs diff --git a/chirpstack/src/main.rs b/chirpstack/src/main.rs index ae496a51..0b96a162 100644 --- a/chirpstack/src/main.rs +++ b/chirpstack/src/main.rs @@ -3,6 +3,8 @@ // TODO: remove this + all dead code. #![allow(dead_code)] +extern crate openssl; + #[macro_use] extern crate lazy_static; extern crate diesel_migrations; diff --git a/cross/Dockerfile.x86_64-unknown-linux-musl b/cross/Dockerfile.x86_64-unknown-linux-musl new file mode 100644 index 00000000..150bc89e --- /dev/null +++ b/cross/Dockerfile.x86_64-unknown-linux-musl @@ -0,0 +1,43 @@ +FROM ghcr.io/cross-rs/x86_64-unknown-linux-musl:latest + +ENV ZLIB_VERSION=1.2.13 +ENV POSTGRESQL_VERSION=11.20 +ENV OPENSSL_VERSION=1.1.1t +ENV MUSL_PREFIX=x86_64-linux-musl + +RUN apt-get update && \ + apt-get --assume-yes install \ + protobuf-compiler + +RUN echo "Building OpenSSL" && \ + cd /tmp && \ + curl -fLO "https://www.openssl.org/source/openssl-$OPENSSL_VERSION.tar.gz" && \ + tar xvzf "openssl-$OPENSSL_VERSION.tar.gz" && cd "openssl-$OPENSSL_VERSION" && \ + env CC=$MUSL_PREFIX-gcc ./Configure no-shared no-zlib -fPIC --prefix=/usr/local/$MUSL_PREFIX-target -DOPENSSL_NO_SECURE_MEMORY linux-x86_64 && \ + env C_INCLUDE_PATH=/usr/local/$MUSL_PREFIX/include/ make depend && \ + env C_INCLUDE_PATH=/usr/local/$MUSL_PREFIX/include/ make && \ + make install_sw && \ + rm -r /tmp/* + +RUN echo "Building zlib" && \ + cd /tmp && \ + curl -fLO "https://zlib.net/zlib-$ZLIB_VERSION.tar.gz" && \ + tar xzf "zlib-$ZLIB_VERSION.tar.gz" && cd "zlib-$ZLIB_VERSION" && \ + CC=$MUSL_PREFIX-gcc ./configure --static --prefix=/usr/local/$MUSL_PREFIX-target && \ + make && make install && \ + rm -r /tmp/* + + +RUN echo "Building libpq" && \ + cd /tmp && \ + curl -fLO "https://ftp.postgresql.org/pub/source/v$POSTGRESQL_VERSION/postgresql-$POSTGRESQL_VERSION.tar.gz" && \ + tar xzf "postgresql-$POSTGRESQL_VERSION.tar.gz" && cd "postgresql-$POSTGRESQL_VERSION" && \ + CC=$MUSL_PREFIX-gcc CPPFLAGS="-I/usr/local/$MUSL_PREFIX/include -I/usr/local/$MUSL_PREFIX-target/include" LDFLAGS="-L/usr/local/$MUSL_PREFIX/lib -L/usr/local/$MUSL_PREFIX-target/lib" ./configure --with-openssl --without-readline --prefix=/usr/local/$MUSL_PREFIX-target && \ + cd src/interfaces/libpq && make all-static-lib && make install-lib-static && \ + rm -r /tmp/* + +# Workaround for re-defined unicode_to_utf8 which also exists in quickjs library. +RUN objcopy --redefine-sym unicode_to_utf8=unicode_to_utf8_rename /usr/local/$MUSL_PREFIX-target/lib/libpq.a + + +ENV PKG_CONFIG_PATH=/usr/local/$MUSL_PREFIX-target/lib/pkgconfig \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 2605dcb9..fc0f5267 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -23,18 +23,6 @@ services: ports: - "8080:8080" - chirpstack-build-amd64: - image: chirpstack/chirpstack-dev-cache:latest - platform: linux/amd64 - volumes: - - ./:/chirpstack - - chirpstack-build-arm64: - image: chirpstack/chirpstack-dev-cache:latest - platform: linux/arm64 - volumes: - - ./:/chirpstack - chirpstack-ui: build: context: ./ui diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 3760361a..96971622 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,8 +1,4 @@ [toolchain] -channel = "1.68.2" +channel = "1.69.0" components = ["rustfmt", "clippy"] -targets = [ - "armv7-unknown-linux-gnueabihf", - "aarch64-unknown-linux-gnu", -] profile = "default" \ No newline at end of file