cargo-binstall/.github/actions/just-setup/action.yml
Jiahao XU 04d28b1f5c
CI: Fix just-setup (#1957)
* Fix just-setup

 - install rust toolchain before calling install-action, just in case there's no available binary
 - configure THP/malloc at the start of action

Signed-off-by: Jiahao XU <30436523+NobodyXu@users.noreply.github.com>

* Fix rust installation

Signed-off-by: Jiahao XU <30436523+NobodyXu@users.noreply.github.com>

* Fix target passed to install-action

Signed-off-by: Jiahao XU <30436523+NobodyXu@users.noreply.github.com>

* Add missing shell

Signed-off-by: Jiahao XU <30436523+NobodyXu@users.noreply.github.com>

* Fix typo

Signed-off-by: Jiahao XU <30436523+NobodyXu@users.noreply.github.com>

* Fix passing target to install-action

Signed-off-by: Jiahao XU <30436523+NobodyXu@users.noreply.github.com>

---------

Signed-off-by: Jiahao XU <30436523+NobodyXu@users.noreply.github.com>
2024-11-05 10:30:30 +00:00

156 lines
4.6 KiB
YAML

name: Setup tools and cache
inputs:
tools:
description: Extra tools
required: false
default: ""
indexcache:
description: Enable index cache
required: true
default: true
type: boolean
buildcache:
description: Enable build cache
required: true
default: true
type: boolean
runs:
using: composite
steps:
- name: Enable macOS developer mode for better
if: runner.os == 'macOS'
run: sudo spctl developer-mode enable-terminal
shell: bash
- name: Enable transparent huge page
if: runner.os == 'Linux'
run: echo madvise | sudo tee /sys/kernel/mm/transparent_hugepage/enabled
shell: bash
- name: Configure jemalloc (used by rustc) to use transparent huge page
if: runner.os == 'Linux'
run: echo "MALLOC_CONF=thp:always,metadata_thp:always" >> "$GITHUB_ENV"
shell: bash
- name: Exclude workspace and cargo/rustup home from windows defender
if: runner.os == 'Windows'
run: |
Add-MpPreference -ExclusionPath '${{ github.workspace }}'
shell: pwsh
- name: Add just to tools to install
run: echo "tools=just" >>"$GITHUB_ENV"
shell: bash
- name: Add inputs.tools to tools to install
if: inputs.tools != ''
env:
inputs_tools: ${{ inputs.tools }}
run: echo "tools=$tools,$inputs_tools" >>"$GITHUB_ENV"
shell: bash
- name: Determine native target
run: |
if [ "$RUNNER_OS" = "Linux" ]; then RUNNER_TARGET=x86_64-unknown-linux-gnu; fi
if [ "$RUNNER_OS" = "macOS" ]; then RUNNER_TARGET=aarch64-apple-darwin; fi
if [ "$RUNNER_OS" = "Windows" ]; then RUNNER_TARGET=x86_64-pc-windows-msvc; fi
echo "RUNNER_TARGET=$RUNNER_TARGET" >>"$GITHUB_ENV"
shell: bash
- name: Install tools
uses: taiki-e/install-action@v2
with:
tool: ${{ env.tools }}
env:
CARGO_BUILD_TARGET: ${{ env.RUNNER_TARGET }}
- name: Install rust toolchains
run: just toolchain
shell: bash
- name: rustc version
run: rustc -vV
shell: bash
- name: Retrieve RUSTFLAGS for caching
if: inputs.indexcache || inputs.buildcache
id: retrieve-rustflags
run: |
if [ -n "${{ inputs.buildcache }}" ]; then
echo RUSTFLAGS="$(just print-rustflags)" >> "$GITHUB_OUTPUT"
else
echo RUSTFLAGS= >> "$GITHUB_OUTPUT"
fi
shell: bash
- run: just ci-install-deps
shell: bash
- if: inputs.indexcache || inputs.buildcache
uses: Swatinem/rust-cache@v2
with:
env-vars: "CARGO CC CFLAGS CXX CMAKE RUST JUST"
env:
RUSTFLAGS: ${{ steps.retrieve-rustflags.outputs.RUSTFLAGS }}
- name: Find zig location and create symlink to it in ~/.local/bin
if: env.JUST_USE_CARGO_ZIGBUILD
run: |
python_package_path=$(python3 -m site --user-site)
ln -s "${python_package_path}/ziglang/zig" "$HOME/.local/bin/zig"
shell: bash
- name: Calculate zig cache key
if: env.JUST_USE_CARGO_ZIGBUILD
run: |
ZIG_VERSION=$(zig version)
SYS_CRATE_HASHSUM=$(cargo tree --all-features --prefix none --no-dedupe --target "$CARGO_BUILD_TARGET" | grep -e '-sys' -e '^ring' | sort -u | sha1sum | sed 's/[ -]*//g')
PREFIX=v0-${JOB_ID}-zig-${ZIG_VERSION}-${CARGO_BUILD_TARGET}-
echo "ZIG_CACHE_KEY=${PREFIX}${SYS_CRATE_HASHSUM}" >> "$GITHUB_ENV"
echo -e "ZIG_CACHE_RESTORE_KEY=$PREFIX" >> "$GITHUB_ENV"
shell: bash
env:
RUSTFLAGS: ${{ steps.retrieve-rustflags.outputs.RUSTFLAGS }}
JOB_ID: ${{ github.job }}
- name: Get zig global cache dir
if: env.JUST_USE_CARGO_ZIGBUILD
id: zig_global_cache_dir_path
run: |
cache_dir=$(zig env | jq -r '.global_cache_dir')
echo "cache_dir=$cache_dir" >> "$GITHUB_OUTPUT"
shell: bash
- name: Cache zig compilation
if: env.JUST_USE_CARGO_ZIGBUILD
uses: actions/cache@v4
with:
path: ${{ steps.zig_global_cache_dir_path.outputs.cache_dir }}
key: ${{ env.ZIG_CACHE_KEY }}
restore-keys: |
${{ env.ZIG_CACHE_RESTORE_KEY }}
- name: Cache make compiled
if: runner.os == 'macOS'
id: cache-make
uses: actions/cache@v4
with:
path: /usr/local/bin/make
key: ${{ runner.os }}-make-4.4.1
- name: Build and use make 4.4.1 on macOS, since cc requires make >=4.3
if: runner.os == 'macOS' && steps.cache-make.outputs.cache-hit != 'true'
run: |
curl "https://ftp.gnu.org/gnu/make/make-${MAKE_VERSION}.tar.gz" | tar xz
pushd "make-${MAKE_VERSION}"
./configure
make -j 4
popd
cp -p "make-${MAKE_VERSION}/make" /usr/local/bin
env:
MAKE_VERSION: 4.4.1
shell: bash
- run: make -v
shell: bash