From 870401fd14ee4c6494012f435ac1512f0568e5ba Mon Sep 17 00:00:00 2001 From: Nghia Date: Tue, 23 Jan 2024 14:39:30 +0700 Subject: [PATCH] ci: use mold linker (#17) * ci: use lld and mold linker * install mold * use sudo * use github actions * install mold by curl * remove sudo * mold for coverage * show error * hardcode * use env * export * put in a script * relative root * not array * move to script * pre-build to build * add linker * update cross * check * check * debian * library * only cargo * cargobin * build * only linux gnu --- .cargo/config.toml | 3 +++ .github/workflows/coverage.yaml | 1 + .github/workflows/main.yaml | 4 ++++ Cross.toml | 7 ++----- ci/cross-pre-build.sh | 7 +++++++ 5 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 .cargo/config.toml create mode 100755 ci/cross-pre-build.sh diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 00000000..3c722b6e --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,3 @@ +#TODO: enable mold for other target +[target.x86_64-unknown-linux-gnu] +rustflags = ["-C", "link-arg=-fuse-ld=mold"] diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml index 780fd225..a8fec8eb 100644 --- a/.github/workflows/coverage.yaml +++ b/.github/workflows/coverage.yaml @@ -31,6 +31,7 @@ jobs: steps: - uses: actions/checkout@v4 + - uses: rui314/setup-mold@v1 - name: Install Rust run: rustup update stable - name: Install cargo-llvm-cov diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 8cba2616..449f60e9 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -47,9 +47,13 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Install mold + uses: rui314/setup-mold@v1 + if: matrix.platform.command == 'cargo' - uses: cargo-bins/cargo-binstall@main - name: Install cross run: cargo binstall cross --no-confirm + if: matrix.platform.command == 'cross' - name: Build and test run: ${{ matrix.platform.command }} test --locked --target ${{ matrix.platform.target }} diff --git a/Cross.toml b/Cross.toml index 66fb75c3..db824f24 100644 --- a/Cross.toml +++ b/Cross.toml @@ -1,8 +1,5 @@ [build.env] passthrough = ["DATABASE_URL"] -[target.aarch64-unknown-linux-gnu] -pre-build = [ - "dpkg --add-architecture $CROSS_DEB_ARCH", - "apt-get update && apt-get --assume-yes install libpq-dev:$CROSS_DEB_ARCH", -] +[build] +pre-build = "ci/cross-pre-build.sh" diff --git a/ci/cross-pre-build.sh b/ci/cross-pre-build.sh new file mode 100755 index 00000000..faba65f7 --- /dev/null +++ b/ci/cross-pre-build.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -euxo pipefail + +if [[ "$CROSS_TARGET" == "aarch64-unknown-linux-gnu" ]]; then + dpkg --add-architecture $CROSS_DEB_ARCH + apt-get update && apt-get --assume-yes install libpq-dev:$CROSS_DEB_ARCH +fi