Skip to content

Commit ebcc21e

Browse files
authored
refactor: change prefix of hook env vars to TAURI_ENV_, closes #8054 (#8057)
1 parent 117a7dc commit ebcc21e

File tree

12 files changed

+44
-34
lines changed

12 files changed

+44
-34
lines changed

.changes/rename-hook-env-vars.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"@tauri-apps/cli": patch:breaking
3+
"tauri-cli": patch:breaking
4+
"tauri-build": patch:breaking
5+
"tauri-utils": patch:breaking
6+
"tauri-codegen": patch:breaking
7+
"tauri-macros": patch:breaking
8+
---
9+
10+
Renamed the beforeDevCommand, beforeBuildCommand and beforeBundleCommand hooks environment variables from `TAURI_PLATFORM, TAURI_ARCH, TAURI_FAMILY, TAURI_PLATFORM_VERSION, TAURI_PLATFORM_TYPE and TAURI_DEBUG` to `TAURI_ENV_PLATFORM, TAURI_ENV_ARCH, TAURI_ENV_FAMILY, TAURI_ENV_PLATFORM_VERSION, TAURI_ENV_PLATFORM_TYPE and TAURI_ENV_DEBUG` to differentiate the prefix with other CLI environment variables.

core/tauri-build/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
339339

340340
let target_triple = std::env::var("TARGET").unwrap();
341341

342-
println!("cargo:rustc-env=TAURI_TARGET_TRIPLE={target_triple}");
342+
println!("cargo:rustc-env=TAURI_ENV_TARGET_TRIPLE={target_triple}");
343343

344344
let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
345345
// TODO: far from ideal, but there's no other way to get the target dir, see <https://github.com/rust-lang/cargo/issues/5457>

core/tauri-codegen/src/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
122122
} = data;
123123

124124
let target = std::env::var("TARGET")
125-
.or_else(|_| std::env::var("TAURI_TARGET_TRIPLE"))
125+
.or_else(|_| std::env::var("TAURI_ENV_TARGET_TRIPLE"))
126126
.as_deref()
127127
.map(Target::from_triple)
128128
.unwrap_or_else(|_| Target::current());

core/tauri-config-schema/schema.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2166,7 +2166,7 @@
21662166
]
21672167
},
21682168
"beforeDevCommand": {
2169-
"description": "A shell command to run before `tauri dev` kicks in.\n\nThe TAURI_PLATFORM, TAURI_ARCH, TAURI_FAMILY, TAURI_PLATFORM_VERSION, TAURI_PLATFORM_TYPE and TAURI_DEBUG environment variables are set if you perform conditional compilation.",
2169+
"description": "A shell command to run before `tauri dev` kicks in.\n\nThe TAURI_ENV_PLATFORM, TAURI_ENV_ARCH, TAURI_ENV_FAMILY, TAURI_ENV_PLATFORM_VERSION, TAURI_ENV_PLATFORM_TYPE and TAURI_ENV_DEBUG environment variables are set if you perform conditional compilation.",
21702170
"anyOf": [
21712171
{
21722172
"$ref": "#/definitions/BeforeDevCommand"
@@ -2177,7 +2177,7 @@
21772177
]
21782178
},
21792179
"beforeBuildCommand": {
2180-
"description": "A shell command to run before `tauri build` kicks in.\n\nThe TAURI_PLATFORM, TAURI_ARCH, TAURI_FAMILY, TAURI_PLATFORM_VERSION, TAURI_PLATFORM_TYPE and TAURI_DEBUG environment variables are set if you perform conditional compilation.",
2180+
"description": "A shell command to run before `tauri build` kicks in.\n\nThe TAURI_ENV_PLATFORM, TAURI_ENV_ARCH, TAURI_ENV_FAMILY, TAURI_ENV_PLATFORM_VERSION, TAURI_ENV_PLATFORM_TYPE and TAURI_ENV_DEBUG environment variables are set if you perform conditional compilation.",
21812181
"anyOf": [
21822182
{
21832183
"$ref": "#/definitions/HookCommand"
@@ -2188,7 +2188,7 @@
21882188
]
21892189
},
21902190
"beforeBundleCommand": {
2191-
"description": "A shell command to run before the bundling phase in `tauri build` kicks in.\n\nThe TAURI_PLATFORM, TAURI_ARCH, TAURI_FAMILY, TAURI_PLATFORM_VERSION, TAURI_PLATFORM_TYPE and TAURI_DEBUG environment variables are set if you perform conditional compilation.",
2191+
"description": "A shell command to run before the bundling phase in `tauri build` kicks in.\n\nThe TAURI_ENV_PLATFORM, TAURI_ENV_ARCH, TAURI_ENV_FAMILY, TAURI_ENV_PLATFORM_VERSION, TAURI_ENV_PLATFORM_TYPE and TAURI_ENV_DEBUG environment variables are set if you perform conditional compilation.",
21922192
"anyOf": [
21932193
{
21942194
"$ref": "#/definitions/HookCommand"

core/tauri-macros/src/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub(crate) struct ContextItems {
2121
impl Parse for ContextItems {
2222
fn parse(input: &ParseBuffer<'_>) -> syn::parse::Result<Self> {
2323
let target = std::env::var("TARGET")
24-
.or_else(|_| std::env::var("TAURI_TARGET_TRIPLE"))
24+
.or_else(|_| std::env::var("TAURI_ENV_TARGET_TRIPLE"))
2525
.as_deref()
2626
.map(Target::from_triple)
2727
.unwrap_or_else(|_| Target::current());

core/tauri-utils/src/config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,17 +1711,17 @@ pub struct BuildConfig {
17111711
pub dist_dir: AppUrl,
17121712
/// A shell command to run before `tauri dev` kicks in.
17131713
///
1714-
/// The TAURI_PLATFORM, TAURI_ARCH, TAURI_FAMILY, TAURI_PLATFORM_VERSION, TAURI_PLATFORM_TYPE and TAURI_DEBUG environment variables are set if you perform conditional compilation.
1714+
/// The TAURI_ENV_PLATFORM, TAURI_ENV_ARCH, TAURI_ENV_FAMILY, TAURI_ENV_PLATFORM_VERSION, TAURI_ENV_PLATFORM_TYPE and TAURI_ENV_DEBUG environment variables are set if you perform conditional compilation.
17151715
#[serde(alias = "before-dev-command")]
17161716
pub before_dev_command: Option<BeforeDevCommand>,
17171717
/// A shell command to run before `tauri build` kicks in.
17181718
///
1719-
/// The TAURI_PLATFORM, TAURI_ARCH, TAURI_FAMILY, TAURI_PLATFORM_VERSION, TAURI_PLATFORM_TYPE and TAURI_DEBUG environment variables are set if you perform conditional compilation.
1719+
/// The TAURI_ENV_PLATFORM, TAURI_ENV_ARCH, TAURI_ENV_FAMILY, TAURI_ENV_PLATFORM_VERSION, TAURI_ENV_PLATFORM_TYPE and TAURI_ENV_DEBUG environment variables are set if you perform conditional compilation.
17201720
#[serde(alias = "before-build-command")]
17211721
pub before_build_command: Option<HookCommand>,
17221722
/// A shell command to run before the bundling phase in `tauri build` kicks in.
17231723
///
1724-
/// The TAURI_PLATFORM, TAURI_ARCH, TAURI_FAMILY, TAURI_PLATFORM_VERSION, TAURI_PLATFORM_TYPE and TAURI_DEBUG environment variables are set if you perform conditional compilation.
1724+
/// The TAURI_ENV_PLATFORM, TAURI_ENV_ARCH, TAURI_ENV_FAMILY, TAURI_ENV_PLATFORM_VERSION, TAURI_ENV_PLATFORM_TYPE and TAURI_ENV_DEBUG environment variables are set if you perform conditional compilation.
17251725
#[serde(alias = "before-bundle-command")]
17261726
pub before_bundle_command: Option<HookCommand>,
17271727
/// Features passed to `cargo` commands.

examples/api/vite.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import { internalIpV4 } from 'internal-ip'
1010
// https://vitejs.dev/config/
1111
export default defineConfig(async ({ command, mode }) => {
1212
const host =
13-
process.env.TAURI_PLATFORM === 'android' ||
14-
process.env.TAURI_PLATFORM === 'ios'
13+
process.env.TAURI_ENV_PLATFORM === 'android' ||
14+
process.env.TAURI_ENV_PLATFORM === 'ios'
1515
? await internalIpV4()
1616
: 'localhost'
1717
return {

tooling/cli/ENVIRONMENT_VARIABLES.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ These environment variables are inputs to the CLI which may have an equivalent C
3939

4040
These environment variables are set for each hook command (`beforeDevCommand`, `beforeBuildCommand`, ...etc) which could be useful to conditionally build your frontend or execute a specific action.
4141

42-
- `TAURI_ARCH` — Target arch, `x86_64`, `aarch64`...etc.
43-
- `TAURI_PLATFORM` — Target platform, `windows`, `macos`, `linux`...etc.
44-
- `TAURI_FAMILY` — Target platform family `unix` or `windows`.
45-
- `TAURI_PLATFORM_TYPE` — Target platform type `Linux`, `Windows_NT` or `Darwin`
46-
- `TAURI_PLATFORM_VERSION` — Build platform version
47-
- `TAURI_DEBUG``true` for `dev` command, `false` for `build` command.
48-
- `TAURI_TARGET_TRIPLE` — Target triple the CLI is building.
42+
- `TAURI_ENV_ARCH` — Target arch, `x86_64`, `aarch64`...etc.
43+
- `TAURI_ENV_PLATFORM` — Target platform, `windows`, `macos`, `linux`...etc.
44+
- `TAURI_ENV_FAMILY` — Target platform family `unix` or `windows`.
45+
- `TAURI_ENV_PLATFORM_TYPE` — Target platform type `Linux`, `Windows_NT` or `Darwin`
46+
- `TAURI_ENV_PLATFORM_VERSION` — Build platform version
47+
- `TAURI_ENV_DEBUG``true` for `dev` command, `false` for `build` command.
48+
- `TAURI_ENV_TARGET_TRIPLE` — Target triple the CLI is building.

tooling/cli/schema.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2166,7 +2166,7 @@
21662166
]
21672167
},
21682168
"beforeDevCommand": {
2169-
"description": "A shell command to run before `tauri dev` kicks in.\n\nThe TAURI_PLATFORM, TAURI_ARCH, TAURI_FAMILY, TAURI_PLATFORM_VERSION, TAURI_PLATFORM_TYPE and TAURI_DEBUG environment variables are set if you perform conditional compilation.",
2169+
"description": "A shell command to run before `tauri dev` kicks in.\n\nThe TAURI_ENV_PLATFORM, TAURI_ENV_ARCH, TAURI_ENV_FAMILY, TAURI_ENV_PLATFORM_VERSION, TAURI_ENV_PLATFORM_TYPE and TAURI_ENV_DEBUG environment variables are set if you perform conditional compilation.",
21702170
"anyOf": [
21712171
{
21722172
"$ref": "#/definitions/BeforeDevCommand"
@@ -2177,7 +2177,7 @@
21772177
]
21782178
},
21792179
"beforeBuildCommand": {
2180-
"description": "A shell command to run before `tauri build` kicks in.\n\nThe TAURI_PLATFORM, TAURI_ARCH, TAURI_FAMILY, TAURI_PLATFORM_VERSION, TAURI_PLATFORM_TYPE and TAURI_DEBUG environment variables are set if you perform conditional compilation.",
2180+
"description": "A shell command to run before `tauri build` kicks in.\n\nThe TAURI_ENV_PLATFORM, TAURI_ENV_ARCH, TAURI_ENV_FAMILY, TAURI_ENV_PLATFORM_VERSION, TAURI_ENV_PLATFORM_TYPE and TAURI_ENV_DEBUG environment variables are set if you perform conditional compilation.",
21812181
"anyOf": [
21822182
{
21832183
"$ref": "#/definitions/HookCommand"
@@ -2188,7 +2188,7 @@
21882188
]
21892189
},
21902190
"beforeBundleCommand": {
2191-
"description": "A shell command to run before the bundling phase in `tauri build` kicks in.\n\nThe TAURI_PLATFORM, TAURI_ARCH, TAURI_FAMILY, TAURI_PLATFORM_VERSION, TAURI_PLATFORM_TYPE and TAURI_DEBUG environment variables are set if you perform conditional compilation.",
2191+
"description": "A shell command to run before the bundling phase in `tauri build` kicks in.\n\nThe TAURI_ENV_PLATFORM, TAURI_ENV_ARCH, TAURI_ENV_FAMILY, TAURI_ENV_PLATFORM_VERSION, TAURI_ENV_PLATFORM_TYPE and TAURI_ENV_DEBUG environment variables are set if you perform conditional compilation.",
21922192
"anyOf": [
21932193
{
21942194
"$ref": "#/definitions/HookCommand"

tooling/cli/src/helpers/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ pub fn command_env(debug: bool) -> HashMap<&'static str, String> {
2323
let mut map = HashMap::new();
2424

2525
map.insert(
26-
"TAURI_PLATFORM_VERSION",
26+
"TAURI_ENV_PLATFORM_VERSION",
2727
os_info::get().version().to_string(),
2828
);
2929

3030
if debug {
31-
map.insert("TAURI_DEBUG", "true".into());
31+
map.insert("TAURI_ENV_DEBUG", "true".into());
3232
}
3333

3434
map

0 commit comments

Comments
 (0)