Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "cross" configuration for release workflow #14

Merged
merged 10 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ env:
ELIXIR_VERSION: 1.13
OTP_VERSION: 24.2
MIX_ENV: test
TOKENIZERS_BUILD: "true"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we use this anywhere?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the "native" module. We want to always force the build in the CI. See:

force_build: System.get_env("TOKENIZERS_BUILD") in ["1", "true"]


jobs:
test:
Expand Down
27 changes: 11 additions & 16 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ jobs:
os: ubuntu-20.04,
nif: "2.16",
use-cross: true,
features: "static_openssl",
}
- { target: aarch64-unknown-linux-gnu, os: ubuntu-20.04, nif: "2.16", use-cross: true }
- { target: aarch64-apple-darwin, os: macos-11, nif: "2.16" }
- { target: x86_64-apple-darwin, os: macos-11, nif: "2.16" }
- { target: x86_64-unknown-linux-gnu, os: ubuntu-20.04, nif: "2.16" }
- { target: x86_64-unknown-linux-musl, os: ubuntu-20.04, nif: "2.16", use-cross: true }
- { target: x86_64-unknown-linux-musl, os: ubuntu-20.04, nif: "2.16", use-cross: true, features: "static_openssl" }
- { target: x86_64-pc-windows-gnu, os: windows-2019, nif: "2.16" }
- { target: x86_64-pc-windows-msvc, os: windows-2019, nif: "2.16" }
# NIF version 2.15
Expand All @@ -47,26 +48,28 @@ jobs:
os: ubuntu-20.04,
nif: "2.15",
use-cross: true,
features: "static_openssl",
}
- { target: aarch64-unknown-linux-gnu, os: ubuntu-20.04, nif: "2.15", use-cross: true }
- { target: aarch64-apple-darwin, os: macos-11, nif: "2.15" }
- { target: x86_64-apple-darwin, os: macos-11, nif: "2.15" }
- { target: x86_64-unknown-linux-gnu, os: ubuntu-20.04, nif: "2.15" }
- { target: x86_64-unknown-linux-musl, os: ubuntu-20.04, nif: "2.15", use-cross: true }
- { target: x86_64-unknown-linux-musl, os: ubuntu-20.04, nif: "2.15", use-cross: true, features: "static_openssl" }
- { target: x86_64-pc-windows-gnu, os: windows-2019, nif: "2.15" }
- { target: x86_64-pc-windows-msvc, os: windows-2019, nif: "2.15" }
# # NIF version 2.14
# NIF version 2.14
- {
target: arm-unknown-linux-gnueabihf,
os: ubuntu-20.04,
nif: "2.14",
use-cross: true,
features: "static_openssl",
}
- { target: aarch64-unknown-linux-gnu, os: ubuntu-20.04, nif: "2.14", use-cross: true }
- { target: aarch64-apple-darwin, os: macos-11, nif: "2.14" }
- { target: x86_64-apple-darwin, os: macos-11, nif: "2.14" }
- { target: x86_64-unknown-linux-gnu, os: ubuntu-20.04, nif: "2.14" }
- { target: x86_64-unknown-linux-musl, os: ubuntu-20.04, nif: "2.14", use-cross: true }
- { target: x86_64-unknown-linux-musl, os: ubuntu-20.04, nif: "2.14", use-cross: true, features: "static_openssl" }
- { target: x86_64-pc-windows-gnu, os: windows-2019, nif: "2.14" }
- { target: x86_64-pc-windows-msvc, os: windows-2019, nif: "2.14" }

Expand All @@ -76,14 +79,6 @@ jobs:
- name: Checkout source code
uses: actions/checkout@v2

- name: Install prerequisites
shell: bash
run: |
case ${{ matrix.job.target }} in
arm-unknown-linux-*) sudo apt-get -y update ; sudo apt-get -y install gcc-arm-linux-gnueabihf libssl-dev openssl;;
aarch64-unknown-linux-gnu) sudo apt-get -y update ; sudo apt-get -y install gcc-aarch64-linux-gnu libssl-dev openssl;;
esac

- name: Extract crate information
shell: bash
run: |
Expand Down Expand Up @@ -115,18 +110,18 @@ jobs:
if: ${{ matrix.job.use-cross }}
with:
binary: "cross"
version: "v0.2.1"
download_url: "https://github.com/rust-embedded/cross/releases/download/${version}/cross-${version}-x86_64-unknown-linux-gnu.tar.gz"
version: "v0.2.4"
download_url: "https://github.com/cross-rs/cross/releases/download/${version}/cross-x86_64-unknown-linux-gnu.tar.gz"
tarball_binary_path: "${binary}"
smoke_test: "${binary} --version"

- name: Build
shell: bash
run: |
if [ "${{ matrix.job.use-cross }}" == "true" ]; then
cross build --release --target=${{ matrix.job.target }}
cross build --release --target=${{ matrix.job.target }} --features=${{ matrix.job.features }}
else
cargo build --release --target=${{ matrix.job.target }}
cargo build --release --target=${{ matrix.job.target }} --features=${{ matrix.job.features }}
fi

- name: Rename lib to the final name
Expand Down
11 changes: 11 additions & 0 deletions native/ex_tokenizers/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions native/ex_tokenizers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ anyhow = "1"
rustler = "0.25.0"
thiserror = "1"
tokenizers = "0.11.3"
openssl = { version = "0.10", optional = true }

[features]
static_openssl = ["openssl/vendored"]
11 changes: 11 additions & 0 deletions native/ex_tokenizers/Cross.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[build.env]
passthrough = [
"RUSTLER_NIF_VERSION"
]

# We need to install some dependencies for specific targets.
[target.arm-unknown-linux-gnueabihf]
pre-build = "./scripts/install-cross-deps"

[target.aarch64-unknown-linux-gnu]
pre-build = "./scripts/install-cross-deps"
8 changes: 8 additions & 0 deletions native/ex_tokenizers/scripts/install-cross-deps
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

# Script to install dependencies for cross compilation

dpkg --add-architecture $CROSS_DEB_ARCH

apt-get update
apt-get install --assume-yes libssl-dev:$CROSS_DEB_ARCH openssl:$CROSS_DEB_ARCH
Copy link
Member

@jonatanklosko jonatanklosko Oct 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@philss did you successfully build on arm-unknown-linux-gnueabihf and x86_64-unknown-linux-musl? When I tried that it failed for gnueabihf (I think because of cross-rs/cross#1018), while with musl I don't think there's a package available (looking here).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonatanklosko I could build for those targets locally. I'm trying to build using the CI.
Did you try to install using the "pre-build" command in the "Cross.toml" file? I also bumped cross version, so maybe this is the reason it worked for me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I did, but I may have missed something, if you can build then it's great :D

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I did, but I may have missed something, if you can build then it's great :D

Oh, I think I got it right now: https://github.com/philss/tokenizers/actions/runs/3198809038. It needs the vendored package for arm-unknown-linux-gnueabihf and x86_64-unknown-linux-musl, and we can't install the package on musl, but that works fine.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonatanklosko I think it should work good now.

Copy link
Member

@jonatanklosko jonatanklosko Oct 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, vendoring definitely works, we can even make it such that this only happens on CI via feature flags:

[dependencies]
# ...
openssl = { version = "0.10", optional = true }

[features]
static_openssl = ["openssl/vendored"]

and cross build ... --features "static_openssl"

This does link openssl statically though.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! I couldn't avoid vendoring for those targets, so I'm going to add the feature flag.