-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df00945
commit 61e1081
Showing
5 changed files
with
42 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM rust:alpine | ||
FROM alpine:edge | ||
|
||
COPY build.sh mimalloc.diff /tmp/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,26 @@ | ||
# `rust-alpine-mimalloc` | ||
|
||
This Docker image builds upon the official `rust:alpine` image and | ||
replaces the default musl malloc implementation with | ||
[`mimalloc`](https://github.com/microsoft/mimalloc). If you build Rust | ||
or C/C++ static executables in this image, the resulting executables | ||
will automatically link with `mimalloc` without needing any special | ||
build flags. | ||
|
||
Supported & tested archs: `amd64` and `arm64v8`. | ||
This Docker image builds upon the `alpine:edge` image, provides | ||
`cargo`/`rustc` and replaces the default musl malloc implementation | ||
with [`mimalloc`](https://github.com/microsoft/mimalloc). If you build | ||
Rust or C/C++ static executables in this image, the resulting | ||
executables will automatically link with `mimalloc` without needing | ||
any special build flags. | ||
|
||
Notice: we switched away from `rust:alpine` and now uses | ||
`cargo`/`rust` packaged by alpine. Statically linked executables will | ||
continue to link against `mimalloc` as intended, but you need extra | ||
command-line arguments to ensure they are indeed static: | ||
|
||
```sh | ||
$ RUSTFLAGS="-C target-feature=+crt-static" cargo install --target x86_64-alpine-linux-musl foo | ||
``` | ||
|
||
The `--target` flag is required. The default target is either | ||
`x86_64-alpine-linux-musl` or `aarch64-alpine-linux-musl`, and can | ||
also be extracted from `$(rustc -vV | sed -n "s|host: ||p")`. | ||
|
||
Supported & tested archs: `amd64` and `arm64/v8`. | ||
|
||
For more details, see this [blog | ||
post](https://www.tweag.io/blog/2023-08-10-rust-static-link-with-mimalloc). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,9 @@ apk upgrade --no-cache | |
|
||
apk add --no-cache \ | ||
alpine-sdk \ | ||
cargo \ | ||
cmake \ | ||
curl \ | ||
mold \ | ||
samurai | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/sh | ||
|
||
set -eu | ||
|
||
TARGET=$(rustc -vV | sed -n "s|host: ||p") | ||
|
||
RUSTFLAGS="-C target-feature=+crt-static" exec cargo install --root "$PWD" --target "$TARGET" names |