From 08b42146b0927e769ede9ae4c80efe40cb539cc3 Mon Sep 17 00:00:00 2001 From: Gary Tierney Date: Sun, 9 Mar 2025 10:35:14 +0000 Subject: [PATCH] Disable dynamic CRT linkage --- .github/workflows/push.yml | 4 +++ Dockerfile | 3 +- README.md | 62 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 README.md diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index fb46497..cb8d285 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -22,8 +22,10 @@ jobs: platform: - docker: linux/amd64 runner: ubuntu-24.04 + rust: x86_64-unknown-linux-gnu - docker: linux/arm64 runner: ubuntu-24.04-arm + rust: aarch64-unknown-linux-gnu steps: - name: Prepare run: | @@ -62,6 +64,8 @@ jobs: outputs: type=image,push-by-digest=true,name-canonical=true,push=true cache-from: type=registry,ref=${{ env.REGISTRY_IMAGE }}:cache cache-to: type=inline + build-args: + TARGET=${{ matrix.platform.rust }} - name: Export digest run: | diff --git a/Dockerfile b/Dockerfile index 0d732d9..c983ecd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,13 +8,14 @@ ENV RUSTUP_HOME=/usr/local/rustup \ PATH=/usr/local/cargo/bin:$PATH \ RUST_VERSION=1.85.0 +ARG TARGET WORKDIR /work RUN --mount=type=cache,target=/usr/local/cargo/registry \ --mount=type=cache,target=/usr/local/rustup \ --mount=type=bind,target=/work,rw \ curl https://sh.rustup.rs -sSf | bash -s -- -y --default-toolchain "${RUST_VERSION}" && \ rustup install stable && \ - cargo build --locked --release && \ + RUSTFLAGS='-C target-feature=+crt-static' cargo build --locked --release --target ${TARGET} && \ mkdir /out/ && mv /work/target/${TARGET}/release/my-cpu /out/ FROM scratch diff --git a/README.md b/README.md new file mode 100644 index 0000000..91ab2f0 --- /dev/null +++ b/README.md @@ -0,0 +1,62 @@ +# my-cpu + +A utility to detect the current CPU and select a matching binary to run from the result. + +## Overview + +`my-cpu` is a tool that helps you run CPU-specific binaries by detecting the host CPU architecture and matching it against provided patterns. This is useful for running optimized binaries based on the CPU capabilities of the host system. + +## Features + +- Automatic CPU detection using LLVM +- Regular expression based matching for CPU selection +- Fallback binary support +- Command passthrough to selected binary + +## Installation + +### From Source + +```bash +cargo build --release +``` + +### Using Docker + +```bash +docker build -t my-cpu . +``` + +## Usage + +```bash +my-cpu --fallback /path/to/fallback/binary -t /path/to/binary:regex [command args...] +``` + +### Arguments + +- `--fallback `: Path to the fallback binary to be used if the CPU cannot be detected or there are no matches +- `-t, --target `: One or more target pairs specified as path to binary and a regex pattern to match against the CPU name +- `[command...]`: The command arguments to pass to the selected binary + +### Example + +```bash +my-cpu --fallback /usr/bin/app-generic \ + -t /usr/bin/app-x64-v4:x86-64-v4 \ + -t /usr/bin/app-avx512:".*avx512.*" \ + -- --some-arg value +``` + +This will: +1. Detect the current CPU +2. Try to match it against the provided patterns +3. Run the matching binary (or fallback) with the provided arguments + +## Building + +### Requirements + +- Rust 1.85.0 or later +- LLVM 19 or later +- C++ compiler