Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"-Clinker-plugin-lto",
"-Clink-arg=-fuse-ld=mold",
"-Clink-arg=-flto",
"-Zpre-link-args=link_libs/mimalloc.o",
"-Zpre-link-args=target/link_libs/mimalloc.o",
]


Expand All @@ -71,6 +71,7 @@

# Frontend of program
[target.wasm32-unknown-unknown]
linker="wasm-ld"
rustflags=[
"-Clink-arg=--max-memory=4294967296",
"-Ctarget-feature=+atomics,+simd128",
Expand Down
42 changes: 31 additions & 11 deletions build_mimalloc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,50 @@ set -eu
# If none is supplied, use the default "2.2.7".
MIMALLOC_VERSION=${1:-2.2.7}

# Fetch mimalloc source files
curl -f -L --retry 5 https://github.com/microsoft/mimalloc/archive/refs/tags/v$MIMALLOC_VERSION.tar.gz | tar xz
ROOT="target"
MI_PATH="$ROOT/mimalloc-$MIMALLOC_VERSION"
OUT_PATH="$MI_PATH/out"
OBJECT="mimalloc.o"
OUT_OBJECT="$OUT_PATH/$OBJECT"
LINK_LIBS="$ROOT/link_libs"

cd mimalloc-$MIMALLOC_VERSION

mkdir out
if [[ -e $OUT_OBJECT ]]; then
echo "Mimalloc v$MIMALLOC_VERSION already installed"
exit 0
fi

mkdir -p "$ROOT"

if [[ ! -d "$MI_PATH" ]]; then
cd "$ROOT"

# Fetch mimalloc source files
echo "Downloading mimalloc v$MIMALLOC_VERSION source files"
curl -f -L --retry 5 https://github.com/microsoft/mimalloc/archive/refs/tags/v$MIMALLOC_VERSION.tar.gz | tar xz

cd ..
fi


mkdir -p "$OUT_PATH"

# Create mimalloc build files with the following settings
cmake -Bout -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=clang \
cmake -B"$OUT_PATH" -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=clang \
-DMI_SECURE=OFF \
-DMI_BUILD_OBJECT=ON \
-DMI_BUILD_TESTS=OFF \
-DMI_DEBUG_FULL=OFF \
-DMI_LIBC_MUSL=ON \
-G Ninja \
.
"$MI_PATH"

# Build mimalloc
cmake --build out

cd ..
cmake --build "$OUT_PATH"

# Create directory if it doesn't already exist
mkdir -p link_libs
mkdir -p "$LINK_LIBS"

# Create a copy of mimalloc. Used to prelink mimalloc in .cargo/config.toml
cp -f mimalloc-$MIMALLOC_VERSION/out/mimalloc.o link_libs/mimalloc.o
echo "Copying $OUT_OBJECT --> $LINK_LIBS/$OBJECT"
cp -f "$OUT_OBJECT" $LINK_LIBS/$OBJECT