diff --git a/.cargo/config.toml b/.cargo/config.toml index c795d50a..47b6ec15 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,3 +1,5 @@ + + [target.armv7-unknown-linux-gnueabihf] linker = "arm-linux-gnueabihf-gcc" @@ -5,4 +7,7 @@ linker = "arm-linux-gnueabihf-gcc" 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 +rustflags = ["-C", "target-feature=+crt-static", "-C", "link-arg=-s", "-C", "link-arg=-lc", "-C", "link-arg=-lgcc"] + +[target.aarch64-unknown-linux-musl] +rustflags = ["-C", "target-feature=+crt-static", "-C", "link-arg=-s", "-C", "link-arg=-lc", "-C", "link-arg=-lgcc"] diff --git a/Cross.toml b/Cross.toml index e632c543..46bda70b 100644 --- a/Cross.toml +++ b/Cross.toml @@ -1,2 +1,8 @@ +[build] +default-target="x86_64-unknown-linux-musl" + [target.x86_64-unknown-linux-musl] -dockerfile="cross/Dockerfile.x86_64-unknown-linux-musl" \ No newline at end of file +dockerfile="cross/Dockerfile.x86_64-unknown-linux-musl" + +[target.aarch64-unknown-linux-musl] +dockerfile="cross/Dockerfile.aarch64-unknown-linux-musl" \ No newline at end of file diff --git a/cross/Dockerfile.aarch64-unknown-linux-musl b/cross/Dockerfile.aarch64-unknown-linux-musl new file mode 100644 index 00000000..ad727eaa --- /dev/null +++ b/cross/Dockerfile.aarch64-unknown-linux-musl @@ -0,0 +1,47 @@ +FROM ghcr.io/cross-rs/aarch64-unknown-linux-musl:latest + +ENV ZLIB_VERSION=1.2.13 +ENV POSTGRESQL_VERSION=11.20 +ENV OPENSSL_VERSION=1.1.1t +ENV OPENSSL_TARGET=linux-aarch64 +ENV MUSL_PREFIX=aarch64-linux-musl +ENV POSTGRESQL_HOST=aarch64-unknown-linux-must + +RUN apt-get update && \ + apt-get --assume-yes install \ + protobuf-compiler \ + libprotobuf-dev \ + binutils-aarch64-linux-gnu + +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 $OPENSSL_TARGET && \ + 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 --host $POSTGRESQL_HOST && \ + 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 /usr/aarch64-linux-gnu/bin/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/cross/Dockerfile.x86_64-unknown-linux-musl b/cross/Dockerfile.x86_64-unknown-linux-musl index 150bc89e..5907ae6b 100644 --- a/cross/Dockerfile.x86_64-unknown-linux-musl +++ b/cross/Dockerfile.x86_64-unknown-linux-musl @@ -3,17 +3,19 @@ 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 OPENSSL_TARGET=linux-x86_64 ENV MUSL_PREFIX=x86_64-linux-musl RUN apt-get update && \ apt-get --assume-yes install \ - protobuf-compiler + protobuf-compiler \ + libprotobuf-dev 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 CC=$MUSL_PREFIX-gcc ./Configure no-shared no-zlib -fPIC --prefix=/usr/local/$MUSL_PREFIX-target -DOPENSSL_NO_SECURE_MEMORY $OPENSSL_TARGET && \ env C_INCLUDE_PATH=/usr/local/$MUSL_PREFIX/include/ make depend && \ env C_INCLUDE_PATH=/usr/local/$MUSL_PREFIX/include/ make && \ make install_sw && \