Skip to content

Commit

Permalink
Merge branch 'dev' into refactor/ios-cert-sync
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Aug 20, 2024
2 parents c0bc284 + 30c7685 commit d6e076f
Show file tree
Hide file tree
Showing 33 changed files with 529 additions and 94 deletions.
5 changes: 5 additions & 0 deletions .changes/append_invoke_initialization_script.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": patch:enhance
---

Added `Builder::append_invoke_initialization_script`.
7 changes: 7 additions & 0 deletions .changes/avoid-rebuilds.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"tauri": patch:bug
"tauri-build": patch:bug
"tauri-utils": patch:bug
---

Prevent build script from rerunning unnecessarily by only writing files when the content changes.
8 changes: 8 additions & 0 deletions .changes/bundler-object-custom-sign-command.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"tauri-bundler": patch:feat
"tauri-utils": patch:feat
"@tauri-apps/cli": patch:feat
"tauri-cli": patch:feat
---

Custom sign command with object notation for whitespaces in the command path and arguments.
6 changes: 6 additions & 0 deletions .changes/change-pr-10676.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@tauri-apps/cli": 'patch:bug'
"tauri-cli": 'patch:bug'
---

Change plugin template call to `register_ios_plugin` params to snake case
5 changes: 5 additions & 0 deletions .changes/enhance-permission-error-message.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": patch:enhance
---

Include more information in the IPC permission error message.
5 changes: 5 additions & 0 deletions .changes/fix-export-default-permissions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-build": patch:bug
---

Correctly export `DefaultPermissionsRule`
6 changes: 6 additions & 0 deletions .changes/fix-ios-build-older-swift.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'tauri-cli': 'patch:bug'
'@tauri-apps/cli': 'patch:bug'
---

Fix Swift plugin compilation on older versions.
5 changes: 5 additions & 0 deletions .changes/fix-tslib-path.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tauri-apps/api": patch:bug
---

Fix tslib path in dist.
7 changes: 7 additions & 0 deletions .changes/fix-xcodebuild-arch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'tauri-cli': 'patch:bug'
'@tauri-apps/cli': 'patch:bug'
---

Do not include the target arch when building and archiving the iOS application,
which makes Xcode project modifications more flexible.
1 change: 1 addition & 0 deletions .changes/pre.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
".changes/fix-ipc-fallback.md",
".changes/fix-manifest-migration.md",
".changes/fix-missing-codesign-error-macos.md",
".changes/fix-tslib-path.md",
".changes/fix-usage-without-compression.md",
".changes/fix-v1-frontend-migration.md",
".changes/get-window-async.md",
Expand Down
3 changes: 1 addition & 2 deletions core/tauri-acl-schema/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use std::{error::Error, path::PathBuf};

use schemars::schema_for;
use tauri_utils::{
acl::capability::Capability,
acl::{Permission, Scopes},
acl::{capability::Capability, Permission, Scopes},
write_if_changed,
};

Expand Down
10 changes: 3 additions & 7 deletions core/tauri-build/src/acl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use tauri_utils::{
APP_ACL_KEY,
},
platform::Target,
write_if_changed,
};

const CAPABILITIES_SCHEMA_FILE_NAME: &str = "schema.json";
Expand Down Expand Up @@ -384,7 +385,8 @@ permissions = [{default_permissions}]

let default_permission_toml_path = plugin_out_dir.join("default.toml");

write_if_changed(&default_permission_toml, &default_permission_toml_path);
write_if_changed(&default_permission_toml_path, default_permission_toml)
.unwrap_or_else(|_| panic!("unable to autogenerate {default_permission_toml_path:?}"));
}

tauri_utils::acl::build::define_permissions(
Expand Down Expand Up @@ -428,12 +430,6 @@ permissions = [{default_permissions}]
Ok(acl_manifests)
}

fn write_if_changed(content: &str, path: &Path) {
if content != read_to_string(path).unwrap_or_default() {
std::fs::write(path, content).unwrap_or_else(|_| panic!("unable to autogenerate {path:?}"));
}
}

pub fn app_manifest_permissions(
out_dir: &Path,
manifest: AppManifest,
Expand Down
2 changes: 1 addition & 1 deletion core/tauri-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ mod static_vcruntime;
#[cfg_attr(docsrs, doc(cfg(feature = "codegen")))]
pub use codegen::context::CodegenContext;

pub use acl::{AppManifest, InlinedPlugin};
pub use acl::{AppManifest, DefaultPermissionRule, InlinedPlugin};

const ACL_MANIFESTS_FILE_NAME: &str = "acl-manifests.json";
const CAPABILITIES_FILE_NAME: &str = "capabilities.json";
Expand Down
27 changes: 16 additions & 11 deletions core/tauri-build/src/mobile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{fs::write, path::PathBuf};

use anyhow::{Context, Result};
use semver::Version;
use tauri_utils::config::Config;
use tauri_utils::{config::Config, write_if_changed};

use crate::is_dev;

Expand Down Expand Up @@ -80,20 +80,25 @@ dependencies {"
}
}

write(&gradle_settings_path, gradle_settings).context("failed to write tauri.settings.gradle")?;
// Overwrite only if changed to not trigger rebuilds
write_if_changed(&gradle_settings_path, gradle_settings)
.context("failed to write tauri.settings.gradle")?;

write(&app_build_gradle_path, app_build_gradle)
write_if_changed(&app_build_gradle_path, app_build_gradle)
.context("failed to write tauri.build.gradle.kts")?;

if !app_tauri_properties.is_empty() {
write(
&app_tauri_properties_path,
format!(
"// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.\n{}",
app_tauri_properties.join("\n")
),
)
.context("failed to write tauri.properties")?;
let app_tauri_properties_content = format!(
"// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.\n{}",
app_tauri_properties.join("\n")
);
if std::fs::read_to_string(&app_tauri_properties_path)
.map(|o| o != app_tauri_properties_content)
.unwrap_or(true)
{
write(&app_tauri_properties_path, app_tauri_properties_content)
.context("failed to write tauri.properties")?;
}
}

println!("cargo:rerun-if-changed={}", gradle_settings_path.display());
Expand Down
43 changes: 39 additions & 4 deletions core/tauri-config-schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2033,10 +2033,14 @@
]
},
"signCommand": {
"description": "Specify a custom command to sign the binaries.\n This command needs to have a `%1` in it which is just a placeholder for the binary path,\n which we will detect and replace before calling the command.\n\n Example:\n ```text\n sign-cli --arg1 --arg2 %1\n ```\n\n By Default we use `signtool.exe` which can be found only on Windows so\n if you are on another platform and want to cross-compile and sign you will\n need to use another tool like `osslsigncode`.",
"type": [
"string",
"null"
"description": "Specify a custom command to sign the binaries.\n This command needs to have a `%1` in args which is just a placeholder for the binary path,\n which we will detect and replace before calling the command.\n\n By Default we use `signtool.exe` which can be found only on Windows so\n if you are on another platform and want to cross-compile and sign you will\n need to use another tool like `osslsigncode`.",
"anyOf": [
{
"$ref": "#/definitions/CustomSignCommandConfig"
},
{
"type": "null"
}
]
}
},
Expand Down Expand Up @@ -2425,6 +2429,37 @@
}
]
},
"CustomSignCommandConfig": {
"description": "Custom Signing Command configuration.",
"anyOf": [
{
"description": "A string notation of the script to execute.\n\n \"%1\" will be replaced with the path to the binary to be signed.\n\n This is a simpler notation for the command.\n Tauri will split the string with `' '` and use the first element as the command name and the rest as arguments.\n\n If you need to use whitespace in the command or arguments, use the object notation [`Self::ScriptWithOptions`].",
"type": "string"
},
{
"description": "An object notation of the command.\n\n This is more complex notation for the command but\n this allows you to use whitespace in the command and arguments.",
"type": "object",
"required": [
"args",
"cmd"
],
"properties": {
"cmd": {
"description": "The command to run to sign the binary.",
"type": "string"
},
"args": {
"description": "The arguments to pass to the command.\n\n \"%1\" will be replaced with the path to the binary to be signed.",
"type": "array",
"items": {
"type": "string"
}
}
},
"additionalProperties": false
}
]
},
"LinuxConfig": {
"description": "Configuration for Linux bundles.\n\n See more: <https://tauri.app/v1/api/config#linuxconfig>",
"type": "object",
Expand Down
11 changes: 3 additions & 8 deletions core/tauri-utils/src/acl/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::{
path::{Path, PathBuf},
};

use crate::acl::Error;
use crate::{acl::Error, write_if_changed};
use schemars::{
schema::{InstanceType, Metadata, RootSchema, Schema, SchemaObject, SubschemaValidation},
schema_for,
Expand Down Expand Up @@ -450,7 +450,8 @@ commands.deny = ["{command}"]
);

let out_path = path.join(format!("{command}.toml"));
write_if_changed(&toml, &out_path);
write_if_changed(&out_path, toml)
.unwrap_or_else(|_| panic!("unable to autogenerate {out_path:?}"));

autogenerated
.allowed
Expand All @@ -462,9 +463,3 @@ commands.deny = ["{command}"]

autogenerated
}

fn write_if_changed(content: &str, path: &Path) {
if content != read_to_string(path).unwrap_or_default() {
std::fs::write(path, content).unwrap_or_else(|_| panic!("unable to autogenerate {path:?}"));
}
}
37 changes: 30 additions & 7 deletions core/tauri-utils/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,34 @@ impl Default for WebviewInstallMode {
}
}

/// Custom Signing Command configuration.
#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "schema", derive(JsonSchema))]
#[serde(rename_all = "camelCase", deny_unknown_fields, untagged)]
pub enum CustomSignCommandConfig {
/// A string notation of the script to execute.
///
/// "%1" will be replaced with the path to the binary to be signed.
///
/// This is a simpler notation for the command.
/// Tauri will split the string with `' '` and use the first element as the command name and the rest as arguments.
///
/// If you need to use whitespace in the command or arguments, use the object notation [`Self::ScriptWithOptions`].
Command(String),
/// An object notation of the command.
///
/// This is more complex notation for the command but
/// this allows you to use whitespace in the command and arguments.
CommandWithOptions {
/// The command to run to sign the binary.
cmd: String,
/// The arguments to pass to the command.
///
/// "%1" will be replaced with the path to the binary to be signed.
args: Vec<String>,
},
}

/// Windows bundler configuration.
///
/// See more: <https://tauri.app/v1/api/config#windowsconfig>
Expand Down Expand Up @@ -935,19 +963,14 @@ pub struct WindowsConfig {
/// Configuration for the installer generated with NSIS.
pub nsis: Option<NsisConfig>,
/// Specify a custom command to sign the binaries.
/// This command needs to have a `%1` in it which is just a placeholder for the binary path,
/// This command needs to have a `%1` in args which is just a placeholder for the binary path,
/// which we will detect and replace before calling the command.
///
/// Example:
/// ```text
/// sign-cli --arg1 --arg2 %1
/// ```
///
/// By Default we use `signtool.exe` which can be found only on Windows so
/// if you are on another platform and want to cross-compile and sign you will
/// need to use another tool like `osslsigncode`.
#[serde(alias = "sign-command")]
pub sign_command: Option<String>,
pub sign_command: Option<CustomSignCommandConfig>,
}

impl Default for WindowsConfig {
Expand Down
6 changes: 4 additions & 2 deletions core/tauri/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
// SPDX-License-Identifier: MIT

use heck::AsShoutySnakeCase;
use tauri_utils::write_if_changed;

use std::env::var_os;
use std::fs::create_dir_all;
use std::fs::read_dir;
use std::fs::read_to_string;
use std::fs::write;
use std::{
env::var,
path::{Path, PathBuf},
Expand Down Expand Up @@ -289,7 +289,9 @@ fn main() {
.replace("{{library}}", &library);

let out_path = kotlin_out_dir.join(file.file_name());
write(&out_path, content).expect("Failed to write kotlin file");
// Overwrite only if changed to not trigger rebuilds
write_if_changed(&out_path, &content).expect("Failed to write kotlin file");

println!("cargo:rerun-if-changed={}", out_path.display());
}
}
Expand Down
47 changes: 47 additions & 0 deletions core/tauri/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1328,6 +1328,53 @@ impl<R: Runtime> Builder<R> {
self
}

/// Append a custom initialization script.
///
/// Allow to append custom initialization script instend of replacing entire invoke system.
///
/// # Examples
///
/// ```
/// let custom_script = r#"
/// // A custom call system bridge build on top of tauri invoke system.
/// async function invoke(cmd, args = {}) {
/// if (!args) args = {};
///
/// let prefix = "";
///
/// if (args?.__module) {
/// prefix = `plugin:hybridcall.${args.__module}|`;
/// }
///
/// const command = `${prefix}tauri_${cmd}`;
///
/// const invoke = window.__TAURI_INTERNALS__.invoke;
///
/// return invoke(command, args).then(result => {
/// if (window.build.debug) {
/// console.log(`call: ${command}`);
/// console.log(`args: ${JSON.stringify(args)}`);
/// console.log(`return: ${JSON.stringify(result)}`);
/// }
///
/// return result;
/// });
/// }
/// "#;
///
/// tauri::Builder::default()
/// .append_invoke_initialization_script(custom_script);
/// ```
pub fn append_invoke_initialization_script(
mut self,
initialization_script: impl AsRef<str>,
) -> Self {
self
.invoke_initialization_script
.push_str(initialization_script.as_ref());
self
}

/// Defines the setup hook.
///
/// # Examples
Expand Down
Loading

0 comments on commit d6e076f

Please sign in to comment.