Skip to content

Instantly share code, notes, and snippets.

@zhangw
Forked from marirs/rust-cross-compile-openssl
Last active February 18, 2023 05:16

Revisions

  1. zhangw revised this gist Feb 18, 2023. 1 changed file with 12 additions and 19 deletions.
    31 changes: 12 additions & 19 deletions rust-cross-compile-openssl
    Original file line number Diff line number Diff line change
    @@ -15,12 +15,15 @@ brew install openssl@1.1
    # this should get installed in:
    # /opt/homebrew/Cellar/openssl\@1.1/

    # check the openssl@1.1 specific version, current version is 1.1.1q
    # ls -alth /opt/homebrew/Cellar/openssl@1.1/1.1.1q

    # Download the OpenSSL Source
    ```bash
    cd /tmp
    wget https://www.openssl.org/source/openssl-1.1.1s.tar.gz
    tar xvf openssl-1.1.1s.tar.gz
    cd openssl-1.1.1s
    wget https://www.openssl.org/source/openssl-1.1.1q.tar.gz
    tar xvf openssl-1.1.1q.tar.gz
    cd openssl-1.1.1q
    ```

    # Configure for `Intel x86_64`
    @@ -33,7 +36,7 @@ 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" \
    ./Configure linux-x86_64 no-shared no-async --prefix=/opt/homebrew/Cellar/openssl\@1.1/1.1.1s/x86_64-linux-gnu --openssldir=/opt/homebrew/Cellar/openssl\@1.1/1.1.1s/x86_64-linux-gnu
    ./Configure linux-x86_64 no-shared no-async --prefix=/opt/homebrew/Cellar/openssl\@1.1/1.1.1q/x86_64-linux-gnu --openssldir=/opt/homebrew/Cellar/openssl\@1.1/1.1.1q/x86_64-linux-gnu
    ```

    # Configure for `aarch64`
    @@ -46,7 +49,7 @@ NM="aarch64-unknown-linux-gnu-nm" \
    RANLIB="aarch64-unknown-linux-gnu-gcc-ranlib" \
    LD="aarch64-unknown-linux-gnu-ld" \
    STRIP="aarch64-unknown-linux-gnu-strip" \
    ./Configure linux-aarch64 no-shared no-async --prefix=/opt/homebrew/Cellar/openssl\@1.1/1.1.1s/aarch64-linux-gnu --openssldir=/opt/homebrew/Cellar/openssl\@1.1/1.1.1s/aarch64-linux-gnu
    ./Configure linux-aarch64 no-shared no-async --prefix=/opt/homebrew/Cellar/openssl\@1.1/1.1.1q/aarch64-linux-gnu --openssldir=/opt/homebrew/Cellar/openssl\@1.1/1.1.1q/aarch64-linux-gnu
    ```

    # Make
    @@ -60,30 +63,20 @@ make install
    ```

    # Now you should have a linux x86_64 version of openssl installed in:
    # /opt/homebrew/Cellar/openssl\@1.1/1.1.1n/x86_64-linux-gnu
    # /opt/homebrew/Cellar/openssl\@1.1/1.1.1q/x86_64-linux-gnu
    # OR for aarch 64
    # /opt/homebrew/Cellar/openssl\@1.1/1.1.1n/aarch64-linux-gnu
    # /opt/homebrew/Cellar/openssl\@1.1/1.1.1q/aarch64-linux-gnu

    ### Rust Cross compile in Mac for linux
    # Now if you want to cross compile for linux on your mac m1 using rust with openssl or openss-sys
    # Cargo.toml - as much as possible try to use "vendored" feature in openssl - that way the openssl will not become
    # a dependancy on the target system

    ```bash
    OPENSSL_INCLUDE_DIR=`brew --prefix openssl@1.1`/x86_64-linux-gnu/include OPENSSL_LIB_DIR=`brew --prefix openssl@1.1`/x86_64-linux-gnu/lib OPENSSL_STATIC=1 cargo b --release --target x86_64-unknown-linux-gnu
    ```

    # for aarch64
    ```bash
    OPENSSL_INCLUDE_DIR=`brew --prefix openssl@1.1`/aarch64-linux-gnu/include OPENSSL_LIB_DIR=`brew --prefix openssl@1.1`/aarch64-linux-gnu/lib OPENSSL_STATIC=1 cargo b --release --target aarch64-unknown-linux-gnu
    TARGET_CC=x86_64-unknown-linux-gnu-gcc CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-unknown-linux-gnu-gcc OPENSSL_DIR=`brew --prefix openssl@1.1`/x86_64-linux-gnu OPENSSL_STATIC=1 cargo build --release --target x86_64-unknown-linux-gnu
    ```

    # if you want to strip the executable:
    ```bash
    x86_64-unknown-linux-gnu-strip target/release/<file>
    ```

    # for aarch64
    ```bash
    aarch64-unknown-linux-gnu-strip target/release/<file>
    ```
    ```
  2. @marirs marirs revised this gist Nov 20, 2022. 1 changed file with 27 additions and 2 deletions.
    29 changes: 27 additions & 2 deletions rust-cross-compile-openssl
    Original file line number Diff line number Diff line change
    @@ -23,7 +23,7 @@ tar xvf openssl-1.1.1s.tar.gz
    cd openssl-1.1.1s
    ```

    # Configure
    # Configure for `Intel x86_64`
    ```bash
    CC="x86_64-unknown-linux-gnu-gcc -fPIE -pie" \
    CXX="x86_64-unknown-linux-gnu-g++" \
    @@ -36,6 +36,19 @@ STRIP="x86_64-unknown-linux-gnu-strip" \
    ./Configure linux-x86_64 no-shared no-async --prefix=/opt/homebrew/Cellar/openssl\@1.1/1.1.1s/x86_64-linux-gnu --openssldir=/opt/homebrew/Cellar/openssl\@1.1/1.1.1s/x86_64-linux-gnu
    ```

    # Configure for `aarch64`
    ```bash
    CC="aarch64-unknown-linux-gnu-gcc -fPIE -pie" \
    CXX="aarch64-unknown-linux-gnu-g++" \
    AS="aarch64-unknown-linux-gnu-as" \
    AR="aarch64-unknown-linux-gnu-ar" \
    NM="aarch64-unknown-linux-gnu-nm" \
    RANLIB="aarch64-unknown-linux-gnu-gcc-ranlib" \
    LD="aarch64-unknown-linux-gnu-ld" \
    STRIP="aarch64-unknown-linux-gnu-strip" \
    ./Configure linux-aarch64 no-shared no-async --prefix=/opt/homebrew/Cellar/openssl\@1.1/1.1.1s/aarch64-linux-gnu --openssldir=/opt/homebrew/Cellar/openssl\@1.1/1.1.1s/aarch64-linux-gnu
    ```

    # Make
    ```bash
    make -j12
    @@ -48,6 +61,8 @@ make install

    # Now you should have a linux x86_64 version of openssl installed in:
    # /opt/homebrew/Cellar/openssl\@1.1/1.1.1n/x86_64-linux-gnu
    # OR for aarch 64
    # /opt/homebrew/Cellar/openssl\@1.1/1.1.1n/aarch64-linux-gnu

    ### Rust Cross compile in Mac for linux
    # Now if you want to cross compile for linux on your mac m1 using rust with openssl or openss-sys
    @@ -58,7 +73,17 @@ make install
    OPENSSL_INCLUDE_DIR=`brew --prefix openssl@1.1`/x86_64-linux-gnu/include OPENSSL_LIB_DIR=`brew --prefix openssl@1.1`/x86_64-linux-gnu/lib OPENSSL_STATIC=1 cargo b --release --target x86_64-unknown-linux-gnu
    ```

    # for aarch64
    ```bash
    OPENSSL_INCLUDE_DIR=`brew --prefix openssl@1.1`/aarch64-linux-gnu/include OPENSSL_LIB_DIR=`brew --prefix openssl@1.1`/aarch64-linux-gnu/lib OPENSSL_STATIC=1 cargo b --release --target aarch64-unknown-linux-gnu
    ```

    # if you want to strip the executable:
    ```bash
    x86_64-unknown-linux-gnu-strip target/release/<file>
    ```
    ```

    # for aarch64
    ```bash
    aarch64-unknown-linux-gnu-strip target/release/<file>
    ```
  3. @marirs marirs revised this gist Nov 20, 2022. No changes.
  4. @marirs marirs revised this gist Nov 20, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion rust-cross-compile-openssl
    Original file line number Diff line number Diff line change
    @@ -33,7 +33,7 @@ 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" \
    ./Configure linux-x86_64 no-shared no-async --prefix=/opt/homebrew/Cellar/openssl\@1.1/1.1.1n/x86_64-linux-gnu --openssldir=/opt/homebrew/Cellar/openssl\@1.1/1.1.1n/x86_64-linux-gnu
    ./Configure linux-x86_64 no-shared no-async --prefix=/opt/homebrew/Cellar/openssl\@1.1/1.1.1s/x86_64-linux-gnu --openssldir=/opt/homebrew/Cellar/openssl\@1.1/1.1.1s/x86_64-linux-gnu
    ```

    # Make
  5. @marirs marirs revised this gist Nov 20, 2022. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions rust-cross-compile-openssl
    Original file line number Diff line number Diff line change
    @@ -18,9 +18,9 @@ brew install openssl@1.1
    # Download the OpenSSL Source
    ```bash
    cd /tmp
    wget https://www.openssl.org/source/openssl-1.1.1n.tar.gz
    tar xvf openssl-1.1.1n.tar.gz
    cd openssl-1.1.1n
    wget https://www.openssl.org/source/openssl-1.1.1s.tar.gz
    tar xvf openssl-1.1.1s.tar.gz
    cd openssl-1.1.1s
    ```

    # Configure
  6. @marirs marirs renamed this gist Apr 24, 2022. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  7. @marirs marirs revised this gist Apr 24, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion cross-compile
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,7 @@ brew install openssl@1.1
    ```bash
    cd /tmp
    wget https://www.openssl.org/source/openssl-1.1.1n.tar.gz
    tar xvf openssl-1.1.1n.tar.gz
    tar xvf openssl-1.1.1n.tar.gz
    cd openssl-1.1.1n
    ```

  8. @marirs marirs revised this gist Apr 24, 2022. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions cross-compile
    Original file line number Diff line number Diff line change
    @@ -19,6 +19,7 @@ brew install openssl@1.1
    ```bash
    cd /tmp
    wget https://www.openssl.org/source/openssl-1.1.1n.tar.gz
    tar xvf openssl-1.1.1n.tar.gz
    cd openssl-1.1.1n
    ```

  9. @marirs marirs revised this gist Apr 24, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion cross-compile
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    # Install the toolchain
    ```
    ```bash
    brew tap SergioBenitez/osxct
    brew install x86_64-unknown-linux-gnu
    ```
  10. @marirs marirs created this gist Apr 24, 2022.
    63 changes: 63 additions & 0 deletions cross-compile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,63 @@
    # Install the toolchain
    ```
    brew tap SergioBenitez/osxct
    brew install x86_64-unknown-linux-gnu
    ```

    # this should get installed in:
    # /opt/homebrew/Cellar/x86_64-unknown-linux-gnu/

    # Installing the macOS OpenSSL - if not already installed
    ```bash
    brew install openssl@1.1
    ```

    # this should get installed in:
    # /opt/homebrew/Cellar/openssl\@1.1/

    # Download the OpenSSL Source
    ```bash
    cd /tmp
    wget https://www.openssl.org/source/openssl-1.1.1n.tar.gz
    cd openssl-1.1.1n
    ```

    # Configure
    ```bash
    CC="x86_64-unknown-linux-gnu-gcc -fPIE -pie" \
    CXX="x86_64-unknown-linux-gnu-g++" \
    AS="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" \
    ./Configure linux-x86_64 no-shared no-async --prefix=/opt/homebrew/Cellar/openssl\@1.1/1.1.1n/x86_64-linux-gnu --openssldir=/opt/homebrew/Cellar/openssl\@1.1/1.1.1n/x86_64-linux-gnu
    ```

    # Make
    ```bash
    make -j12
    ```

    # Install
    ```bash
    make install
    ```

    # Now you should have a linux x86_64 version of openssl installed in:
    # /opt/homebrew/Cellar/openssl\@1.1/1.1.1n/x86_64-linux-gnu

    ### Rust Cross compile in Mac for linux
    # Now if you want to cross compile for linux on your mac m1 using rust with openssl or openss-sys
    # Cargo.toml - as much as possible try to use "vendored" feature in openssl - that way the openssl will not become
    # a dependancy on the target system

    ```bash
    OPENSSL_INCLUDE_DIR=`brew --prefix openssl@1.1`/x86_64-linux-gnu/include OPENSSL_LIB_DIR=`brew --prefix openssl@1.1`/x86_64-linux-gnu/lib OPENSSL_STATIC=1 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>
    ```