mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-12-29 14:04:19 +03:00
This commit is contained in:
parent
117a7dc2bb
commit
ebcc21e4b9
10
.changes/rename-hook-env-vars.md
Normal file
10
.changes/rename-hook-env-vars.md
Normal file
@ -0,0 +1,10 @@
|
||||
---
|
||||
"@tauri-apps/cli": patch:breaking
|
||||
"tauri-cli": patch:breaking
|
||||
"tauri-build": patch:breaking
|
||||
"tauri-utils": patch:breaking
|
||||
"tauri-codegen": patch:breaking
|
||||
"tauri-macros": patch:breaking
|
||||
---
|
||||
|
||||
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.
|
@ -339,7 +339,7 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
|
||||
|
||||
let target_triple = std::env::var("TARGET").unwrap();
|
||||
|
||||
println!("cargo:rustc-env=TAURI_TARGET_TRIPLE={target_triple}");
|
||||
println!("cargo:rustc-env=TAURI_ENV_TARGET_TRIPLE={target_triple}");
|
||||
|
||||
let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
|
||||
// TODO: far from ideal, but there's no other way to get the target dir, see <https://github.com/rust-lang/cargo/issues/5457>
|
||||
|
@ -122,7 +122,7 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
|
||||
} = data;
|
||||
|
||||
let target = std::env::var("TARGET")
|
||||
.or_else(|_| std::env::var("TAURI_TARGET_TRIPLE"))
|
||||
.or_else(|_| std::env::var("TAURI_ENV_TARGET_TRIPLE"))
|
||||
.as_deref()
|
||||
.map(Target::from_triple)
|
||||
.unwrap_or_else(|_| Target::current());
|
||||
|
@ -2166,7 +2166,7 @@
|
||||
]
|
||||
},
|
||||
"beforeDevCommand": {
|
||||
"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.",
|
||||
"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.",
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/BeforeDevCommand"
|
||||
@ -2177,7 +2177,7 @@
|
||||
]
|
||||
},
|
||||
"beforeBuildCommand": {
|
||||
"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.",
|
||||
"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.",
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/HookCommand"
|
||||
@ -2188,7 +2188,7 @@
|
||||
]
|
||||
},
|
||||
"beforeBundleCommand": {
|
||||
"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.",
|
||||
"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.",
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/HookCommand"
|
||||
|
@ -21,7 +21,7 @@ pub(crate) struct ContextItems {
|
||||
impl Parse for ContextItems {
|
||||
fn parse(input: &ParseBuffer<'_>) -> syn::parse::Result<Self> {
|
||||
let target = std::env::var("TARGET")
|
||||
.or_else(|_| std::env::var("TAURI_TARGET_TRIPLE"))
|
||||
.or_else(|_| std::env::var("TAURI_ENV_TARGET_TRIPLE"))
|
||||
.as_deref()
|
||||
.map(Target::from_triple)
|
||||
.unwrap_or_else(|_| Target::current());
|
||||
|
@ -1711,17 +1711,17 @@ pub struct BuildConfig {
|
||||
pub dist_dir: AppUrl,
|
||||
/// A shell command to run before `tauri dev` kicks in.
|
||||
///
|
||||
/// 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.
|
||||
/// 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.
|
||||
#[serde(alias = "before-dev-command")]
|
||||
pub before_dev_command: Option<BeforeDevCommand>,
|
||||
/// A shell command to run before `tauri build` kicks in.
|
||||
///
|
||||
/// 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.
|
||||
/// 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.
|
||||
#[serde(alias = "before-build-command")]
|
||||
pub before_build_command: Option<HookCommand>,
|
||||
/// A shell command to run before the bundling phase in `tauri build` kicks in.
|
||||
///
|
||||
/// 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.
|
||||
/// 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.
|
||||
#[serde(alias = "before-bundle-command")]
|
||||
pub before_bundle_command: Option<HookCommand>,
|
||||
/// Features passed to `cargo` commands.
|
||||
|
@ -10,8 +10,8 @@ import { internalIpV4 } from 'internal-ip'
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig(async ({ command, mode }) => {
|
||||
const host =
|
||||
process.env.TAURI_PLATFORM === 'android' ||
|
||||
process.env.TAURI_PLATFORM === 'ios'
|
||||
process.env.TAURI_ENV_PLATFORM === 'android' ||
|
||||
process.env.TAURI_ENV_PLATFORM === 'ios'
|
||||
? await internalIpV4()
|
||||
: 'localhost'
|
||||
return {
|
||||
|
@ -39,10 +39,10 @@ These environment variables are inputs to the CLI which may have an equivalent C
|
||||
|
||||
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.
|
||||
|
||||
- `TAURI_ARCH` — Target arch, `x86_64`, `aarch64`...etc.
|
||||
- `TAURI_PLATFORM` — Target platform, `windows`, `macos`, `linux`...etc.
|
||||
- `TAURI_FAMILY` — Target platform family `unix` or `windows`.
|
||||
- `TAURI_PLATFORM_TYPE` — Target platform type `Linux`, `Windows_NT` or `Darwin`
|
||||
- `TAURI_PLATFORM_VERSION` — Build platform version
|
||||
- `TAURI_DEBUG` — `true` for `dev` command, `false` for `build` command.
|
||||
- `TAURI_TARGET_TRIPLE` — Target triple the CLI is building.
|
||||
- `TAURI_ENV_ARCH` — Target arch, `x86_64`, `aarch64`...etc.
|
||||
- `TAURI_ENV_PLATFORM` — Target platform, `windows`, `macos`, `linux`...etc.
|
||||
- `TAURI_ENV_FAMILY` — Target platform family `unix` or `windows`.
|
||||
- `TAURI_ENV_PLATFORM_TYPE` — Target platform type `Linux`, `Windows_NT` or `Darwin`
|
||||
- `TAURI_ENV_PLATFORM_VERSION` — Build platform version
|
||||
- `TAURI_ENV_DEBUG` — `true` for `dev` command, `false` for `build` command.
|
||||
- `TAURI_ENV_TARGET_TRIPLE` — Target triple the CLI is building.
|
||||
|
@ -2166,7 +2166,7 @@
|
||||
]
|
||||
},
|
||||
"beforeDevCommand": {
|
||||
"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.",
|
||||
"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.",
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/BeforeDevCommand"
|
||||
@ -2177,7 +2177,7 @@
|
||||
]
|
||||
},
|
||||
"beforeBuildCommand": {
|
||||
"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.",
|
||||
"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.",
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/HookCommand"
|
||||
@ -2188,7 +2188,7 @@
|
||||
]
|
||||
},
|
||||
"beforeBundleCommand": {
|
||||
"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.",
|
||||
"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.",
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/HookCommand"
|
||||
|
@ -23,12 +23,12 @@ pub fn command_env(debug: bool) -> HashMap<&'static str, String> {
|
||||
let mut map = HashMap::new();
|
||||
|
||||
map.insert(
|
||||
"TAURI_PLATFORM_VERSION",
|
||||
"TAURI_ENV_PLATFORM_VERSION",
|
||||
os_info::get().version().to_string(),
|
||||
);
|
||||
|
||||
if debug {
|
||||
map.insert("TAURI_DEBUG", "true".into());
|
||||
map.insert("TAURI_ENV_DEBUG", "true".into());
|
||||
}
|
||||
|
||||
map
|
||||
|
@ -224,14 +224,14 @@ impl Interface for Rust {
|
||||
fn env(&self) -> HashMap<&str, String> {
|
||||
let mut env = HashMap::new();
|
||||
env.insert(
|
||||
"TAURI_TARGET_TRIPLE",
|
||||
"TAURI_ENV_TARGET_TRIPLE",
|
||||
self.app_settings.target_triple.clone(),
|
||||
);
|
||||
|
||||
let mut s = self.app_settings.target_triple.split('-');
|
||||
let (arch, _, host) = (s.next().unwrap(), s.next().unwrap(), s.next().unwrap());
|
||||
env.insert(
|
||||
"TAURI_ARCH",
|
||||
"TAURI_ENV_ARCH",
|
||||
match arch {
|
||||
// keeps compatibility with old `std::env::consts::ARCH` implementation
|
||||
"i686" | "i586" => "x86".into(),
|
||||
@ -239,7 +239,7 @@ impl Interface for Rust {
|
||||
},
|
||||
);
|
||||
env.insert(
|
||||
"TAURI_PLATFORM",
|
||||
"TAURI_ENV_PLATFORM",
|
||||
match host {
|
||||
// keeps compatibility with old `std::env::consts::OS` implementation
|
||||
"darwin" => "macos".into(),
|
||||
@ -250,7 +250,7 @@ impl Interface for Rust {
|
||||
);
|
||||
|
||||
env.insert(
|
||||
"TAURI_FAMILY",
|
||||
"TAURI_ENV_FAMILY",
|
||||
match host {
|
||||
"windows" => "windows".into(),
|
||||
_ => "unix".into(),
|
||||
@ -258,9 +258,9 @@ impl Interface for Rust {
|
||||
);
|
||||
|
||||
match host {
|
||||
"linux" => env.insert("TAURI_PLATFORM_TYPE", "Linux".into()),
|
||||
"windows" => env.insert("TAURI_PLATFORM_TYPE", "Windows_NT".into()),
|
||||
"darwin" => env.insert("TAURI_PLATFORM_TYPE", "Darwin".into()),
|
||||
"linux" => env.insert("TAURI_ENV_PLATFORM_TYPE", "Linux".into()),
|
||||
"windows" => env.insert("TAURI_ENV_PLATFORM_TYPE", "Windows_NT".into()),
|
||||
"darwin" => env.insert("TAURI_ENV_PLATFORM_TYPE", "Darwin".into()),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
|
@ -13,15 +13,15 @@ export default defineConfig({
|
||||
port: 1420,
|
||||
strictPort: true,
|
||||
},
|
||||
// to make use of `TAURI_DEBUG` and other env variables
|
||||
// to make use of `TAURI_ENV_DEBUG` and other env variables
|
||||
// https://tauri.studio/v1/api/config#buildconfig.beforedevcommand
|
||||
envPrefix: ["VITE_", "TAURI_"],
|
||||
envPrefix: ["VITE_", "TAURI_ENV_"],
|
||||
build: {
|
||||
// Tauri supports es2021
|
||||
target: ["es2021", "chrome100", "safari13"],
|
||||
// don't minify for debug builds
|
||||
minify: !process.env.TAURI_DEBUG ? "esbuild" : false,
|
||||
minify: !process.env.TAURI_ENV_DEBUG ? "esbuild" : false,
|
||||
// produce sourcemaps for debug builds
|
||||
sourcemap: !!process.env.TAURI_DEBUG,
|
||||
sourcemap: !!process.env.TAURI_ENV_DEBUG,
|
||||
},
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user