diff --git a/.cargo/config.toml b/.cargo/config.toml index 95be821..d2be771 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -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", ] @@ -71,6 +71,7 @@ # Frontend of program [target.wasm32-unknown-unknown] + linker="wasm-ld" rustflags=[ "-Clink-arg=--max-memory=4294967296", "-Ctarget-feature=+atomics,+simd128", diff --git a/build_mimalloc.sh b/build_mimalloc.sh index 64d0d70..cfe2fb4 100755 --- a/build_mimalloc.sh +++ b/build_mimalloc.sh @@ -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 \ No newline at end of file +echo "Copying $OUT_OBJECT --> $LINK_LIBS/$OBJECT" +cp -f "$OUT_OBJECT" $LINK_LIBS/$OBJECT \ No newline at end of file