diff --git a/core/tauri-build/src/mobile.rs b/core/tauri-build/src/mobile.rs index 6f58f3ebe..958b174c2 100644 --- a/core/tauri-build/src/mobile.rs +++ b/core/tauri-build/src/mobile.rs @@ -32,7 +32,7 @@ impl PluginBuilder { /// Injects the mobile templates in the given path relative to the manifest root. pub fn run(self) -> Result<()> { - let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap(); + let target_os = var("CARGO_CFG_TARGET_OS").unwrap(); match target_os.as_str() { "android" => { if let Some(path) = self.android_path { @@ -76,7 +76,22 @@ project(':{pkg_name}').projectDir = new File('./tauri-plugins/{pkg_name}')" #[cfg(target_os = "macos")] "ios" => { if let Some(path) = self.ios_path { - link_swift_library(&std::env::var("CARGO_PKG_NAME").unwrap(), path); + let package_name = var("CARGO_PKG_NAME").unwrap(); + let tauri_library_path = std::env::var("DEP_TAURI_IOS_LIBRARY_PATH") + .expect("missing `DEP_TAURI_IOS_LIBRARY_PATH` environment variable. Make sure `tauri` is a dependency of the plugin."); + + let project_path = std::env::temp_dir().join(&package_name); + std::fs::create_dir_all(&project_path)?; + copy_folder(&path, &project_path.join("ios"))?; + + let package_swift_file = include_str!("../templates/Package.swift") + .replace("$PLUGIN_PACKAGE_NAME", &package_name) + .replace("$PLUGIN_PACKAGE_SRC_PATH", "ios/Sources") + .replace("$TAURI_PATH", &tauri_library_path); + + std::fs::write(project_path.join("Package.swift"), package_swift_file)?; + std::env::set_current_dir(&project_path)?; + link_swift_library(&var("CARGO_PKG_NAME").unwrap(), project_path); } } _ => (), @@ -112,6 +127,16 @@ pub fn inject_android_project(source: impl AsRef, target: impl AsRef None }; + copy_folder(source, target)?; + + if let Some(out_dir) = out_dir { + rename(out_dir, &build_path)?; + } + + Ok(()) +} + +fn copy_folder(source: &Path, target: &Path) -> Result<()> { let _ = fs::remove_dir_all(target); for entry in walkdir::WalkDir::new(source) { @@ -125,9 +150,5 @@ pub fn inject_android_project(source: impl AsRef, target: impl AsRef } } - if let Some(out_dir) = out_dir { - rename(out_dir, &build_path)?; - } - Ok(()) } diff --git a/core/tauri-build/templates/Package.swift b/core/tauri-build/templates/Package.swift new file mode 100644 index 000000000..3ee73ac7f --- /dev/null +++ b/core/tauri-build/templates/Package.swift @@ -0,0 +1,23 @@ +// swift-tools-version:5.7 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "PluginWorkspace", + products: [ + .library(name: "$PLUGIN_PACKAGE_NAME", type: .static, targets: ["$PLUGIN_PACKAGE_NAME"]), + ], + dependencies: [ + .package(name: "Tauri", path: "$TAURI_PATH"), + ], + targets: [ + .target( + name: "$PLUGIN_PACKAGE_NAME", + dependencies: [ + .byName(name: "Tauri") + ], + path: "$PLUGIN_PACKAGE_SRC_PATH" + ), + ] +) diff --git a/core/tauri/Cargo.toml b/core/tauri/Cargo.toml index 7afcb0f39..54d0266cc 100644 --- a/core/tauri/Cargo.toml +++ b/core/tauri/Cargo.toml @@ -11,6 +11,7 @@ name = "tauri" readme = "README.md" repository = "https://github.com/tauri-apps/tauri" version = "2.0.0-alpha.3" +links = "Tauri" [package.metadata.docs.rs] no-default-features = true diff --git a/core/tauri/build.rs b/core/tauri/build.rs index 755edbe92..e46bd7eb5 100644 --- a/core/tauri/build.rs +++ b/core/tauri/build.rs @@ -158,7 +158,10 @@ fn main() { #[cfg(target_os = "macos")] { if target_os == "ios" { - tauri_build::mobile::link_swift_library("Tauri", "./mobile/ios-api"); + let lib_path = + PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()).join("mobile/ios-api"); + tauri_build::mobile::link_swift_library("Tauri", &lib_path); + println!("cargo:ios_library_path={}", lib_path.display()); } } }