tauri-apps / tauri

Build smaller, faster, and more secure desktop and mobile applications with a web frontend.
https://tauri.app
Apache License 2.0
82.7k stars 2.48k forks source link

[bug] - Using sysroot for 'iPhoneOS' but targeting 'MacOSX' #11103

Closed stolinski closed 5 days ago

stolinski commented 1 week ago

Describe the bug

I'm attempting to port Tauri In App Payments to both v2 as well as iOS. Everything is building, but when running tauri ios dev i'm getting an invalid manifest error.

I had posted on Discord about if this was a swift-rs issue or a Tauri issue and was told to open here, but it's possibly a swift-rs issue.

Reproduction

https://github.com/stolinski/scott-ttemp

Run tauri dev ios

Expected behavior

App loads.

Full tauri info output

[✔] Environment
    - OS: Mac OS 15.0.0 arm64 (X64)
    ✔ Xcode Command Line Tools: installed
    ✔ rustc: 1.81.0 (eeb90cda1 2024-09-04)
    ✔ cargo: 1.81.0 (2dbb1af80 2024-08-20)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: stable-aarch64-apple-darwin (default)
    - node: 20.16.0
    - pnpm: 9.7.0
    - npm: 10.8.1
    - bun: 1.0.25

[-] Packages
    - tauri 🦀: 2.0.0-rc.6
    - tauri-build 🦀: 2.0.0-rc.6
    - wry 🦀: 0.42.0
    - tao 🦀: 0.29.1
    - @tauri-apps/api : 2.0.0-rc.4
    - @tauri-apps/cli : 2.0.0-rc.13

[-] Plugins
    - tauri-plugin-shell 🦀: 2.0.0-rc.2
    - @tauri-apps/plugin-shell : 2.0.0-rc.1

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../build
    - devUrl: http://localhost:1420/
    - framework: Svelte
    - bundler: Vite

[-] iOS
    - Developer Teams: Level Up Tutorials LLC (ID: AS6YFWZTTJ), Scott Tolinski (ID: WX3RQ7F2B7)

Stack trace

error: failed to run custom build command for `tauri-plugin-iap v0.0.1 (/Users/scotttolinski/Sites/projects/decider-app/plugins/iap)`

Caused by:
  process didn't exit successfully: `/Users/scotttolinski/Sites/projects/decider-app/src-tauri/target/debug/build/tauri-plugin-iap-096f22ba769ec6f5/build-script-build` (exit status: 101)
  --- stdout
  cargo:rustc-link-search=native=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos
  cargo:rustc-link-search=native=/usr/lib/swift
  cargo:rustc-link-lib=clang_rt.ios
  cargo:rustc-link-search=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/16/lib/darwin

  --- stderr
  error: 'swift-iap': Invalid manifest (compiled with: ["/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc", "-vfsoverlay", "/var/folders/fm/_sgpt7q91_x97jrvd53whjtm0000gn/T/TemporaryDirectory.0ewK2P/vfs.yaml", "-L", "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/ManifestAPI", "-lPackageDescription", "-Xlinker", "-rpath", "-Xlinker", "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/ManifestAPI", "-target", "arm64-apple-macosx13.0", "-sdk", "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.0.sdk", "-F", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks", "-I", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib", "-L", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib", "-swift-version", "5", "-I", "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/ManifestAPI", "-sdk", "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.0.sdk", "-package-description-version", "5.10.0", "/Users/scotttolinski/Sites/projects/decider-app/plugins/iap/swift-iap/Package.swift", "-o", "/var/folders/fm/_sgpt7q91_x97jrvd53whjtm0000gn/T/TemporaryDirectory.FtT0p1/swift-iap-manifest"])
  <unknown>:0: warning: using sysroot for 'iPhoneOS' but targeting 'MacOSX'
  <unknown>:0: error: unable to load standard library for target 'arm64-apple-macosx13.0'
  error: 'swift-iap': Invalid manifest (compiled with: ["/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc", "-vfsoverlay", "/var/folders/fm/_sgpt7q91_x97jrvd53whjtm0000gn/T/TemporaryDirectory.JpQjNZ/vfs.yaml", "-L", "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/ManifestAPI", "-lPackageDescription", "-Xlinker", "-rpath", "-Xlinker", "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/ManifestAPI", "-target", "arm64-apple-macosx13.0", "-sdk", "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.0.sdk", "-F", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks", "-I", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib", "-L", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib", "-swift-version", "5", "-I", "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/ManifestAPI", "-sdk", "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.0.sdk", "-package-description-version", "5.10.0", "/Users/scotttolinski/Sites/projects/decider-app/plugins/iap/swift-iap/Package.swift", "-o", "/var/folders/fm/_sgpt7q91_x97jrvd53whjtm0000gn/T/TemporaryDirectory.m4eIAY/swift-iap-manifest"])
  <unknown>:0: warning: using sysroot for 'iPhoneOS' but targeting 'MacOSX'
  <unknown>:0: error: unable to load standard library for target 'arm64-apple-macosx13.0'
  thread 'main' panicked at /Users/scotttolinski/.cargo/registry/src/index.crates.io-6f17d22bba15001f/swift-rs-1.0.7/src-rs/build.rs:281:17:
  Failed to compile swift package TauriIAP
  stack backtrace:
     0: rust_begin_unwind
               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:665:5
     1: core::panicking::panic_fmt
               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/panicking.rs:74:14
     2: swift_rs::build::SwiftLinker::link
               at /Users/scotttolinski/.cargo/registry/src/index.crates.io-6f17d22bba15001f/swift-rs-1.0.7/src-rs/build.rs:281:17
     3: build_script_build::main
               at ./build.rs:6:5
     4: core::ops::function::FnOnce::call_once
               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/ops/function.rs:250:5
  note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
    Error [tauri_cli_node] Failed to run `cargo build`: command ["cargo", "build", "--package", "decider-app", "--manifest-path", "/Users/scotttolinski/Sites/projects/decider-app/src-tauri/Cargo.toml", "--target", "aarch64-apple-ios", "--features", "tauri/rustls-tls", "--lib", "--no-default-features"] exited with code 101
 ELIFECYCLE  Command failed with exit code 1.

note: Run script build phase 'Build Rust Code' will be run during every build because the option to run the script phase "Based on dependency analysis" is unchecked. (in target 'decider-app_iOS' from project 'decider-app')
** BUILD FAILED **

The following build commands failed:
    PhaseScriptExecution Build\ Rust\ Code /Users/scotttolinski/Library/Developer/Xcode/DerivedData/decider-app-hepjwdpaecdpowcrsqiophscuzit/Build/Intermediates.noindex/decider-app.build/debug-iphoneos/decider-app_iOS.build/Script-BFE46E4EC9F9451DEBF6C466.sh (in target 'decider-app_iOS' from project 'decider-app')
    Building workspace decider-app with scheme decider-app_iOS and configuration debug
(2 failures)
    Error command ["xcodebuild"] exited with code 65
 ELIFECYCLE  Command failed with exit code 1.

Additional context

With some adjustments it worked just fine for MacOS but never for iOS.

FabianLars commented 1 week ago

this should hopefully be fixed by https://github.com/tauri-apps/tauri/pull/11063 - can you try this?

cargo install tauri-cli --git https://github.com/tauri-apps/tauri
cargo tauri build / cargo tauri ios dev

Edit: Or well, maybe not as they were building for iOS, still worth a try i guess. If it doesn't work with the git cli either i guess we'll have to do the same as the PR for the set_env line above it.

FabianLars commented 1 week ago

Okay, i just did what i said in the Edit above, can you try this then please (different branch than above)?

cargo install tauri-cli --git https://github.com/tauri-apps/tauri --branch fix/sysroot
cargo tauri ios dev
stolinski commented 1 week ago

Update here.

I tried to install via cargo install tauri-cli --git https://github.com/tauri-apps/tauri --branch dev since fix/sysroot was merged and deleted but got this compile error when installing.

error[E0432]: unresolved import `tower::util`
   --> /Users/scotttolinski/.cargo/registry/src/index.crates.io-6f17d22bba15001f/jsonrpsee-server-0.24.4/src/utils.rs:37:12
    |
37  | use tower::util::Oneshot;
    |            ^^^^ could not find `util` in `tower`
    |
note: found an item that was configured out
   --> /Users/scotttolinski/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tower-0.4.13/src/lib.rs:215:9
    |
215 | pub mod util;
    |         ^^^^
note: the item is gated behind the `util` feature
   --> /Users/scotttolinski/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tower-0.4.13/src/lib.rs:213:7
    |
213 | #[cfg(feature = "util")]
    |       ^^^^^^^^^^^^^^^^

error[E0432]: unresolved import `tower::ServiceExt`
   --> /Users/scotttolinski/.cargo/registry/src/index.crates.io-6f17d22bba15001f/jsonrpsee-server-0.24.4/src/utils.rs:38:5
    |
38  | use tower::ServiceExt;
    |     ^^^^^^^----------
    |     |      |
    |     |      help: a similar name exists in the module: `Service`
    |     no `ServiceExt` in the root
    |
note: found an item that was configured out
   --> /Users/scotttolinski/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tower-0.4.13/src/lib.rs:223:34
    |
223 | pub use self::util::{service_fn, ServiceExt};
    |                                  ^^^^^^^^^^
note: the item is gated behind the `util` feature
   --> /Users/scotttolinski/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tower-0.4.13/src/lib.rs:220:7
    |
220 | #[cfg(feature = "util")]
    |       ^^^^^^^^^^^^^^^^

   Compiling which v6.0.3
error[E0599]: the method `graceful_shutdown` exists for struct `Pin<&mut UpgradeableConnection<'_, TokioIo<TcpStream>, TowerToHyperService<<... as Layer<...>>::Service>, ...>>`, but its trait bounds were not satisfied
    --> /Users/scotttolinski/.cargo/registry/src/index.crates.io-6f17d22bba15001f/jsonrpsee-server-0.24.4/src/server.rs:1233:19
     |
1233 |                 conn.as_mut().graceful_shutdown();
     |                               ^^^^^^^^^^^^^^^^^ method cannot be called due to unsatisfied trait bounds
     |
    ::: /Users/scotttolinski/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hyper-util-0.1.9/src/rt/tokio.rs:16:1
     |
16   | pub struct TokioExecutor {}
     | ------------------------ doesn't satisfy `_: HttpServerConnExec<TowerToHyperServiceFuture<<HttpMiddleware as Layer<TowerServiceNoHttp<RpcMiddleware>>>::Service, Request<Body>>, Body>`
     |
     = note: the full type name has been written to '/var/folders/fm/_sgpt7q91_x97jrvd53whjtm0000gn/T/cargo-installbRRUJo/release/deps/jsonrpsee_server-11cc40a95bfd3e8c.long-type-1070622843571128600.txt'
     = note: consider using `--verbose` to print the full type name to the console
     = note: the following trait bounds were not satisfied:
             `{type error}: Sized`
             which is required by `TokioExecutor: HttpServerConnExec<utils::TowerToHyperServiceFuture<<HttpMiddleware as Layer<TowerServiceNoHttp<RpcMiddleware>>>::Service, hyper::Request<jsonrpsee_core::http_helpers::Body>>, Body>`

error[E0599]: no method named `oneshot` found for type parameter `S` in the current scope
  --> /Users/scotttolinski/.cargo/registry/src/index.crates.io-6f17d22bba15001f/jsonrpsee-server-0.24.4/src/utils.rs:61:60
   |
51 | impl<S> hyper::service::Service<HttpRequest<hyper::body::Incoming>> for TowerToHyperService<S>
   |      - method `oneshot` not found for this type parameter
...
61 |         TowerToHyperServiceFuture { future: self.service.clone().oneshot(req) }
   |                                                                  ^^^^^^^ method not found in `S`

   Compiling tower v0.5.1
   Compiling reqwest v0.12.7
Some errors have detailed explanations: E0432, E0599.
For more information about an error, try `rustc --explain E0432`.
error: could not compile `jsonrpsee-server` (lib) due to 4 previous errors
warning: build failed, waiting for other jobs to finish...
error: failed to compile `tauri-cli v2.0.0-rc.16 (https://github.com/tauri-apps/tauri?branch=dev#a944b9b0)`, intermediate artifacts can be found at `/var/folders/fm/_sgpt7q91_x97jrvd53whjtm0000gn/T/cargo-installbRRUJo`.
To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path.

So am unable to test the fix.

FabianLars commented 1 week ago

cargo install tauri-cli --git https://github.com/tauri-apps/tauri --branch dev --locked

stolinski commented 1 week ago

Hm. After running cargo install tauri-cli --git https://github.com/tauri-apps/tauri --branch dev --locked Still unable to get passed

  <unknown>:0: warning: using sysroot for 'iPhoneOS' but targeting 'MacOSX'
  <unknown>:0: error: unable to load standard library for target 'arm64-apple-macosx13.0'

fwiw my tauri info looks like

[✔] Environment
    - OS: Mac OS 15.0.0 arm64 (X64)
    ✔ Xcode Command Line Tools: installed
    ✔ rustc: 1.81.0 (eeb90cda1 2024-09-04)
    ✔ cargo: 1.81.0 (2dbb1af80 2024-08-20)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: stable-aarch64-apple-darwin (default)
    - node: 20.16.0
    - pnpm: 9.7.0
    - npm: 10.8.1
    - bun: 1.0.25

[-] Packages
    - tauri 🦀: 2.0.0-rc.15
    - tauri-build 🦀: 2.0.0-rc.12
    - wry 🦀: 0.43.1
    - tao 🦀: 0.30.1
    - tauri-cli 🦀: 2.0.0-rc.16
    - @tauri-apps/api : 2.0.0-rc.5
    - @tauri-apps/cli : 2.0.0-rc.16

[-] Plugins
    - tauri-plugin-shell 🦀: 2.0.0-rc.3
    - @tauri-apps/plugin-shell : 2.0.0-rc.1

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../build
    - devUrl: http://localhost:1420/
    - framework: Svelte
    - bundler: Vite

So CLI version is rc.16

lucasfernog commented 5 days ago

why are you building your iOS plugin code directly with swift-rs instead of using tauri's build script? something like this: https://github.com/tauri-apps/plugins-workspace/blob/3b2bd3065d516735b33519df014a81b0d481c7a8/plugins/notification/build.rs#L28

anyway, you need to remove the SDKROOT environment variable before building the Swift code (like this: https://github.com/tauri-apps/tauri/blob/60a5aea53db02ae6af325812ab97555f2c013d70/crates/tauri-utils/src/build.rs#L23)

stolinski commented 4 days ago

Thank you for the fix, I can confirm it's working. As for why using swift-rs, I was just porting an existing IAP plugin and that was the strategy they used. I'll try the build script approach as well.