Brendonovich / swift-rs

Call Swift functions from Rust with ease!
Apache License 2.0
246 stars 28 forks source link

Build Error #41

Closed LeviticusNelson closed 1 year ago

LeviticusNelson commented 1 year ago

There is something going on with one of the flags when trying to build the swift library. This is the error output that I got (i dont know why they have horizontal scroll like this so sorry):

`rustc --crate-name apple --edition=2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=171 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C metadata=547086dcf6d9c495 -C extra-filename=-547086dcf6d9c495 --out-dir /Users/levi/rust-learning-path/apple/target/debug/deps -C incremental=/Users/levi/rust-learning-path/apple/target/debug/incremental -L dependency=/Users/levi/rust-learning-path/apple/target/debug/deps --extern swift_rs=/Users/levi/rust-learning-path/apple/target/debug/deps/libswift_rs-7335deb19aefad88.rlib -L native=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx -L native=/usr/lib/swift -L /opt/homebrew/Cellar/llvm/16.0.0/lib/clang/16/lib/darwin -L native=/Users/levi/rust-learning-path/apple/target/debug/build/apple-04556bd78aa3159f/out/swift-rs/vision-swift/arm64-apple-macosx/debug -l clang_rt.osx -l static=vision-swift`
error: linking with `cc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/opt/homebrew/Cellar/rust/1.68.1/lib/rustlib/aarch64-apple-darwin/bin:/opt/homebrew/opt/llvm/bin:/Users/levi/.local/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/levi/.cargo/bin" VSLANG="1033" ZERO_AR_DATE="1" "cc" "-arch" "arm64" "/var/folders/41/kstpxs7s151d7v9g3vc9d3_40000gn/T/rustckwkX95/symbols.o" "/Users/levi/rust-learning-path/apple/target/debug/deps/apple-547086dcf6d9c495.154d0cghazxorl9r.rcgu.o" "/Users/levi/rust-learning-path/apple/target/debug/deps/apple-547086dcf6d9c495.15qausif7zqtprc7.rcgu.o" "/Users/levi/rust-learning-path/apple/target/debug/deps/apple-547086dcf6d9c495.1iu0d5zfdsuuesyu.rcgu.o" "/Users/levi/rust-learning-path/apple/target/debug/deps/apple-547086dcf6d9c495.1twzhypv2ek3rmrd.rcgu.o" "/Users/levi/rust-learning-path/apple/target/debug/deps/apple-547086dcf6d9c495.263hq7psqtssznr0.rcgu.o" "/Users/levi/rust-learning-path/apple/target/debug/deps/apple-547086dcf6d9c495.2gnj03nbub08yos6.rcgu.o" "/Users/levi/rust-learning-path/apple/target/debug/deps/apple-547086dcf6d9c495.2p2dth3l3yiceoq5.rcgu.o" "/Users/levi/rust-learning-path/apple/target/debug/deps/apple-547086dcf6d9c495.2x3nsifyfohuiesl.rcgu.o" "/Users/levi/rust-learning-path/apple/target/debug/deps/apple-547086dcf6d9c495.2yo30l1iclc8qmbo.rcgu.o" "/Users/levi/rust-learning-path/apple/target/debug/deps/apple-547086dcf6d9c495.35200gmpxtinj2lm.rcgu.o" "/Users/levi/rust-learning-path/apple/target/debug/deps/apple-547086dcf6d9c495.35qvyvdudr9ymhz7.rcgu.o" "/Users/levi/rust-learning-path/apple/target/debug/deps/apple-547086dcf6d9c495.36s5qro8y4aimgkk.rcgu.o" "/Users/levi/rust-learning-path/apple/target/debug/deps/apple-547086dcf6d9c495.39g79ks79xkp3bwx.rcgu.o" "/Users/levi/rust-learning-path/apple/target/debug/deps/apple-547086dcf6d9c495.3arurhv7km2wmiqw.rcgu.o" "/Users/levi/rust-learning-path/apple/target/debug/deps/apple-547086dcf6d9c495.3bk6f9zm1z7zzm4q.rcgu.o" "/Users/levi/rust-learning-path/apple/target/debug/deps/apple-547086dcf6d9c495.3d4k1y9qb1l6noie.rcgu.o" "/Users/levi/rust-learning-path/apple/target/debug/deps/apple-547086dcf6d9c495.3ixl0mqdx2mum42x.rcgu.o" "/Users/levi/rust-learning-path/apple/target/debug/deps/apple-547086dcf6d9c495.3j56ikjfbeduqnii.rcgu.o" "/Users/levi/rust-learning-path/apple/target/debug/deps/apple-547086dcf6d9c495.3jihj07prp8pia2k.rcgu.o" "/Users/levi/rust-learning-path/apple/target/debug/deps/apple-547086dcf6d9c495.3l76cfws8s6f0668.rcgu.o" "/Users/levi/rust-learning-path/apple/target/debug/deps/apple-547086dcf6d9c495.3lvo5q7thgypvks3.rcgu.o" "/Users/levi/rust-learning-path/apple/target/debug/deps/apple-547086dcf6d9c495.3nd9hvgms2o5iu5i.rcgu.o" "/Users/levi/rust-learning-path/apple/target/debug/deps/apple-547086dcf6d9c495.3uwunkks8z74ky7.rcgu.o" "/Users/levi/rust-learning-path/apple/target/debug/deps/apple-547086dcf6d9c495.44s8hlwbua1oad4j.rcgu.o" "/Users/levi/rust-learning-path/apple/target/debug/deps/apple-547086dcf6d9c495.46htggsj5o290x76.rcgu.o" "/Users/levi/rust-learning-path/apple/target/debug/deps/apple-547086dcf6d9c495.4am6l4q3fcg1yxgy.rcgu.o" "/Users/levi/rust-learning-path/apple/target/debug/deps/apple-547086dcf6d9c495.4gt5axjmxcet1rka.rcgu.o" "/Users/levi/rust-learning-path/apple/target/debug/deps/apple-547086dcf6d9c495.4mmmhhxecl9mw5a7.rcgu.o" "/Users/levi/rust-learning-path/apple/target/debug/deps/apple-547086dcf6d9c495.4n43bfgly40y72td.rcgu.o" "/Users/levi/rust-learning-path/apple/target/debug/deps/apple-547086dcf6d9c495.536fuavk9mik4pqd.rcgu.o" "/Users/levi/rust-learning-path/apple/target/debug/deps/apple-547086dcf6d9c495.56kaaik52ttnu92m.rcgu.o" "/Users/levi/rust-learning-path/apple/target/debug/deps/apple-547086dcf6d9c495.5auziozrl4qg4h9s.rcgu.o" "/Users/levi/rust-learning-path/apple/target/debug/deps/apple-547086dcf6d9c495.lsi3jqt4jj6kiej.rcgu.o" "/Users/levi/rust-learning-path/apple/target/debug/deps/apple-547086dcf6d9c495.4bsjo6j3g15k2uwl.rcgu.o" "-L" "/Users/levi/rust-learning-path/apple/target/debug/deps" "-L" "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx" "-L" "/usr/lib/swift" "-L" "/opt/homebrew/Cellar/llvm/16.0.0/lib/clang/16/lib/darwin" "-L" "/Users/levi/rust-learning-path/apple/target/debug/build/apple-04556bd78aa3159f/out/swift-rs/vision-swift/arm64-apple-macosx/debug" "-L" "/opt/homebrew/Cellar/rust/1.68.1/lib/rustlib/aarch64-apple-darwin/lib" "-lclang_rt.osx" "-lvision-swift" "/Users/levi/rust-learning-path/apple/target/debug/deps/libswift_rs-7335deb19aefad88.rlib" "/opt/homebrew/Cellar/rust/1.68.1/lib/rustlib/aarch64-apple-darwin/lib/libstd-23698c4450bc1fde.rlib" "/opt/homebrew/Cellar/rust/1.68.1/lib/rustlib/aarch64-apple-darwin/lib/libpanic_unwind-4939c81e9f485a5a.rlib" "/opt/homebrew/Cellar/rust/1.68.1/lib/rustlib/aarch64-apple-darwin/lib/libobject-91a8703297d6de89.rlib" "/opt/homebrew/Cellar/rust/1.68.1/lib/rustlib/aarch64-apple-darwin/lib/libmemchr-e353b3d653a56cc7.rlib" "/opt/homebrew/Cellar/rust/1.68.1/lib/rustlib/aarch64-apple-darwin/lib/libaddr2line-493393514073a4e7.rlib" "/opt/homebrew/Cellar/rust/1.68.1/lib/rustlib/aarch64-apple-darwin/lib/libgimli-36f160a05208bfbe.rlib" "/opt/homebrew/Cellar/rust/1.68.1/lib/rustlib/aarch64-apple-darwin/lib/librustc_demangle-a2ed42c41738450c.rlib" "/opt/homebrew/Cellar/rust/1.68.1/lib/rustlib/aarch64-apple-darwin/lib/libstd_detect-da3452bfedb91980.rlib" "/opt/homebrew/Cellar/rust/1.68.1/lib/rustlib/aarch64-apple-darwin/lib/libhashbrown-7ca38467bec794b0.rlib" "/opt/homebrew/Cellar/rust/1.68.1/lib/rustlib/aarch64-apple-darwin/lib/libminiz_oxide-6cd00e9f6269c478.rlib" "/opt/homebrew/Cellar/rust/1.68.1/lib/rustlib/aarch64-apple-darwin/lib/libadler-73a9c98315e9bee8.rlib" "/opt/homebrew/Cellar/rust/1.68.1/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_alloc-42a9d24082a53ec4.rlib" "/opt/homebrew/Cellar/rust/1.68.1/lib/rustlib/aarch64-apple-darwin/lib/libunwind-f97f01178ef47923.rlib" "/opt/homebrew/Cellar/rust/1.68.1/lib/rustlib/aarch64-apple-darwin/lib/libcfg_if-43f1ef680b5b75e7.rlib" "/opt/homebrew/Cellar/rust/1.68.1/lib/rustlib/aarch64-apple-darwin/lib/liblibc-e135550b52fb8265.rlib" "/opt/homebrew/Cellar/rust/1.68.1/lib/rustlib/aarch64-apple-darwin/lib/liballoc-1a371dcfae9f04a1.rlib" "/opt/homebrew/Cellar/rust/1.68.1/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_core-aea2164fcc3a714c.rlib" "/opt/homebrew/Cellar/rust/1.68.1/lib/rustlib/aarch64-apple-darwin/lib/libcore-3dd398d88a1b33da.rlib" "/opt/homebrew/Cellar/rust/1.68.1/lib/rustlib/aarch64-apple-darwin/lib/libcompiler_builtins-ccd0efab0862927d.rlib" "-lSystem" "-lc" "-lm" "-L" "/opt/homebrew/Cellar/rust/1.68.1/lib/rustlib/aarch64-apple-darwin/lib" "-o" "/Users/levi/rust-learning-path/apple/target/debug/deps/apple-547086dcf6d9c495" "-Wl,-dead_strip" "-nodefaultlibs"
  = note: ld: library not found for -lvision-swift
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

error: could not compile `apple` due to previous error

Caused by:
  process didn't exit successfully: `rustc --crate-name apple --edition=2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=171 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C metadata=547086dcf6d9c495 -C extra-filename=-547086dcf6d9c495 --out-dir /Users/levi/rust-learning-path/apple/target/debug/deps -C incremental=/Users/levi/rust-learning-path/apple/target/debug/incremental -L dependency=/Users/levi/rust-learning-path/apple/target/debug/deps --extern swift_rs=/Users/levi/rust-learning-path/apple/target/debug/deps/libswift_rs-7335deb19aefad88.rlib -L native=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx -L native=/usr/lib/swift -L /opt/homebrew/Cellar/llvm/16.0.0/lib/clang/16/lib/darwin -L native=/Users/levi/rust-learning-path/apple/target/debug/build/apple-04556bd78aa3159f/out/swift-rs/vision-swift/arm64-apple-macosx/debug -l clang_rt.osx -l static=vision-swift` (exit status: 1)
Brendonovich commented 1 year ago

Oh that's odd - my guess is you've put the wrong path to your swift library? Strange that rustc is giving the error and not cargo. Would you be able to put together a reproduction so I can try it out?

LeviticusNelson commented 1 year ago

@Brendonovich I did use cargo to build but here is the project: https://github.com/LeviticusNelson/apple-vision-rs

Brendonovich commented 1 year ago

Ah, looks like a documentation problem - the Swift library has to be static. Have opened a PR for you.

    products: [
        .library(
            name: "vision-swift",
+           type: .static,
            targets: ["vision-swift"]
        ),
    ],
LeviticusNelson commented 1 year ago

@Brendonovich thanks for the help!