浏览代码

feat(cli): update project.yml syntax

Lucas Nogueira 2 年之前
父节点
当前提交
f9b529a96e
共有 3 个文件被更改,包括 68 次插入20 次删除
  1. 56 1
      tooling/cli/src/mobile/ios/xcode_script.rs
  2. 1 0
      tooling/cli/src/mobile/mod.rs
  3. 11 19
      tooling/cli/templates/mobile/ios/project.yml

+ 56 - 1
tooling/cli/src/mobile/ios/xcode_script.rs

@@ -14,6 +14,15 @@ pub struct Options {
   /// Value of `SDKROOT` env var
   #[clap(long)]
   sdk_root: PathBuf,
+  /// Value of `FRAMEWORK_SEARCH_PATHS` env var
+  #[clap(long)]
+  framework_search_paths: String,
+  /// Value of `GCC_PREPROCESSOR_DEFINITIONS` env var
+  #[clap(long)]
+  gcc_preprocessor_definitions: String,
+  /// Value of `HEADER_SEARCH_PATHS` env var
+  #[clap(long)]
+  header_search_paths: String,
   /// Value of `CONFIGURATION` env var
   #[clap(long)]
   configuration: String,
@@ -38,6 +47,17 @@ pub fn command(options: Options) -> Result<()> {
     }
   }
 
+  // `xcode-script` is ran from the `gen/apple` folder.
+  std::env::set_current_dir(
+    std::env::current_dir()
+      .unwrap()
+      .parent()
+      .unwrap()
+      .parent()
+      .unwrap(),
+  )
+  .unwrap();
+
   let profile = profile_from_configuration(&options.configuration);
   let macos = macos_from_platform(&options.platform);
 
@@ -46,7 +66,9 @@ pub fn command(options: Options) -> Result<()> {
     // The `PATH` env var Xcode gives us is missing any additions
     // made by the user's profile, so we'll manually add cargo's
     // `PATH`.
-    let env = env.prepend_to_path(util::home_dir()?.join(".cargo/bin"));
+    let env = env
+      .explicit_env_vars(cli_options.vars)
+      .prepend_to_path(util::home_dir()?.join(".cargo/bin"));
 
     if !options.sdk_root.is_dir() {
       return Err(anyhow::anyhow!(
@@ -62,10 +84,42 @@ pub fn command(options: Options) -> Result<()> {
       ));
     }
 
+    // Host flags that are used by build scripts
+    let macos_isysroot = {
+      let macos_sdk_root = options
+        .sdk_root
+        .join("../../../../MacOSX.platform/Developer/SDKs/MacOSX.sdk");
+      if !macos_sdk_root.is_dir() {
+        return Err(anyhow::anyhow!(
+          "Invalid SDK root {}",
+          macos_sdk_root.display()
+        ));
+      }
+      format!("-isysroot {}", macos_sdk_root.display())
+    };
+
     let mut host_env = HashMap::<&str, &OsStr>::new();
 
     host_env.insert("RUST_BACKTRACE", "1".as_ref());
 
+    host_env.insert("CFLAGS_x86_64_apple_darwin", macos_isysroot.as_ref());
+    host_env.insert("CXXFLAGS_x86_64_apple_darwin", macos_isysroot.as_ref());
+
+    host_env.insert(
+      "OBJC_INCLUDE_PATH_x86_64_apple_darwin",
+      include_dir.as_os_str(),
+    );
+
+    host_env.insert(
+      "FRAMEWORK_SEARCH_PATHS",
+      options.framework_search_paths.as_ref(),
+    );
+    host_env.insert(
+      "GCC_PREPROCESSOR_DEFINITIONS",
+      options.gcc_preprocessor_definitions.as_ref(),
+    );
+    host_env.insert("HEADER_SEARCH_PATHS", options.header_search_paths.as_ref());
+
     let macos_target = Target::macos();
 
     let isysroot = format!("-isysroot {}", options.sdk_root.display());
@@ -76,6 +130,7 @@ pub fn command(options: Options) -> Result<()> {
         "arm64" => "aarch64_apple_ios",
         "arm64-sim" => "aarch64_apple_ios_sim",
         "x86_64" => "x86_64_apple_ios",
+        "Simulator" => continue,
         _ => {
           return Err(anyhow::anyhow!(
             "Arch specified by Xcode was invalid. {} isn't a known arch",

+ 1 - 0
tooling/cli/src/mobile/mod.rs

@@ -138,6 +138,7 @@ fn env_vars() -> HashMap<String, OsString> {
     if (k.starts_with("TAURI") && k != "TAURI_PRIVATE_KEY" && k != "TAURI_KEY_PASSWORD")
       || k.starts_with("WRY")
       || k == "TMPDIR"
+      || k == "PATH"
     {
       vars.insert(k.into_owned(), v);
     }

+ 11 - 19
tooling/cli/templates/mobile/ios/project.yml

@@ -76,11 +76,11 @@ targets:
         ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES: true
       groups: [app]
     dependencies:
-      - target: lib_{{app.name}}_iOS
-        embed: false
-        link: false
       - framework: lib{{snake-case app.name}}.a
         embed: false
+      {{~#each ios-libraries}}
+      - framework: {{this}}
+        embed: false{{/each}}
       {{~#each ios-vendor-frameworks}}
       - framework: {{prefix-path this}}{{/each}}
       {{~#each ios-vendor-sdks}}
@@ -94,7 +94,6 @@ targets:
       {{~#each ios-frameworks}}
       - sdk: {{this}}.framework{{/each}}
       - sdk: WebKit.framework
-    {{~#if ios-pre-build-scripts}}
     preBuildScripts:
       {{~#each ios-pre-build-scripts}}{{#if this.path}}
       - path {{this.path}}{{/if}}{{#if this.script}}
@@ -113,8 +112,14 @@ targets:
         runOnlyWhenInstalling: {{this.run-only-when-installing}}{{/if}}{{#if this.based-on-dependency-analysis}}
         basedOnDependencyAnalysis: {{this.based-on-dependency-analysis}}{{/if}}{{#if this.discovered-dependency-file}}
         discoveredDependencyFile: {{this.discovered-dependency-file}}{{/if}}
-      {{~/each~}}
-    {{~/if~}}
+      {{~/each}}
+
+      - script: {{ tauri-binary }} {{ tauri-binary-args-str }} -v --platform ${PLATFORM_DISPLAY_NAME:?} --sdk-root ${SDKROOT:?} --framework-search-paths "${FRAMEWORK_SEARCH_PATHS:?}" --header-search-paths "${HEADER_SEARCH_PATHS:?}" --gcc-preprocessor-definitions "${GCC_PREPROCESSOR_DEFINITIONS:?}" --configuration ${CONFIGURATION:?} ${FORCE_COLOR} ${ARCHS:?}
+        name: Build Rust Code
+        basedOnDependencyAnalysis: false
+        outputFiles:
+          - $(SRCROOT)/target/aarch64-apple-ios/${CONFIGURATION}/deps/lib{{snake-case app.name}}.a
+          - $(SRCROOT)/target/x86_64-apple-ios/${CONFIGURATION}/deps/lib{{snake-case app.name}}.a
     {{~#if ios-post-compile-scripts}}
     postCompileScripts:
       {{~#each ios-post-compile-scripts}}{{#if this.path}}
@@ -157,16 +162,3 @@ targets:
         discoveredDependencyFile: {{this.discovered-dependency-file}}{{/if}}
       {{~/each~}}
     {{~/if}}
-
-  lib_{{app.name}}_iOS:
-    type: ""
-    platform: iOS
-    settings:
-      ENABLE_BITCODE: false
-      ARCHS: [{{join ios-valid-archs}}]
-      VALID_ARCHS: {{~#each ios-valid-archs}} {{this}} {{/each}}
-    legacy:
-      toolPath: {{ tauri-binary }}
-      arguments: {{ tauri-binary-args-str }} -v --platform ${PLATFORM_DISPLAY_NAME:?} --sdk-root ${SDKROOT:?} --configuration ${CONFIGURATION:?} ${FORCE_COLOR} ${ARCHS:?}
-      passSettings: false # prevents evil linker errors
-      workingDirectory: $(SRCROOT)/../..