summaryrefslogtreecommitdiffstats
path: root/pkgs/build-support/rust/hooks/maturin-build-hook.sh
blob: 3f4625a4bc3203c39e615a98bce7cfaff29d06d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# shellcheck shell=bash disable=SC2154,SC2164

maturinBuildHook() {
    echo "Executing maturinBuildHook"

    runHook preBuild

    # Put the wheel to dist/ so that regular Python tooling can find it.
    local dist="$PWD/dist"

    if [ -n "${buildAndTestSubdir-}" ]; then
        pushd "${buildAndTestSubdir}"
    fi

    # This is a huge hack, but it's the least invasive way
    # to get the required interpreter name for maturin.
    local interpreter_path="$(command -v python3 || command -v pypy3)"
    local interpreter_name="$($interpreter_path -c 'import os; import sysconfig; print(os.path.basename(sysconfig.get_config_var('\''INCLUDEPY'\'')))')"

    local flagsArray=(
        "--jobs=$NIX_BUILD_CORES"
        "--offline"
        "--target" "@rustcTargetSpec@"
        "--manylinux" "off"
        "--strip"
        "--out" "$dist"
        "--interpreter" "$interpreter_name"
    )

    if [ -n "${maturinBuildProfile}" ]; then
      flagsArray+=("--profile" "${maturinBuildProfile}")
    else
      flagsArray+=("--release")
    fi

    concatTo flagsArray maturinBuildFlags

    echoCmd 'maturinBuildHook flags' "${flagsArray[@]}"
    @setEnv@ maturin build "${flagsArray[@]}"

    if [ -n "${buildAndTestSubdir-}" ]; then
        popd
    fi

    # These are python build hooks and may depend on ./dist
    runHook postBuild

    echo "Finished maturinBuildHook"
}

buildPhase=maturinBuildHook