Skip to content

Commit

Permalink
Disable dynamic CRT linkage
Browse files Browse the repository at this point in the history
  • Loading branch information
garyttierney committed Mar 9, 2025
1 parent e371c3e commit 08b4214
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down Expand Up @@ -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: |
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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>`: Path to the fallback binary to be used if the CPU cannot be detected or there are no matches
- `-t, --target <PATH:REGEX>`: 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

0 comments on commit 08b4214

Please sign in to comment.