build BLAKE3 for current host

step1、安装依赖

所有时Terminal + Shell + GNU CoreUtils
下载时cURL
解压时tar + gzip
编译时gcc / GCC | Clang / LLVM
运行时
  • glibc ( libc.sold-linux-x86-64.so )

step2、使用curl命令下载BLAKE3源码包 (

curl -L -o BLAKE3-0.3.7.tar.gz https://github.com/BLAKE3-team/BLAKE3/archive/refs/tags/0.3.7.tar.gz

step3、使用tar解压BLAKE3源码包

tar vxf BLAKE3-0.3.7.tar.gz

step4、进入BLAKE3-0.3.7目录

cd BLAKE3-0.3.7

step5、查看BLAKE3-0.3.7目录的内容

注意BLAKE3分别用RustC实现。c目录中的代码就是C实现。

编译Rust实现

cargo build --locked

编译C实现

#!/bin/sh

SRCS='blake3.c blake3_dispatch.c blake3_portable.c'

DYLIB=so

BUILD_FOR_ARCH=x86_64

CFLAGS='-v'
CPPFLAGS=
LDFLAGS=

AR=ar

PREFIX=/usr/local

echo() {
    printf "%b\n" "$*"
}

run() {
    echo "$COLOR_PURPLE==>$COLOR_OFF $COLOR_GREEN$@$COLOR_OFF"
    eval "$*"
}

build_and_install() {
    case $BUILD_FOR_ARCH in
        arm*|aarch64)
            CPPFLAGS="$CPPFLAGS -DBLAKE3_USE_NEON"
            SRCS="$SRCS blake3_neon.c"
            ;;
        i386|i686)
            SRCS="$SRCS blake3_sse2.c blake3_sse41.c blake3_avx2.c blake3_avx512.c" ;;
        x86_64)
            SRCS="$SRCS blake3_sse2_x86-64_unix.S blake3_sse41_x86-64_unix.S blake3_avx2_x86-64_unix.S blake3_avx512_x86-64_unix.S" ;;
    esac

    OBJS=''

    for item in $SRCS
    do
        (
            case $item in
                blake3_sse2.c)   export CFLAGS="$CFLAGS -msse2"   ;;
                blake3_sse41.c)  export CFLAGS="$CFLAGS -msse4.1" ;;
                blake3_avx2.c)   export CFLAGS="$CFLAGS -mavx2"   ;;
                blake3_avx512.c) export CFLAGS="$CFLAGS -mavx512f -mavx512vl"
            esac
            run $CC $CFLAGS $CPPFLAGS -c -o $item.o $item || exit 1
        )
        OBJS="$item.o $OBJS"
    done

    run $CC $LDFLAGS -shared -o libblake3.$DYLIB $OBJS &&
    run $AR rsc libblake3.a $OBJS &&
    run install -d               $PREFIX/include &&
    run install blake3.h         $PREFIX/include &&
    run install -d               $PREFIX/bin &&
    run install libblake3.a      $PREFIX/bin &&
    run install libblake3.$DYLIB $PREFIX/bin &&
}

build_and_install