mediawiki: 1.42.4 -> 1.43.0 (#369641)
[NixPkgs.git] / pkgs / by-name / ca / cargo-tauri / hook.sh
blobadfa24b515b8587cd0d24acd48d153fa2316064b
1 # shellcheck shell=bash disable=SC2034,SC2154,SC2164
3 # We replace these
4 export dontCargoBuild=true
5 export dontCargoInstall=true
7 tauriBuildHook() {
8 echo "Executing tauriBuildHook"
10 runHook preBuild
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
19 # separateDebugInfo.
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
29 # config file
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@"
39 "--offline"
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
72 popd
75 runHook postBuild
77 echo "Finished tauriBuildHook"
80 tauriInstallHook() {
81 echo "Executing tauriInstallHook"
83 runHook preInstall
85 # Use a nice variable for our target directory in the following script
86 targetDir=target/@targetSubdirectory@/$cargoBuildType
88 @installScript@
90 runHook postInstall
92 echo "Finished tauriInstallHook"
95 if [ -z "${dontTauriBuild:-}" ] && [ -z "${buildPhase:-}" ]; then
96 buildPhase=tauriBuildHook
99 if [ -z "${dontTauriInstall:-}" ] && [ -z "${installPhase:-}" ]; then
100 installPhase=tauriInstallHook