Last active
September 15, 2024 16:30
-
-
Save marirs/d4060217348907f2ea206111e3ff512b to your computer and use it in GitHub Desktop.
Rust Cross Compile Diesel-PostgreSQL for Linux on Mac M1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Download the Source | |
```bash | |
cd /tmp/ | |
wget https://ftp.postgresql.org/pub/source/v14.2/postgresql-14.2.tar.gz | |
tar xvf postgresql-14.2.tar.gz | |
cd postgresql-14.2 | |
``` | |
# Configure | |
# - with openssl | |
```bash | |
./configure --host=x86_64-unknown-linux-gnu CC=x86_64-unknown-linux-gnu-gcc CXX=x86_64-unknown-linux-gnu-g++ AS=x86_64-unknown-linux-gnu-as AR=x86_64-unknown-linux-gnu-as AR=x86_64-unknown-linux-gnu-ar NM=x86_64-unknown-linux-gnu-nm RANLIB=x86_64-unknown-linux-gnu-gcc-ranlib LD=x86_64-unknown-linux-gnu-ld STRIP=x86_64-unknown-linux-gnu-strip --without-readline --without-zlib --with-openssl --prefix=/opt/homebrew/Cellar/postgresql/x86_64-linux-gnu/ --with-includes=/opt/homebrew/Cellar/openssl\@1.1/1.1.1n/x86_64-linux-gnu/include/ --with-libraries=/opt/homebrew/Cellar/openssl\@1.1/1.1.1n/x86_64-linux-gnu/lib/ | |
``` | |
# Configure | |
# - without openssl | |
```bash | |
./configure --host=x86_64-unknown-linux-gnu CC=x86_64-unknown-linux-gnu-gcc CXX=x86_64-unknown-linux-gnu-g++ AS=x86_64-unknown-linux-gnu-as AR=x86_64-unknown-linux-gnu-as AR=x86_64-unknown-linux-gnu-ar NM=x86_64-unknown-linux-gnu-nm RANLIB=x86_64-unknown-linux-gnu-gcc-ranlib LD=x86_64-unknown-linux-gnu-ld STRIP=x86_64-unknown-linux-gnu-strip --without-readline --without-zlib --prefix=/opt/homebrew/Cellar/postgresql/x86_64-linux-gnu/ | |
``` | |
# Assuming configure succeeds, cd into `src/interfaces/libpq` and run `make` | |
```bash | |
cd src/interfaces/libpq | |
``` | |
# Make | |
```bash | |
make -j12 | |
``` | |
# Install | |
```bash | |
make install | |
``` | |
# If the libpgcommon is required | |
```bash | |
cd ../../common/ | |
make -j12 | |
make install | |
``` | |
# if the libpgport is required | |
```bash | |
cd ../port/ | |
make -j12 | |
make install | |
``` | |
# Now you should have a linux x86_64 version of pqlib installed in: | |
# /opt/homebrew/Cellar/postgresql/x86_64-linux-gnu/ | |
### Rust Cross compile in Mac for linux | |
```bash | |
PQ_LIB_DIR=/opt/homebrew/Cellar/postgresql/x86_64-linux-gnu/lib/ PQ_INCLUDE_DIR=/opt/homebrew/Cellar/postgresql/x86_64-linux-gnu/include/ cargo b --release --target x86_64-unknown-linux-gnu | |
``` | |
# If you want to compile static | |
```bash | |
PQ_LIB_STATIC=1 PQ_LIB_DIR=/opt/homebrew/Cellar/postgresql/x86_64-linux-gnu/lib/ PQ_INCLUDE_DIR=/opt/homebrew/Cellar/postgresql/x86_64-linux-gnu/include/ cargo b --release --target x86_64-unknown-linux-gnu | |
``` | |
# if you want to strip the executable: | |
```bash | |
x86_64-unknown-linux-gnu-strip target/release/<file> | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment