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

ci: Build prqlc-clib as artifacts #4075

Merged
merged 12 commits into from
Jan 13, 2024
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
97 changes: 97 additions & 0 deletions .github/actions/build-prqlc-clib/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: build-prqlc-clib
description: >
A version of `build-prqlc` for the C bindings.

Note that this is quite open to change, including names and which files we
package. Contributions and/or suggestions are welcome.

inputs:
target:
description: Build target
required: true
profile:
description: Build profile option; `dev` or `release`.
required: true
features:
description: Features to enable
default: ""
outputs:
artifact-name:
description: The name of the artifact
value: ${{ steps.echo-artifact-name.outputs.artifact-name }}

runs:
using: composite
steps:
- run: rustup target add ${{ inputs.target }}
shell: bash

- run: ./.github/workflows/scripts/set_version.sh
shell: bash

- uses: Swatinem/rust-cache@v2
with:
# Share cache with `test-rust`, except for `musl` targets.
save-if:
${{ (github.ref == 'refs/heads/main') && contains(inputs.target,
'musl') }}
shared-key: rust-${{ inputs.target }}
prefix-key: ${{ env.version }}

- if: runner.os == 'Linux'
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y musl-tools

- if: runner.os == 'Windows' && inputs.profile == 'release'
shell: bash
run: |
echo 'RUSTFLAGS=-Ctarget-feature=+crt-static' >>"$GITHUB_ENV"

- if: inputs.target == 'aarch64-unknown-linux-musl'
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
echo 'CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-linux-gnu-gcc' >>"$GITHUB_ENV"
echo 'CC=aarch64-linux-gnu-gcc' >>"$GITHUB_ENV"

- name: cargo build
uses: richb-hanover/[email protected]
with:
command: build
args:
--profile=${{ inputs.profile }} --locked --target=${{ inputs.target }}
--features=${{ inputs.features }} ${{ contains(inputs.target, 'musl')
&& '--package=prqlc-clib' || '--all-targets' }}

- name: Create artifact for Linux and macOS
shell: bash
if: runner.os != 'Windows'
run: |
export ARTIFACT_NAME="prqlc_lib-v${{ github.ref_type == 'tag' && github.ref_name || 0 }}-${{ matrix.target }}.tar.gz"
echo "ARTIFACT_NAME=${ARTIFACT_NAME}" >>"$GITHUB_ENV"
cd target/${{ matrix.target }}/${{ inputs.profile == 'release' && 'release' || 'debug' }}
ls -al
tar czf "../../../${ARTIFACT_NAME}" *prqlc_lib*

- name: Create artifact for Windows
shell: bash
if: runner.os == 'Windows'
run: |
export ARTIFACT_NAME="prqlc_lib-v${{ github.ref_type == 'tag' && github.ref_name || 0 }}-${{ matrix.target }}.zip"
echo "ARTIFACT_NAME=${ARTIFACT_NAME}" >>"$GITHUB_ENV"
cd target/${{ matrix.target }}/${{ inputs.profile == 'release' && 'release' || 'debug' }}
ls -al
7z a "../../../${ARTIFACT_NAME}" *prqlc_lib*

- name: Upload prqlc-clib
uses: actions/upload-artifact@v3
with:
name: prqlc_lib-${{ inputs.target }}
path: ${{ env.ARTIFACT_NAME }}

- id: echo-artifact-name
shell: bash
run: echo "artifact-name=${{ env.ARTIFACT_NAME }}" >>"$GITHUB_OUTPUT"
3 changes: 3 additions & 0 deletions .github/actions/build-prqlc/action.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: build-prqlc
description: >
Build prqlc

Note that much of this is copy/pasted into build-prqlc-clib, so changes here
should generally be copied into that file.
inputs:
target:
description: Build target
Expand Down
34 changes: 34 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,40 @@ jobs:
append_body: true
files: ${{ steps.build-artifact.outputs.artifact-name }}

build-prqlc_lib:
# Currently a copy/paste of `build-prqlc`.
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
- os: ubuntu-latest
target: aarch64-unknown-linux-musl
- os: macos-latest
target: x86_64-apple-darwin
- os: macos-latest
target: aarch64-apple-darwin
- os: windows-latest
target: x86_64-pc-windows-msvc
permissions:
contents: write
steps:
- name: 📂 Checkout code
uses: actions/checkout@v4
- uses: ./.github/actions/build-prqlc-clib
id: build-artifact
with:
target: ${{ matrix.target }}
profile: release
- name: Upload release artifact
if: github.event_name == 'release'
uses: softprops/action-gh-release@v1
with:
append_body: true
files: ${{ steps.build-artifact.outputs.artifact-name }}

winget-release:
runs-on: ubuntu-latest
needs: build-prqlc
Expand Down
34 changes: 34 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,40 @@ jobs:
RUSTFLAGS: "-C debuginfo=0"
RUSTDOCFLAGS: "-Dwarnings"

build-prqlc-clib:
runs-on: ${{ matrix.os }}
needs: rules
if: needs.rules.outputs.rust == 'true' || needs.rules.outputs.main == 'true'
strategy:
fail-fast: false
matrix:
include:
# Match the features with the available caches from tests
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
features: default
- os: macos-latest
target: x86_64-apple-darwin
features: default,test-dbs
- os: windows-latest
target: x86_64-pc-windows-msvc
features: default
steps:
- name: 📂 Checkout code
uses: actions/checkout@v4
- uses: ./.github/actions/build-prqlc-clib
with:
target: ${{ matrix.target }}
profile: dev
features: ${{ matrix.features }}
# These are the same env variables as in `test-rust.yaml`. Custom actions
# don't allow setting env variables for the whole job, so we do it here.
env:
CARGO_TERM_COLOR: always
CLICOLOR_FORCE: 1
RUSTFLAGS: "-C debuginfo=0"
RUSTDOCFLAGS: "-Dwarnings"

create-issue-on-nightly-failure:
runs-on: ubuntu-latest
needs:
Expand Down
7 changes: 7 additions & 0 deletions prqlc/bindings/clib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ repository.workspace = true
rust-version.workspace = true
version.workspace = true

# This means we can build with `--features=default`, which can make builds more generic
[features]
default = []

[lib]
# We produce both of these at the moment, but could consider refining this. ref
# https://github.com/rust-lang/cargo/issues/8607 &
# https://github.com/rust-lang/rust/issues/59302
crate_type = ["staticlib", "cdylib"]
doctest = false
name = "prqlc_lib"
Expand Down
Loading