1 # shellcheck shell=bash disable=SC2034,SC2154,SC2164
4 export dontCargoBuild
=true
5 export dontCargoInstall
=true
8 echo "Executing tauriBuildHook"
12 ## The following is lifted from rustPlatform.cargoBuildHook
13 ## As we're replacing it, we should also be respecting its options.
15 # Account for running outside of mkRustPackage where this may not be set
16 cargoBuildType
="${cargoBuildType:-release}"
18 # Let stdenv handle stripping, for consistency and to not break
20 export "CARGO_PROFILE_${cargoBuildType@U}_STRIP"=false
22 if [ -n "${buildAndTestSubdir-}" ]; then
23 # ensure the output doesn't end up in the subdirectory
24 CARGO_TARGET_DIR
="$(pwd)/target"
25 export CARGO_TARGET_DIR
27 # Tauri doesn't respect $CARGO_TARGET_DIR, but does respect the cargo
28 # argument...but that doesn't respect `--target`, so we have to use the
30 # https://github.com/tauri-apps/tauri/issues/10190
31 printf '\nbuild.target-dir = "%s"' "$CARGO_TARGET_DIR" >>config.toml
33 pushd "${buildAndTestSubdir}"
36 local cargoFlagsArray
=(
37 "-j" "$NIX_BUILD_CORES"
38 "--target" "@rustHostPlatformSpec@"
41 local tauriFlagsArray
=(
42 "--bundles" "${tauriBundleType:-@defaultTauriBundleType@}"
43 "--target" "@rustHostPlatformSpec@"
46 if [ "${cargoBuildType}" != "debug" ]; then
47 cargoFlagsArray
+=("--profile" "${cargoBuildType}")
50 if [ -n "${cargoBuildNoDefaultFeatures-}" ]; then
51 cargoFlagsArray
+=("--no-default-features")
54 if [ -n "${cargoBuildFeatures-}" ]; then
55 cargoFlagsArray
+=("--features=$(concatStringsSep "," cargoBuildFeatures)")
58 concatTo cargoFlagsArray cargoBuildFlags
60 if [ "${cargoBuildType:-}" == "debug" ]; then
61 tauriFlagsArray
+=("--debug")
64 concatTo tauriFlagsArray tauriBuildFlags
66 echoCmd
'cargo-tauri.hook cargoFlags' "${cargoFlagsArray[@]}"
67 echoCmd
'cargo-tauri.hook tauriFlags' "${tauriFlagsArray[@]}"
69 @setEnv@ cargo tauri build
"${tauriFlagsArray[@]}" -- "${cargoFlagsArray[@]}"
71 if [ -n "${buildAndTestSubdir-}" ]; then
77 echo "Finished tauriBuildHook"
81 echo "Executing tauriInstallHook"
85 # Use a nice variable for our target directory in the following script
86 targetDir
=target
/@targetSubdirectory@
/$cargoBuildType
92 echo "Finished tauriInstallHook"
95 if [ -z "${dontTauriBuild:-}" ] && [ -z "${buildPhase:-}" ]; then
96 buildPhase
=tauriBuildHook
99 if [ -z "${dontTauriInstall:-}" ] && [ -z "${installPhase:-}" ]; then
100 installPhase
=tauriInstallHook