actions-rs / cargo

šŸ“¦ GitHub Action for Rust `cargo` command
https://github.com/marketplace/actions/rust-cargo
MIT License
644 stars 60 forks source link

Using cross with additional libraries #115

Open kpcyrd opened 4 years ago

kpcyrd commented 4 years ago

Do the checklist before filing an issue:

Motivation

I'm currently using github actions to test-build my project with for x86_64. I'd like to extend this to other architectures, and there's an example in the README on how to do that. I've tried to use that for my project, but then noticed the build fails my project depends on additional libaries that are missing in the cross build container. This is related to https://github.com/rust-embedded/cross/issues/149 but it's unclear how to use the hacks mentioned in the issue with github actions.

Workflow example

I don't know what's the best way to integrate this, and I assume it'd need proper support by cross.

on: [push]

name: ARMv7 build

jobs:
  linux_arm7:
    name: Linux ARMv7
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          target: armv7-unknown-linux-gnueabihf
          override: true
      # prepare container image somehow
      - uses: actions-rs/cargo@v1
        with:
          apt:
          - libpcap-dev
          - libseccomp-dev
      - uses: actions-rs/cargo@v1
        with:
          use-cross: true
          command: build
          args: --target armv7-unknown-linux-gnueabihf

Additional context

I wrote this script in an attempt to apply the workarounds mentioned in the cross issue tracker, but couldn't get it to work because I need to have the cross binary in advance to detect the version for the image I'm preparing (therefore this is all untested):

#!/bin/sh
set -xe

case "$1" in
    arm-*)
        ARCH=arm64
        ;;
    armv7-*)
        ARCH=arm64
        ;;
    aarch64-*)
        ARCH=arm64
        ;;
    i686-*)
        ARCH=i386
        ;;
    *)
        echo 'ERROR: unknown arch'
        exit 1
        ;;
esac

CROSS=`cross -V | sed -nr 's/cross (.*)/\1/p'`

cat > Dockerfile.cross <<EOF
FROM rustembedded/cross:$1-$CROSS
RUN dpkg --add-architecture $ARCH && \
    apt-get update && \
    apt-get install libpcap-dev:$ARCH libseccomp-dev:$ARCH
EOF

docker build -t "rustembedded/cross:$1-$CROSS" Dockerfile.cross
Animeshz commented 3 years ago

Any updates? šŸ‘€ (Also: is there a way to run a few startup shell commands in the docker image before we proceed to the compilation? instead of creating and maintaining a new docker image?)

wcampbell0x2a commented 2 years ago

I would also like this feature for the same use case as above of needing an external library to compile my code.

Emilgardis commented 2 years ago

cc https://github.com/cross-rs/cross/pull/635