Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .changes/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"feat": "New Features",
"enhance": "Enhancements",
"bug": "Bug Fixes",
"pref": "Performance Improvements",
"perf": "Performance Improvements",
"changes": "What's Changed",
"sec": "Security fixes",
"deps": "Dependencies",
Expand Down
8 changes: 8 additions & 0 deletions .changes/dont-ship-global-bundle-if-no-global-tauri.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
tauri: 'patch:perf'
tauri-build: 'patch:perf'
tauri-plugin: 'patch:perf'
tauri-utils: 'patch:perf'
---

Don't ship global `bundle.global.js` if `app > withGlobalTauri` is set to false
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ The list of Tauri's features includes, but is not limited to:

Tauri currently supports development and distribution on the following platforms:

| Platform | Versions |
| :---------------- | :-------------------------------------------------------------------------------------------------------------- |
| Windows | 7 and above |
| macOS | 10.15 and above |
| Linux | webkit2gtk 4.0 for Tauri v1 (for example Ubuntu 18.04). webkit2gtk 4.1 for Tauri v2 (for example Ubuntu 22.04). |
| iOS/iPadOS | 9 and above |
| Android | 7 and above (currently 8 and above) |
| Platform | Versions |
| :--------- | :-------------------------------------------------------------------------------------------------------------- |
| Windows | 7 and above |
| macOS | 10.15 and above |
| Linux | webkit2gtk 4.0 for Tauri v1 (for example Ubuntu 18.04). webkit2gtk 4.1 for Tauri v2 (for example Ubuntu 22.04). |
| iOS/iPadOS | 9 and above |
| Android | 7 and above (currently 8 and above) |

## Contributing

Expand Down
2 changes: 0 additions & 2 deletions crates/tauri-build/src/acl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,6 @@ pub fn build(out_dir: &Path, target: Target, attributes: &Attributes) -> super::
let capabilities_path = save_capabilities(&capabilities)?;
fs::copy(capabilities_path, out_dir.join(CAPABILITIES_FILE_NAME))?;

tauri_utils::plugin::save_global_api_scripts_paths(out_dir);

let mut permissions_map = inline_plugins_acl.permission_files;
if has_app_manifest {
permissions_map.insert(APP_ACL_KEY.to_string(), app_acl.permission_files);
Expand Down
2 changes: 2 additions & 0 deletions crates/tauri-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,8 @@ pub fn try_build(attributes: Attributes) -> Result<()> {

acl::build(&out_dir, target, &attributes)?;

tauri_utils::plugin::save_global_api_scripts_paths(&out_dir, None);

println!("cargo:rustc-env=TAURI_ENV_TARGET_TRIPLE={target_triple}");
// when running codegen in this build script, we need to access the env var directly
env::set_var("TAURI_ENV_TARGET_TRIPLE", &target_triple);
Expand Down
2 changes: 1 addition & 1 deletion crates/tauri-plugin/src/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl<'a> Builder<'a> {
}

if let Some(path) = self.global_api_script_path {
tauri_utils::plugin::define_global_api_script_path(path);
tauri_utils::plugin::define_global_api_script_path(&path);
}

mobile::setup(self.android_path, self.ios_path)?;
Expand Down
15 changes: 12 additions & 3 deletions crates/tauri-utils/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ mod build {
pub const GLOBAL_API_SCRIPT_FILE_LIST_PATH: &str = "__global-api-script.js";

/// Defines the path to the global API script using Cargo instructions.
pub fn define_global_api_script_path(path: PathBuf) {
pub fn define_global_api_script_path(path: &Path) {
println!(
"cargo:{GLOBAL_API_SCRIPT_PATH_KEY}={}",
path
Expand All @@ -31,18 +31,27 @@ mod build {

/// Collects the path of all the global API scripts defined with [`define_global_api_script_path`]
/// and saves them to the out dir with filename [`GLOBAL_API_SCRIPT_FILE_LIST_PATH`].
pub fn save_global_api_scripts_paths(out_dir: &Path) {
///
/// `tauri_global_scripts` is only used in Tauri's monorepo for the examples to work
/// since they don't have a build script to run `tauri-build` and pull in the deps env vars
pub fn save_global_api_scripts_paths(out_dir: &Path, mut tauri_global_scripts: Option<PathBuf>) {
let mut scripts = Vec::new();

for (key, value) in vars_os() {
let key = key.to_string_lossy();

if key.starts_with("DEP_") && key.ends_with(GLOBAL_API_SCRIPT_PATH_KEY) {
if key == format!("DEP_TAURI_{GLOBAL_API_SCRIPT_PATH_KEY}") {
tauri_global_scripts = Some(PathBuf::from(value));
} else if key.starts_with("DEP_") && key.ends_with(GLOBAL_API_SCRIPT_PATH_KEY) {
let script_path = PathBuf::from(value);
scripts.push(script_path);
}
}

if let Some(tauri_global_scripts) = tauri_global_scripts {
scripts.insert(0, tauri_global_scripts);
}

fs::write(
out_dir.join(GLOBAL_API_SCRIPT_FILE_LIST_PATH),
serde_json::to_string(&scripts).expect("failed to serialize global API script paths"),
Expand Down
10 changes: 10 additions & 0 deletions crates/tauri/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,16 @@ fn main() {
}
}

let tauri_global_scripts = PathBuf::from("./scripts/bundle.global.js")
.canonicalize()
.expect("failed to canonicalize tauri global API script path");
tauri_utils::plugin::define_global_api_script_path(&tauri_global_scripts);
// This should usually be done in `tauri-build`,
// but we need to do this here for the examples in this workspace to work as they don't have build scripts
if is_tauri_workspace {
tauri_utils::plugin::save_global_api_scripts_paths(&out_dir, Some(tauri_global_scripts));
}

let permissions = define_permissions(&out_dir);
tauri_utils::acl::build::generate_allowed_commands(&out_dir, permissions).unwrap();
}
Expand Down
2 changes: 0 additions & 2 deletions crates/tauri/scripts/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@
__RAW_core_script__

__RAW_event_initialization_script__

__RAW_bundle_script__
})()
12 changes: 0 additions & 12 deletions crates/tauri/src/manager/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ impl<R: Runtime> WebviewManager<R> {
) -> crate::Result<PendingWebview<EventLoopMessage, R>> {
let app_manager = manager.manager();

let is_init_global = app_manager.config.app.with_global_tauri;
let plugin_init_scripts = app_manager
.plugins
.lock()
Expand Down Expand Up @@ -185,7 +184,6 @@ impl<R: Runtime> WebviewManager<R> {
app_manager,
&ipc_init.into_string(),
&pattern_init.into_string(),
is_init_global,
use_https_scheme,
)?
.to_string(),
Expand Down Expand Up @@ -346,7 +344,6 @@ impl<R: Runtime> WebviewManager<R> {
app_manager: &AppManager<R>,
ipc_script: &str,
pattern_script: &str,
with_global_tauri: bool,
use_https_scheme: bool,
) -> crate::Result<String> {
#[derive(Template)]
Expand All @@ -357,8 +354,6 @@ impl<R: Runtime> WebviewManager<R> {
#[raw]
ipc_script: &'a str,
#[raw]
bundle_script: &'a str,
#[raw]
core_script: &'a str,
#[raw]
event_initialization_script: &'a str,
Expand All @@ -374,12 +369,6 @@ impl<R: Runtime> WebviewManager<R> {
invoke_key: &'a str,
}

let bundle_script = if with_global_tauri {
include_str!("../../scripts/bundle.global.js")
} else {
""
};

let freeze_prototype = if app_manager.config.app.security.freeze_prototype {
include_str!("../../scripts/freeze_prototype.js")
} else {
Expand All @@ -389,7 +378,6 @@ impl<R: Runtime> WebviewManager<R> {
InitJavascript {
pattern_script,
ipc_script,
bundle_script,
core_script: &CoreJavascript {
os_name: std::env::consts::OS,
protocol_scheme: if use_https_scheme { "https" } else { "http" },
Expand Down