Skip to content

Mac Catalyst: ld is trying to find prebuilt rustlib when building with -Z build-std #107670

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

Closed
imWildCat opened this issue Feb 4, 2023 · 9 comments
Labels
C-bug Category: This is a bug. O-ios Operating system: iOS O-macos Operating system: macOS

Comments

@imWildCat
Copy link
Contributor

imWildCat commented Feb 4, 2023

I tried this code:

fn main() {
    println!("Hello, world!");
}

with cargo +nightly build --verbose -Z build-std --target x86_64-apple-ios-macabi

source: https://github.com/imWildCat-archived/rs-demo/blob/main/src/main.rs

I expected to see this happen: this code can be built with cargo, with nightly toolchain, targeting x86_64-apple-ios-macabi

Instead, this happened:

Compiling rs-demo v0.1.0 (/Users/runner/work/rs-demo/rs-demo)
...
...
= note: ld: warning: directory not found for option '-L/Users/runner/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-ios-macabi/lib'
[80](https://github.com/imWildCat-archived/rs-demo/actions/runs/4092406201/jobs/7057120479#step:6:81)
          ld: warning: directory not found for option '-L/Users/runner/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-ios-macabi/lib'
[81](https://github.com/imWildCat-archived/rs-demo/actions/runs/4092406201/jobs/7057120479#step:6:82)
          ld: building for Mac Catalyst, but linking in object file built for , file '/Users/runner/work/rs-demo/rs-demo/target/x86_64-apple-ios-macabi/debug/deps/rs_demo-521d12542c4c7be3.184v2gvf82jr0rex.rcgu.o'
[82](https://github.com/imWildCat-archived/rs-demo/actions/runs/4092406201/jobs/7057120479#step:6:83)
          clang: error: linker command failed with exit code 1 (use -v to see invocation)
[83](https://github.com/imWildCat-archived/rs-demo/actions/runs/4092406201/jobs/7057120479#step:6:84)
          
[84](https://github.com/imWildCat-archived/rs-demo/actions/runs/4092406201/jobs/7057120479#step:6:85)

[85](https://github.com/imWildCat-archived/rs-demo/actions/runs/4092406201/jobs/7057120479#step:6:86)
error: could not compile `rs-demo` due to previous error
[86](https://github.com/imWildCat-archived/rs-demo/actions/runs/4092406201/jobs/7057120479#step:6:87)

[87](https://github.com/imWildCat-archived/rs-demo/actions/runs/4092406201/jobs/7057120479#step:6:88)
Caused by:
[88](https://github.com/imWildCat-archived/rs-demo/actions/runs/4092406201/jobs/7057120479#step:6:89)
  process didn't exit successfully: `rustc --crate-name rs_demo --edition=2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C metadata=521d12542c4c7be3 -C extra-filename=-521d12542c4c7be3 --out-dir /Users/runner/work/rs-demo/rs-demo/target/x86_64-apple-ios-macabi/debug/deps --target x86_64-apple-ios-macabi -C incremental=/Users/runner/work/rs-demo/rs-demo/target/x86_64-apple-ios-macabi/debug/incremental -L dependency=/Users/runner/work/rs-demo/rs-demo/target/x86_64-apple-ios-macabi/debug/deps -L dependency=/Users/runner/work/rs-demo/rs-demo/target/debug/deps --extern 'noprelude:alloc=/Users/runner/work/rs-demo/rs-demo/target/x86_64-apple-ios-macabi/debug/deps/liballoc-9c4e6a45fc1dc0a3.rlib' --extern 'noprelude:compiler_builtins=/Users/runner/work/rs-demo/rs-demo/target/x86_64-apple-ios-macabi/debug/deps/libcompiler_builtins-7d186f938ad1e774.rlib' --extern 'noprelude:core=/Users/runner/work/rs-demo/rs-demo/target/x86_64-apple-ios-macabi/debug/deps/libcore-339a72cfd77df96f.rlib' --extern 'noprelude:panic_unwind=/Users/runner/work/rs-demo/rs-demo/target/x86_64-apple-ios-macabi/debug/deps/libpanic_unwind-06c139a128f5078d.rlib' --extern 'noprelude:proc_macro=/Users/runner/work/rs-demo/rs-demo/target/x86_64-apple-ios-macabi/debug/deps/libproc_macro-b6089ec1e1d5f8a1.rlib' --extern 'noprelude:std=/Users/runner/work/rs-demo/rs-demo/target/x86_64-apple-ios-macabi/debug/deps/libstd-a6b8e5f053fdec98.rlib' -Z unstable-options` (exit status: 1)

Meta

rustc --version --verbose:

rustc 1.67.0 (fc594f156 2023-01-24)
binary: rustc
commit-hash: fc594f15669680fa70d255faec3ca3fb507c3405
commit-date: 2023-01-24
host: x86_64-apple-darwin
release: 1.67.0
LLVM version: 15.0.6

(source)

Nightly version:

rustc 1.69.0-nightly (658fad6c5 2023-02-03)

Full repro: https://github.com/imWildCat-archived/rs-demo/actions/runs/4092406201/jobs/7057120479

Additional notes

This bug has been existing since last summer, probably before +nightly-2022-08-08.
Previously I thought it is related to #106925
But it should be a different issue.

I'm happy to propose a fix. However, I'm not sure where I can start. May I have some hint?

@imWildCat imWildCat added the C-bug Category: This is a bug. label Feb 4, 2023
@thomcc thomcc added O-macos Operating system: macOS O-ios Operating system: iOS labels Feb 4, 2023
@bjorn3
Copy link
Member

bjorn3 commented Feb 6, 2023

The thing described by the issue title is merely a warning. The actual error is building for Mac Catalyst, but linking in object file built for , file '/Users/runner/work/rs-demo/rs-demo/target/x86_64-apple-ios-macabi/debug/deps/rs_demo-521d12542c4c7be3.184v2gvf82jr0rex.rcgu.o. What does file /Users/runner/work/rs-demo/rs-demo/target/x86_64-apple-ios-macabi/debug/deps/rs_demo-521d12542c4c7be3.184v2gvf82jr0rex.rcgu.o show?

@imWildCat
Copy link
Contributor Author

Thanks for helping!

@bjorn3 I made another commit to my demo: https://github.com/imWildCat-archived/rs-demo/actions/runs/4110334750

which created artifacts for target dir.

-rwxr-xr-x@ 1 wildcat  staff   3.0K Feb  7  2023 rs_demo-521d12542c4c7be3.11h1k1cxazyrm761.rcgu.o
-rwxr-xr-x@ 1 wildcat  staff   6.5K Feb  7  2023 rs_demo-521d12542c4c7be3.1b4n3ypj1i7wdx18.rcgu.o
-rwxr-xr-x@ 1 wildcat  staff   2.7K Feb  7  2023 rs_demo-521d12542c4c7be3.1bxeufcsx2uf9wms.rcgu.o
-rwxr-xr-x@ 1 wildcat  staff   3.2K Feb  7  2023 rs_demo-521d12542c4c7be3.2n8jw0mkj0otg1qk.rcgu.o
-rwxr-xr-x@ 1 wildcat  staff   2.7K Feb  7  2023 rs_demo-521d12542c4c7be3.2qji0k665nmkk6cb.rcgu.o
-rwxr-xr-x@ 1 wildcat  staff   4.8K Feb  7  2023 rs_demo-521d12542c4c7be3.3a98xjqypw74yju3.rcgu.o
-rwxr-xr-x@ 1 wildcat  staff   4.6K Feb  7  2023 rs_demo-521d12542c4c7be3.3i3usuytvnh90f5d.rcgu.o
-rwxr-xr-x@ 1 wildcat  staff   1.6K Feb  7  2023 rs_demo-521d12542c4c7be3.3okfkjsnslejtqlm.rcgu.o
-rwxr-xr-x@ 1 wildcat  staff   247B Feb  7  2023 rs_demo-521d12542c4c7be3.d
➜  rust-target-dir-x86_64-apple-ios-macabi cd x86_64-apple-ios-macabi/debug/deps/

➜  deps fd rs_demo-521d12542c4c7be3. -x file {}
./rs_demo-521d12542c4c7be3.3i3usuytvnh90f5d.rcgu.o: Mach-O 64-bit object x86_64
./rs_demo-521d12542c4c7be3.2qji0k665nmkk6cb.rcgu.o: Mach-O 64-bit object x86_64
./rs_demo-521d12542c4c7be3.3okfkjsnslejtqlm.rcgu.o: Mach-O 64-bit object x86_64
./rs_demo-521d12542c4c7be3.1bxeufcsx2uf9wms.rcgu.o: Mach-O 64-bit object x86_64
./rs_demo-521d12542c4c7be3.3a98xjqypw74yju3.rcgu.o: Mach-O 64-bit object x86_64
./rs_demo-521d12542c4c7be3.11h1k1cxazyrm761.rcgu.o: Mach-O 64-bit object x86_64
./rs_demo-521d12542c4c7be3.2n8jw0mkj0otg1qk.rcgu.o: Mach-O 64-bit object x86_64
./rs_demo-521d12542c4c7be3.1b4n3ypj1i7wdx18.rcgu.o: Mach-O 64-bit object x86_64
./rs_demo-521d12542c4c7be3.d: ASCII text

@bjorn3
Copy link
Member

bjorn3 commented Feb 7, 2023

That CI run complains about ld: building for Mac Catalyst, but linking in object file built for , file '/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/rustcIrdx0v/symbols.o' for architecture x86_64 which is an object file produced by the object crate rather than LLVM. @philipc I think a LC_BUILD_VERSION command needs to be emitted by the object crate with the right target platform for the linker to accept object files when compiling for Mac Catalyst. There seems to be a special case where for all platforms except Mac Catalyst an unknown platform is accepted too: https://github.com/apple-oss-distributions/ld64/blob/dbf8f7feb5579761f1623b004bd468bdea7c6225/src/ld/PlatformSupport.cpp#L82-L83

@imWildCat
Copy link
Contributor Author

Thanks! I think we can dedup?

Found a similar one: #106021

cc @thomcc

@bjorn3
Copy link
Member

bjorn3 commented Feb 7, 2023

Yeah, that looks like it is the same issue.

@imWildCat
Copy link
Contributor Author

@bjorn3 thanks! let me try the fix proposed by @ara4n first

@imWildCat
Copy link
Contributor Author

This is really difficult for me. I decided to give up my Mac Catalyst app first. 🥶
I don't think the community should waste time following up on Apple's strange changes anymore. Because almost no one uses Rust to develop Mac Catalyst apps anymore.

@imWildCat imWildCat closed this as not planned Won't fix, can't repro, duplicate, stale Feb 12, 2023
@munhitsu
Copy link

munhitsu commented Apr 7, 2023

I've used automerge 1.0 with a Catalyst app. Now when automerge 2.0 was released I can't migrate because of this bug.

@imWildCat
Copy link
Contributor Author

@munhitsu #106021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. O-ios Operating system: iOS O-macos Operating system: macOS
Projects
None yet
Development

No branches or pull requests

4 participants