Skip to content

Commit b5ee03a

Browse files
feat(cli.rs): expose debug flag to beforeDev/beforeBuild commands (#2727)
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
1 parent 53fdfe5 commit b5ee03a

File tree

6 files changed

+15
-10
lines changed

6 files changed

+15
-10
lines changed

.changes/before-script-envs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"cli.rs": patch
33
---
44

5-
Define `PLATFORM`, `ARCH`, `FAMILY` and `PLATFORM_TYPE` environment variables for the `beforeDevCommand` and `beforeBuildCommand` scripts.
5+
Define `PLATFORM`, `ARCH`, `FAMILY`, `PLATFORM_TYPE` and `TAURI_DEBUG` environment variables for the `beforeDevCommand` and `beforeBuildCommand` scripts.

tooling/cli.rs/config_definition.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -820,11 +820,11 @@ pub struct BuildConfig {
820820
pub dist_dir: AppUrl,
821821
/// A shell command to run before `tauri dev` kicks in.
822822
///
823-
/// The PLATFORM, ARCH, FAMILY and PLATFORM_TYPE environment variables are set if you perform conditional compilation.
823+
/// The PLATFORM, ARCH, FAMILY, PLATFORM_TYPE and TAURI_DEBUG environment variables are set if you perform conditional compilation.
824824
pub before_dev_command: Option<String>,
825825
/// A shell command to run before `tauri build` kicks in.
826826
///
827-
/// The PLATFORM, ARCH, FAMILY and PLATFORM_TYPE environment variables are set if you perform conditional compilation.
827+
/// The PLATFORM, ARCH, FAMILY, PLATFORM_TYPE and TAURI_DEBUG environment variables are set if you perform conditional compilation.
828828
pub before_build_command: Option<String>,
829829
/// Features passed to `cargo` commands.
830830
pub features: Option<Vec<String>>,

tooling/cli.rs/schema.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,14 @@
261261
"type": "object",
262262
"properties": {
263263
"beforeBuildCommand": {
264-
"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.",
264+
"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.",
265265
"type": [
266266
"string",
267267
"null"
268268
]
269269
},
270270
"beforeDevCommand": {
271-
"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.",
271+
"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.",
272272
"type": [
273273
"string",
274274
"null"

tooling/cli.rs/src/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl Build {
9191
.arg("/C")
9292
.arg(before_build)
9393
.current_dir(app_dir())
94-
.envs(command_env()),
94+
.envs(command_env(self.debug)),
9595
)
9696
.with_context(|| format!("failed to run `{}` with `cmd /C`", before_build))?;
9797
#[cfg(not(target_os = "windows"))]
@@ -100,7 +100,7 @@ impl Build {
100100
.arg("-c")
101101
.arg(before_build)
102102
.current_dir(app_dir())
103-
.envs(command_env()),
103+
.envs(command_env(self.debug)),
104104
)
105105
.with_context(|| format!("failed to run `{}` with `sh -c`", before_build))?;
106106
}

tooling/cli.rs/src/dev.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,15 @@ impl Dev {
142142
.arg("/C")
143143
.arg(before_dev)
144144
.current_dir(app_dir())
145-
.envs(command_env())
145+
.envs(command_env(true)) // development build always includes debug information
146146
.spawn()
147147
.with_context(|| format!("failed to run `{}` with `cmd /C`", before_dev))?;
148148
#[cfg(not(target_os = "windows"))]
149149
let child = Command::new("sh")
150150
.arg("-c")
151151
.arg(before_dev)
152152
.current_dir(app_dir())
153-
.envs(command_env())
153+
.envs(command_env(true)) // development build always includes debug information
154154
.spawn()
155155
.with_context(|| format!("failed to run `{}` with `sh -c`", before_dev))?;
156156
BEFORE_DEV.set(Mutex::new(child)).unwrap();

tooling/cli.rs/src/helpers/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ pub fn execute_with_output(cmd: &mut Command) -> crate::Result<()> {
4141
}
4242
}
4343

44-
pub fn command_env() -> HashMap<String, String> {
44+
pub fn command_env(debug: bool) -> HashMap<String, String> {
4545
let mut map = HashMap::new();
46+
4647
map.insert("PLATFORM".into(), std::env::consts::OS.into());
4748
map.insert("ARCH".into(), std::env::consts::ARCH.into());
4849
map.insert("FAMILY".into(), std::env::consts::FAMILY.into());
@@ -55,6 +56,10 @@ pub fn command_env() -> HashMap<String, String> {
5556
#[cfg(target_os = "macos")]
5657
map.insert("PLATFORM_TYPE".into(), "Darwing".into());
5758

59+
if debug {
60+
map.insert("TAURI_DEBUG".into(), "true".to_string());
61+
}
62+
5863
map
5964
}
6065

0 commit comments

Comments
 (0)