Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] Cargo workspace breaks mobile bundler #5865

Closed
JonasKruckenberg opened this issue Dec 19, 2022 · 11 comments
Closed

[bug] Cargo workspace breaks mobile bundler #5865

JonasKruckenberg opened this issue Dec 19, 2022 · 11 comments
Assignees
Labels
platform: Android platform: iOS status: needs triage This issue needs to triage, applied to new issues type: bug

Comments

@JonasKruckenberg
Copy link
Contributor

JonasKruckenberg commented Dec 19, 2022

Describe the bug

I recently started adding a top-level cargo workspace to all my Tauri apps, so that regular cargo commands work without annoying cd src-tauri.

This breaks the mobile bundler however as it apparently expects a hard-coded targetpath for the dylib.

Reproduction

  1. Create a Tauri app that has mobile support (so through ppm crate vite and cargo tauri init)
  2. Add a top level cargo workspace
    [workspace]
    members = ["src-tauri"]
  3. See the error ld: warning: directory not found for option '-L/Users/jonaskruckenberg/Documents/GitHub/elk-desktop/src-tauri/target/aarch64-apple-ios-sim/debug' it is looking in the wrong path for the dylib

Expected behavior

The mobile bundler should use the cargo apis (cargo metadata maybe?) to figure out the correct target directory

Platform and versions

Environment
  › OS: Mac OS 13.0.1 X64
  › Node.js: 18.12.1
  › npm: 8.19.2
  › pnpm: 7.18.1
  › yarn: 1.22.19
  › rustup: 1.25.1
  › rustc: 1.65.0
  › cargo: 1.65.0
  › Rust toolchain: stable-aarch64-apple-darwin 

Packages
WARNING: no lock files found, defaulting to npm
  › @tauri-apps/cli [NPM]: 2.0.0-alpha.0
  › @tauri-apps/api [NPM]: Not installed!
  › tauri [RUST]: 2.0.0-alpha.1 (1.2.2, 2.0.0-alpha.1),
  › tauri-build [RUST]: 2.0.0-alpha.0,
  › tao [RUST]: 0.15.6,
  › wry [RUST]: 0.23.1,

App
  › build-type: bundle
  › CSP: style-src 'self'; media-src https:; connect-src https: wss:; font-src 'self'; default-src 'none'; img-src 'self' data: https:
  › distDir: ../elk/.output/public
  › devPath: http://localhost:5314/

App directory structure
  ├─ target
  ├─ elk
  ├─ .github
  ├─ src-tauri
  └─ .git

iOS
  › Teams: None

Stack trace

Ld /Users/jonaskruckenberg/Library/Developer/Xcode/DerivedData/app-elzodwdekrmvyqaltibljffxgybm/Build/Products/debug-iphonesimulator/app.app/app normal (in target 'app_iOS' from project 'app')
    cd /Users/jonaskruckenberg/Documents/GitHub/elk-desktop/src-tauri/gen/apple
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -target arm64-sim-apple-ios9.0-simulator -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator16.1.sdk -L/Users/jonaskruckenberg/Library/Developer/Xcode/DerivedData/app-elzodwdekrmvyqaltibljffxgybm/Build/Intermediates.noindex/EagerLinkingTBDs -L/Users/jonaskruckenberg/Library/Developer/Xcode/DerivedData/app-elzodwdekrmvyqaltibljffxgybm/Build/Products/debug-iphonesimulator -L/Users/jonaskruckenberg/Documents/GitHub/elk-desktop/src-tauri/target/aarch64-apple-ios-sim/debug -F/Users/jonaskruckenberg/Library/Developer/Xcode/DerivedData/app-elzodwdekrmvyqaltibljffxgybm/Build/Intermediates.noindex/EagerLinkingTBDs -F/Users/jonaskruckenberg/Library/Developer/Xcode/DerivedData/app-elzodwdekrmvyqaltibljffxgybm/Build/Products/debug-iphonesimulator -F. -filelist /Users/jonaskruckenberg/Library/Developer/Xcode/DerivedData/app-elzodwdekrmvyqaltibljffxgybm/Build/Intermediates.noindex/app.build/debug-iphonesimulator/app_iOS.build/Objects-normal/arm64-sim/app.LinkFileList -Xlinker -rpath -Xlinker @executable_path/Frameworks -dead_strip -Xlinker -object_path_lto -Xlinker /Users/jonaskruckenberg/Library/Developer/Xcode/DerivedData/app-elzodwdekrmvyqaltibljffxgybm/Build/Intermediates.noindex/app.build/debug-iphonesimulator/app_iOS.build/Objects-normal/arm64-sim/app_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -Xlinker -objc_abi_version -Xlinker 2 -stdlib\=libc++ -fobjc-arc -fobjc-link-runtime -Xlinker -sectcreate -Xlinker __TEXT -Xlinker __entitlements -Xlinker /Users/jonaskruckenberg/Library/Developer/Xcode/DerivedData/app-elzodwdekrmvyqaltibljffxgybm/Build/Intermediates.noindex/app.build/debug-iphonesimulator/app_iOS.build/app.app-Simulated.xcent -Xlinker -sectcreate -Xlinker __TEXT -Xlinker __ents_der -Xlinker /Users/jonaskruckenberg/Library/Developer/Xcode/DerivedData/app-elzodwdekrmvyqaltibljffxgybm/Build/Intermediates.noindex/app.build/debug-iphonesimulator/app_iOS.build/app.app-Simulated.xcent.der -lapp -framework CoreGraphics -framework Metal -framework MetalKit -framework QuartzCore -framework Security -framework UIKit -framework WebKit -Xlinker -no_adhoc_codesign -Xlinker -dependency_info -Xlinker /Users/jonaskruckenberg/Library/Developer/Xcode/DerivedData/app-elzodwdekrmvyqaltibljffxgybm/Build/Intermediates.noindex/app.build/debug-iphonesimulator/app_iOS.build/Objects-normal/arm64-sim/app_dependency_info.dat -o /Users/jonaskruckenberg/Library/Developer/Xcode/DerivedData/app-elzodwdekrmvyqaltibljffxgybm/Build/Products/debug-iphonesimulator/app.app/app
ld: warning: directory not found for option '-L/Users/jonaskruckenberg/Documents/GitHub/elk-desktop/src-tauri/target/aarch64-apple-ios-sim/debug'
ld: library not found for -lapp
clang: error: linker command failed with exit code 1 (use -v to see invocation)

** BUILD FAILED **


The following build commands failed:
        Ld /Users/jonaskruckenberg/Library/Developer/Xcode/DerivedData/app-elzodwdekrmvyqaltibljffxgybm/Build/Products/debug-iphonesimulator/app.app/app normal (in target 'app_iOS' from project 'app')
(1 failure)
       Error Command "xcodebuild -scheme app_iOS -workspace /Users/jonaskruckenberg/Documents/GitHub/elk-desktop/src-tauri/gen/apple/app.xcodeproj/project.xcworkspace/ -sdk iphonesimulator -configuration debug -arch arm64-sim -allowProvisioningUpdates build" didn't complete successfully, exiting with code 65.

Additional context

No response

@JonasKruckenberg JonasKruckenberg added type: bug status: needs triage This issue needs to triage, applied to new issues platform: iOS labels Dec 19, 2022
@FabianLars
Copy link
Member

FabianLars commented Dec 19, 2022

Same for the build.target-dir config btw

@lucasfernog
Copy link
Member

The iOS usage was fixed by #5807 since we call the target detection used on desktop to move the artifacts to the Xcode project. I'll work on fixing it for Android.

lucasfernog added a commit to tauri-apps/cargo-mobile2 that referenced this issue Dec 28, 2022
This is needed for tauri-apps/tauri#5865. The ideal solution would be moving the target dir resolver from the Tauri CLI to a separate crate, but that's overengineering until someone wants to use the tauri-mobile CLI without Tauri.
@penx
Copy link

penx commented Feb 8, 2023

The iOS usage was fixed by #5807

@lucasfernog I'm getting "ld: library not found for -lapp" when running yarn tauri ios dev

This is a new project, using vite, following the guide today and with the following versions

rust@1.64
tauri@2.0.0-alpha.3
tauri-cli-ios@2.0.0-alpha.2
tauri-build@2.0.0-alpha.1
@tauri-apps/ap@2.0.0-alpha.0
@tauri-apps/cli@2.0.0-alpha.2

yarn add -D @tauri-apps/cli@next @tauri-apps/api@next
yarn tauri init
TAURI_APPLE_DEVELOPMENT_TEAM=XXX yarn tauri ios init
yarn tauri ios dev

(yarn tauri dev runs on macOS fine)

@lucasfernog
Copy link
Member

Did you add the [lib] section in Cargo.toml?

@penx
Copy link

penx commented Feb 8, 2023

I guess I've missed some setup instructions? I've been following

I have the folllowing in lib, which was generated:

[lib]
name = "app_lib"
crate-type = ["staticlib", "cdylib", "rlib"]

And this issue was the only result for this error :)

@penx
Copy link

penx commented Feb 8, 2023

Full Cargo.toml

[package]
name = "app"
version = "0.1.0"
description = "A Tauri App"
authors = ["you"]
license = ""
repository = ""
edition = "2021"
rust-version = "1.64"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
name = "app_lib"
crate-type = ["staticlib", "cdylib", "rlib"]

[build-dependencies]
tauri-build = { version = "2.0.0-alpha.1", features = [] }

[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "2.0.0-alpha.3", features = [] }

[features]
default = []
# this feature is used for production builds or when `devPath` points to the filesystem
# DO NOT remove this
custom-protocol = [ "tauri/custom-protocol" ]

@penx
Copy link

penx commented Feb 8, 2023

using arch x86_64

@penx
Copy link

penx commented Feb 8, 2023

Removing

name = "app_lib"

Seems to have fixed it

@penx
Copy link

penx commented Feb 8, 2023

I can run yarn tauri ios dev with the above change, but with yarn tauri ios build, I'm getting

(...)/Build/Intermediates.noindex/ArchiveIntermediates/myapp_iOS/IntermediateBuildFilesPath/myapp.build/release-iphoneos/myapp_iOS.build/assetcatalog_generated_info.plist

note: Building targets in dependency order
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 'myapp_iOS' from project 'myapp')
2023-02-08 18:24:41.876 xcodebuild[87790:4543154] [MT] IDEDistribution: -[IDEDistributionLogging _createLoggingBundleAtPath:]: Created bundle at path "/var/folders/.../T/myapp_iOS_2023-02-08_18-24-41.876.xcdistributionlogs".
error: exportArchive: The operation couldn’t be completed. Bad file descriptor

Error Domain=NSPOSIXErrorDomain Code=9 "Bad file descriptor"

** EXPORT FAILED **


       Error Command "xcodebuild -quiet -exportArchive -archivePath /.../.../src-tauri/gen/apple/build/myapp_iOS.xcarchive -exportOptionsPlist /.../.../src-tauri/gen/apple/ExportOptions.plist -exportPath /.../.../src-tauri/gen/apple/build" didn't complete successfully, exiting with code 70.

I'll keep trying and will try get a repo with a replication up if I can't solve it.

@penx
Copy link

penx commented Feb 8, 2023

Rerunning the xcodebuild command myself seems to work...

@penx
Copy link

penx commented Feb 22, 2023

Revisiting this today, I'm finding the "Bad file descriptor" happens when using yarn (yarn tauri ios build) but if I switch to using cargo (cargo tauri ios build) the build completes successfully.

I still have beforeBuildCommand and beforeDevCommand using yarn, but initialise the build using cargo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: Android platform: iOS status: needs triage This issue needs to triage, applied to new issues type: bug
Projects
None yet
Development

No branches or pull requests

4 participants