# Cross-compile for a specific target triplet (x86_64 by default) ARG TARGET ARG CORES=4 FROM rustembedded/cross:${TARGET}-musl # Create download directory RUN mkdir /src ### Environment # Configure compiler ENV MAKE="make -j$CORES" \ CC="musl-gcc -fPIE -pie -static" \ PREFIX=/usr/local/x86_64-linux-musl \ RUSTFLAGS="-C relocation-model=static" # Configure paths ENV PATH=$PREFIX/bin:$PATH \ C_INCLUDE_PATH=$PREFIX/include \ LD_LIBRARY_PATH=$PREFIX/lib # Configure pkg-config ENV PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig \ PKG_CONFIG_ALLOW_CROSS=true \ PKG_CONFIG_ALL_STATIC=true # Install development libraries RUN apt-get update && apt-get install -y \ bison \ flex \ musl-dev \ musl-tools ### OpenSSL ARG SSL_VER # Download OpenSSL RUN curl -sSL "https://www.openssl.org/source/openssl-${SSL_VER}.tar.gz" | tar -xzC /src # Build OpenSSL statically RUN cd "/src/openssl-${SSL_VER}" \ && ./Configure \ no-shared \ no-zlib \ -fPIC \ --prefix=$PREFIX \ --openssldir=$PREFIX/ssl \ linux-x86_64 \ && $MAKE depend \ && $MAKE \ && $MAKE install # Configure OpenSSL crate ENV OPENSSL_STATIC=true \ OPENSSL_NO_VENDOR=true ### PostgreSQL ARG PQ_VER # Download PostgreSQL RUN curl -sSL "https://ftp.postgresql.org/pub/source/v${PQ_VER}/postgresql-${PQ_VER}.tar.gz" | tar -xzC /src # Build PostgreSQL statically RUN cd "/src/postgresql-${PQ_VER}" \ && CPPFLAGS=-I$PREFIX/include LDFLAGS="-L$PREFIX/lib" \ ./configure \ --with-openssl \ --without-readline \ --without-zlib \ --prefix=$PREFIX \ --host=$TARGET \ && ${MAKE} -C src/interfaces/libpq all-static-lib \ && ${MAKE} -C src/interfaces/libpq install-lib-pc \ && ${MAKE} -C src/interfaces/libpq install-lib-static \ && ${MAKE} -C src/bin/pg_config \ && ${MAKE} -C src/bin/pg_config install