diff --git a/.changes/before-script-envs.md b/.changes/before-script-envs.md index 792f21f9d..0f474da88 100644 --- a/.changes/before-script-envs.md +++ b/.changes/before-script-envs.md @@ -2,4 +2,4 @@ "cli.rs": patch --- -Define `PLATFORM`, `ARCH`, `FAMILY` and `PLATFORM_TYPE` environment variables for the `beforeDevCommand` and `beforeBuildCommand` scripts. +Define `PLATFORM`, `ARCH`, `FAMILY`, `PLATFORM_TYPE` and `TAURI_DEBUG` environment variables for the `beforeDevCommand` and `beforeBuildCommand` scripts. diff --git a/tooling/cli.rs/config_definition.rs b/tooling/cli.rs/config_definition.rs index 50794091f..54ed08a6c 100644 --- a/tooling/cli.rs/config_definition.rs +++ b/tooling/cli.rs/config_definition.rs @@ -820,11 +820,11 @@ pub struct BuildConfig { pub dist_dir: AppUrl, /// A shell command to run before `tauri dev` kicks in. /// - /// The PLATFORM, ARCH, FAMILY and PLATFORM_TYPE environment variables are set if you perform conditional compilation. + /// The PLATFORM, ARCH, FAMILY, PLATFORM_TYPE and TAURI_DEBUG environment variables are set if you perform conditional compilation. pub before_dev_command: Option, /// A shell command to run before `tauri build` kicks in. /// - /// The PLATFORM, ARCH, FAMILY and PLATFORM_TYPE environment variables are set if you perform conditional compilation. + /// The PLATFORM, ARCH, FAMILY, PLATFORM_TYPE and TAURI_DEBUG environment variables are set if you perform conditional compilation. pub before_build_command: Option, /// Features passed to `cargo` commands. pub features: Option>, diff --git a/tooling/cli.rs/schema.json b/tooling/cli.rs/schema.json index 607460c46..4210d79be 100644 --- a/tooling/cli.rs/schema.json +++ b/tooling/cli.rs/schema.json @@ -261,14 +261,14 @@ "type": "object", "properties": { "beforeBuildCommand": { - "description": "A shell command to run before `tauri build` kicks in.\n\nThe PLATFORM, ARCH, FAMILY and PLATFORM_TYPE environment variables are set if you perform conditional compilation.", + "description": "A shell command to run before `tauri build` kicks in.\n\nThe PLATFORM, ARCH, FAMILY, PLATFORM_TYPE and TAURI_DEBUG environment variables are set if you perform conditional compilation.", "type": [ "string", "null" ] }, "beforeDevCommand": { - "description": "A shell command to run before `tauri dev` kicks in.\n\nThe PLATFORM, ARCH, FAMILY and PLATFORM_TYPE environment variables are set if you perform conditional compilation.", + "description": "A shell command to run before `tauri dev` kicks in.\n\nThe PLATFORM, ARCH, FAMILY, PLATFORM_TYPE and TAURI_DEBUG environment variables are set if you perform conditional compilation.", "type": [ "string", "null" diff --git a/tooling/cli.rs/src/build.rs b/tooling/cli.rs/src/build.rs index 48e0d5660..0fe0d3a9c 100644 --- a/tooling/cli.rs/src/build.rs +++ b/tooling/cli.rs/src/build.rs @@ -91,7 +91,7 @@ impl Build { .arg("/C") .arg(before_build) .current_dir(app_dir()) - .envs(command_env()), + .envs(command_env(self.debug)), ) .with_context(|| format!("failed to run `{}` with `cmd /C`", before_build))?; #[cfg(not(target_os = "windows"))] @@ -100,7 +100,7 @@ impl Build { .arg("-c") .arg(before_build) .current_dir(app_dir()) - .envs(command_env()), + .envs(command_env(self.debug)), ) .with_context(|| format!("failed to run `{}` with `sh -c`", before_build))?; } diff --git a/tooling/cli.rs/src/dev.rs b/tooling/cli.rs/src/dev.rs index 0ff88fca9..ef738cbee 100644 --- a/tooling/cli.rs/src/dev.rs +++ b/tooling/cli.rs/src/dev.rs @@ -142,7 +142,7 @@ impl Dev { .arg("/C") .arg(before_dev) .current_dir(app_dir()) - .envs(command_env()) + .envs(command_env(true)) // development build always includes debug information .spawn() .with_context(|| format!("failed to run `{}` with `cmd /C`", before_dev))?; #[cfg(not(target_os = "windows"))] @@ -150,7 +150,7 @@ impl Dev { .arg("-c") .arg(before_dev) .current_dir(app_dir()) - .envs(command_env()) + .envs(command_env(true)) // development build always includes debug information .spawn() .with_context(|| format!("failed to run `{}` with `sh -c`", before_dev))?; BEFORE_DEV.set(Mutex::new(child)).unwrap(); diff --git a/tooling/cli.rs/src/helpers/mod.rs b/tooling/cli.rs/src/helpers/mod.rs index 10ee5b6f0..63e998a05 100644 --- a/tooling/cli.rs/src/helpers/mod.rs +++ b/tooling/cli.rs/src/helpers/mod.rs @@ -41,8 +41,9 @@ pub fn execute_with_output(cmd: &mut Command) -> crate::Result<()> { } } -pub fn command_env() -> HashMap { +pub fn command_env(debug: bool) -> HashMap { let mut map = HashMap::new(); + map.insert("PLATFORM".into(), std::env::consts::OS.into()); map.insert("ARCH".into(), std::env::consts::ARCH.into()); map.insert("FAMILY".into(), std::env::consts::FAMILY.into()); @@ -55,6 +56,10 @@ pub fn command_env() -> HashMap { #[cfg(target_os = "macos")] map.insert("PLATFORM_TYPE".into(), "Darwing".into()); + if debug { + map.insert("TAURI_DEBUG".into(), "true".to_string()); + } + map }