|
@@ -1,5 +1,5 @@
|
|
|
use std::{
|
|
|
- env::var,
|
|
|
+ env::{var, var_os},
|
|
|
fs::{self, rename},
|
|
|
path::{Path, PathBuf},
|
|
|
};
|
|
@@ -36,16 +36,30 @@ impl PluginBuilder {
|
|
|
match target_os.as_str() {
|
|
|
"android" => {
|
|
|
if let Some(path) = self.android_path {
|
|
|
- let manifest_dir = var("CARGO_MANIFEST_DIR").map(PathBuf::from).unwrap();
|
|
|
+ let manifest_dir = var_os("CARGO_MANIFEST_DIR").map(PathBuf::from).unwrap();
|
|
|
+ let source = manifest_dir.join(path);
|
|
|
+
|
|
|
+ let tauri_library_path = std::env::var("DEP_TAURI_ANDROID_LIBRARY_PATH")
|
|
|
+ .expect("missing `DEP_TAURI_ANDROID_LIBRARY_PATH` environment variable. Make sure `tauri` is a dependency of the plugin.");
|
|
|
+
|
|
|
+ copy_folder(
|
|
|
+ Path::new(&tauri_library_path),
|
|
|
+ &source.join("tauri-api"),
|
|
|
+ &[],
|
|
|
+ )?;
|
|
|
+
|
|
|
if let Ok(project_dir) = var("TAURI_ANDROID_PROJECT_PATH") {
|
|
|
- let source = manifest_dir.join(path);
|
|
|
let pkg_name = var("CARGO_PKG_NAME").unwrap();
|
|
|
|
|
|
println!("cargo:rerun-if-env-changed=TAURI_ANDROID_PROJECT_PATH");
|
|
|
|
|
|
let project_dir = PathBuf::from(project_dir);
|
|
|
|
|
|
- inject_android_project(source, project_dir.join("tauri-plugins").join(&pkg_name))?;
|
|
|
+ inject_android_project(
|
|
|
+ source,
|
|
|
+ project_dir.join("tauri-plugins").join(&pkg_name),
|
|
|
+ &["tauri-api"],
|
|
|
+ )?;
|
|
|
|
|
|
let gradle_settings_path = project_dir.join("tauri.settings.gradle");
|
|
|
let gradle_settings = fs::read_to_string(&gradle_settings_path)?;
|
|
@@ -76,22 +90,16 @@ project(':{pkg_name}').projectDir = new File('./tauri-plugins/{pkg_name}')"
|
|
|
#[cfg(target_os = "macos")]
|
|
|
"ios" => {
|
|
|
if let Some(path) = self.ios_path {
|
|
|
- let package_name = var("CARGO_PKG_NAME").unwrap();
|
|
|
+ let manifest_dir = var_os("CARGO_MANIFEST_DIR").map(PathBuf::from).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);
|
|
|
+ copy_folder(
|
|
|
+ &Path::new(&tauri_library_path),
|
|
|
+ &path.join("tauri-api"),
|
|
|
+ &[".build", "Package.resolved", "Tests"],
|
|
|
+ )?;
|
|
|
+ link_swift_library(&var("CARGO_PKG_NAME").unwrap(), manifest_dir.join(path));
|
|
|
}
|
|
|
}
|
|
|
_ => (),
|
|
@@ -106,14 +114,21 @@ project(':{pkg_name}').projectDir = new File('./tauri-plugins/{pkg_name}')"
|
|
|
pub fn link_swift_library(name: &str, source: impl AsRef<Path>) {
|
|
|
let source = source.as_ref();
|
|
|
println!("cargo:rerun-if-changed={}", source.display());
|
|
|
+ let curr_dir = std::env::current_dir().unwrap();
|
|
|
+ std::env::set_current_dir(&source).unwrap();
|
|
|
swift_rs::build::SwiftLinker::new("10.13")
|
|
|
.with_ios("11")
|
|
|
.with_package(name, source)
|
|
|
.link();
|
|
|
+ std::env::set_current_dir(&curr_dir).unwrap();
|
|
|
}
|
|
|
|
|
|
#[doc(hidden)]
|
|
|
-pub fn inject_android_project(source: impl AsRef<Path>, target: impl AsRef<Path>) -> Result<()> {
|
|
|
+pub fn inject_android_project(
|
|
|
+ source: impl AsRef<Path>,
|
|
|
+ target: impl AsRef<Path>,
|
|
|
+ ignore_paths: &[&str],
|
|
|
+) -> Result<()> {
|
|
|
let source = source.as_ref();
|
|
|
let target = target.as_ref();
|
|
|
|
|
@@ -127,7 +142,7 @@ pub fn inject_android_project(source: impl AsRef<Path>, target: impl AsRef<Path>
|
|
|
None
|
|
|
};
|
|
|
|
|
|
- copy_folder(source, target)?;
|
|
|
+ copy_folder(source, target, ignore_paths)?;
|
|
|
|
|
|
if let Some(out_dir) = out_dir {
|
|
|
rename(out_dir, &build_path)?;
|
|
@@ -136,12 +151,19 @@ pub fn inject_android_project(source: impl AsRef<Path>, target: impl AsRef<Path>
|
|
|
Ok(())
|
|
|
}
|
|
|
|
|
|
-fn copy_folder(source: &Path, target: &Path) -> Result<()> {
|
|
|
+fn copy_folder(source: &Path, target: &Path, ignore_paths: &[&str]) -> Result<()> {
|
|
|
let _ = fs::remove_dir_all(target);
|
|
|
|
|
|
for entry in walkdir::WalkDir::new(source) {
|
|
|
let entry = entry?;
|
|
|
let rel_path = entry.path().strip_prefix(source)?;
|
|
|
+ let rel_path_str = rel_path.to_string_lossy();
|
|
|
+ if ignore_paths
|
|
|
+ .iter()
|
|
|
+ .any(|path| rel_path_str.starts_with(path))
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
let dest_path = target.join(rel_path);
|
|
|
if entry.file_type().is_dir() {
|
|
|
fs::create_dir(dest_path)?;
|