cargo icon indicating copy to clipboard operation
cargo copied to clipboard

Using cross with additional libraries

Open kpcyrd opened this issue 4 years ago • 3 comments

Do the checklist before filing an issue:

  • [X] Is this related to the actions-rs Actions? If you think it's a problem related to Github Actions in general, use GitHub Community forum instead: https://github.community
  • [X] You've read the Contributing section about feature requests: https://github.com/actions-rs/.github/blob/master/CONTRIBUTING.md#feature-requests
  • [ ] Is this something you can debug and fix? Send a pull request! Bug fixes and documentation fixes are welcome.

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

kpcyrd avatar Oct 03 '20 02:10 kpcyrd

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?)

Animeshz avatar Oct 09 '21 10:10 Animeshz

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

wcampbell0x2a avatar Dec 28 '21 16:12 wcampbell0x2a

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

Emilgardis avatar Apr 04 '22 15:04 Emilgardis