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

Detect non-default build targets for cross compilation #87

Open
Brendonovich opened this issue Mar 18, 2023 · 4 comments
Open

Detect non-default build targets for cross compilation #87

Brendonovich opened this issue Mar 18, 2023 · 4 comments

Comments

@Brendonovich
Copy link
Contributor

When compiling in GitHub Actions it's necessary to target x86_64-unknown-linux-musl, which currently can only be set using the CARGO_BUILD_TARGET environment variable - and even then, the runtime doesn't know to look in target/x86_64-unknown-linux-musl/... for build artifacts.
Detection of CARGO_BUILD_TARGET would probably be enough, idk if the runtime can be configured with CLI args or via vercel.json.

@ecklf
Copy link
Collaborator

ecklf commented Mar 28, 2023

The toolchain file should help in this scenario right? It could be created with https://github.com/marketplace/actions/create-file.

@Brendonovich
Copy link
Contributor Author

Hmmm I'm not sure that does the job. I just tried adding a rust-toolchain.toml to a project and restricted it to linux-only, but it still built and ran for macOS. Maybe I'm using it wrong?

@ecklf
Copy link
Collaborator

ecklf commented Mar 29, 2023

From what I see we'd also have to use a cargo configuration file.

https://doc.rust-lang.org/cargo/reference/config.html#configuration-format

CleanShot 2023-03-29 at 10 39 01@2x

We can also specify the target directory here to resolve the issue of resolving the build artifacts.

@arnarthor
Copy link

I ran into this issue as well.

A dirty workaround for me was to use cargo to build the project, then run rm -rf target/release && mv target/x86_64-unknown-linux-musl target/release and then run vercel build

That way I could also use the rust-cache action so my builds are pretty snappy now.

This method is obviously not ideal, but at least gets the job done for now.

Full github action workflow

name: vercel-dev

on:
  push:
    branches-ignore:
      - main

concurrency:
  group: ${{ github.ref }}
  cancel-in-progress: true

jobs:
  # rust:
  #   uses: ./.github/workflows/rust.yml
  deploy:
    runs-on: ubuntu-latest
    # needs: rust
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Rust setup
        uses: actions-rs/toolchain@v1
        with:
          target: x86_64-unknown-linux-musl
          profile: minimal
          toolchain: stable
          override: true
      - run: rustup default stable-x86_64-unknown-linux-musl
      - name: Rust cache
        uses: Swatinem/rust-cache@v2
      - name: Rust build
        uses: actions-rs/cargo@v1
        with:
          command: build
          args: --quiet --release
      - run: rm -rf target/release && mv target/x86_64-unknown-linux-musl/release target/release/
      - name: Vercel build
        run: npm install --global vercel@canary
      - name: Pull Vercel Environment Information
        run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}
      - name: Build Project Artifacts
        run: vercel build --token=${{ secrets.VERCEL_TOKEN }}
      - name: Deploy to Vercel
        uses: amondnet/vercel-action@v25
        with:
          vercel-args: "--prebuilt"
          vercel-token: ${{ secrets.VERCEL_TOKEN }}
          github-token: ${{ secrets.GITHUB_TOKEN }}
          vercel-org-id: ${{ vars.VERCEL_ORG_ID}}
          vercel-project-id: ${{ vars.VERCEL_PROJECT_ID}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants