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

Targets filtered out too early #36156

Closed
japaric opened this issue Aug 31, 2016 · 18 comments · Fixed by #77202
Closed

Targets filtered out too early #36156

japaric opened this issue Aug 31, 2016 · 18 comments · Fixed by #77202
Labels
A-frontend Area: Compiler frontend (errors, parsing and HIR) C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@japaric
Copy link
Member

japaric commented Aug 31, 2016

Targets like aarch64-apple-ios don't appear under --print target-list with today's nightly (and latest beta):

$ rustc --print target-list | grep ios || echo (empty)
(empty)

but they appear there if I use the latest stable:

$ rustup run stable rustc --print target-list | grep ios
aarch64-apple-ios
armv7-apple-ios
armv7s-apple-ios
i386-apple-ios
x86_64-apple-ios

It's not like they just don't appear under the list of built-in targets. Using --target aarch64-apple-ios also says that the target doesn't exist

$ rustc --target aarch64-apple-ios --print cfg
error: Error loading target specification: Could not find specification for target "aarch64-apple-ios"

The weird thing is that you can rustup target add aarch64-apple-ios but then you can't use the target:

$ rustup target add aarch64-apple-ios
info: component 'rust-std' for target 'aarch64-apple-ios' is up to date
$ rustc --target aarch64-apple-ios --print cfg
error: Error loading target specification: Could not find specification for target "aarch64-apple-ios"

Meta

$ rustc -V
rustc 1.13.0-nightly (77d2cd28f 2016-08-29)
$ rustup run beta rustc -V
rustc 1.12.0-beta.2 (389dad798 2016-08-24)
$ rustup run stable rustc -V
rustc 1.11.0 (9b21dcd6a 2016-08-15)

cc @alexcrichton

@TimNN
Copy link
Contributor

TimNN commented Aug 31, 2016

Works fine on OS X:

$ rustc +nightly-2016-08-30 --print target-list | grep ios                                                                                                             
aarch64-apple-ios
armv7-apple-ios
armv7s-apple-ios
i386-apple-ios
x86_64-apple-ios

@TimNN
Copy link
Contributor

TimNN commented Aug 31, 2016

I think this was a side effect of #34980 and is directly related to #36157:

  • The code no longer panics if the SDK path cannot be found (returns Results now)
  • When generating the list of targets, the Err Results for the iOS ones are filtered out (and the error messages discarded)
  • Thus the iOS targets cannot be found in the target list

@alexcrichton
Copy link
Member

I believe @TimNN's diagnosis is correct in that #34980 is the cause here.

I feel like we should do a larger refactor and just not return a Result at all. That is, the iOS pieces should all have graceful fallbacks, or we should delay running tools like xcrun until as late as possible (e.g. when actually linking for the target).

@cardoe
Copy link
Contributor

cardoe commented Sep 15, 2016

@alexcrichton The point of the Result was so that in the future if there was a default search path like RFC 131 first mentioned that they could get filtered out if they were invalid for the current version of the compiler used.

@cardoe
Copy link
Contributor

cardoe commented Sep 15, 2016

I will also note that I agree with deferring the xcrun until as late as possible and making that target not fail where it does so that its always printed out. I was just trying to say why we went with the Result because part of the discussion happened on IRC and was not captured in the issue.

@alexcrichton
Copy link
Member

@cardoe yeah I just figure that something like --print target-list should probably print these out and the actual error should just be delayed as long as possible.

@Mark-Simulacrum Mark-Simulacrum added the A-frontend Area: Compiler frontend (errors, parsing and HIR) label May 13, 2017
@Mark-Simulacrum
Copy link
Member

This is still a problem. I suspect that the issue lies with code somewhere in src/librustc_back/target/mod.rs but I'm not sure.

@Mark-Simulacrum Mark-Simulacrum changed the title *-ios targets removed from the compiler? Targets filtered out too early Jul 26, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 26, 2017
@dbrgn
Copy link
Contributor

dbrgn commented Sep 20, 2017

Still having this problem on Linux, on current nightly as well as on stable:

$ rustup target add aarch64-apple-ios
info: component 'rust-std' for target 'aarch64-apple-ios' is up to date
$ cargo lipo --release
error: failed to run `rustc` to learn about target-specific information

Caused by:
  process didn't exit successfully: `rustc - --crate-name ___ --print=file-names --crate-type bin --crate-type proc-macro --crate-type rlib --crate-type staticlib --target aarch64-apple-ios` (exit code: 101)
--- stderr
error: Error loading target specification: Could not find specification for target "aarch64-apple-ios"
  |
  = help: Use `--print target-list` for a list of built-in targets


Cargo exited unsuccessfully: exit code: 101
$ cargo build --release --target aarch64-apple-ios
error: failed to run `rustc` to learn about target-specific information

Caused by:
  process didn't exit successfully: `rustc - --crate-name ___ --print=file-names --crate-type bin --crate-type proc-macro --crate-type rlib --crate-type staticlib --target aarch64-apple-ios` (exit code: 101)
--- stderr
error: Error loading target specification: Could not find specification for target "aarch64-apple-ios"
  |
  = help: Use `--print target-list` for a list of built-in targets

Is there a workaround, or is it currently not possible to build Rust libraries for iOS targets from Linux?

@brianpesy
Copy link

I am receiving the error just above, and I am working on a Mac. I'm trying to build a Rust library for my iOS application right now. Any workarounds to this?

@cardoe
Copy link
Contributor

cardoe commented Feb 15, 2018

Install Xcode along with the necessary SDKs for the iOS target you are trying to build for. What's failing is the following command:
xcrun --show-sdk-path -sdk sdk_name where "sdk_name" is likely "iphoneos".

@cardoe
Copy link
Contributor

cardoe commented Feb 15, 2018

Is there a workaround, or is it currently not possible to build Rust libraries for iOS targets from Linux?

No. It is not possible to use the iOS SDK from any platform other than a Mac. This is not a limitation of Rust but a limitation of the SDK itself.

@brianpesy
Copy link

I've downloaded the SDKs, and I'm using the latest version of Xcode. I'm able to program in Swift and build applications. However, when I run the command, this shows up:

$ xcrun --show-sdk-path -sdk iphoneos
xcrun: error: SDK "iphoneos" cannot be located
xcrun: error: SDK "iphoneos" cannot be located
xcrun: error: unable to lookup item 'Path' in SDK 'iphoneos'

Any ideas on getting around this?

@cardoe
Copy link
Contributor

cardoe commented Feb 18, 2018

I've never done iOS dev and I've only got Xcode really because of some interest in Swift a while back. So that being said, it unfortunately works on my box.

$ xcrun --show-sdk-path -sdk iphoneos
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.2.sdk

I suspect there's probably a component manager in Xcode that allows you to pull in different components and you don't have the iOS SDK installed.

@dbrgn
Copy link
Contributor

dbrgn commented Feb 18, 2018

I'm not an macOS developer at all, but if I remember correctly you have to open the Xcode GUI once, which will ask you to accept some license and download some components. You could be missing those components.

@AlexMikhalev
Copy link

@brianpesy you are missing Xcode installation, Xcode command line tools are not enough. Install full version of Xcode, start it to accept license (it will install additional components) then
xcrun --show-sdk-path -sdk iphoneos will run without errors.

@tmarkovski
Copy link

had the same problem, the solution was to run sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
https://stackoverflow.com/questions/17980759/xcode-select-active-developer-directory-error/17980786#17980786

@isislovecruft
Copy link

I hit this problem today trying to build some @dalek-cryptography code for iOS on a Linux machine and switching to macOS and using @tmarkovski's workaround fixed it for me.

@Jake-Shadle
Copy link

For those who just want to print the ios targets using --print target-list or --print cfg --target aarch64-apple-ios etc, you can create an executable script called xcrun anywhere in your PATH that echos a valid path somewhere on your system, eg.

#!/bin/bash
echo "/home/<your_use_name>"

@bors bors closed this as completed in 37df40b Oct 1, 2020
Jake-Shadle added a commit to EmbarkStudios/cfg-expr that referenced this issue Feb 9, 2024
rust-lang/rust#36156 was apparently resolved years ago, so the hack is no longer needed
Jake-Shadle added a commit to EmbarkStudios/cfg-expr that referenced this issue Feb 9, 2024
* Remove xcrun hack

rust-lang/rust#36156 was apparently resolved years ago, so the hack is no longer needed

* Fixup update script

1.76.0 introduced a few new target keys, but they are experimental and thus not worth supporting until/if they are stabilized.

Also aarch64-apple-watchos was added but does not print in stable due to an LLVM call failing, but does work on nightly, so we use nightly for that ONE target

* Update builtins to 1.76.0

* Fix tests

* Fix lints
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-frontend Area: Compiler frontend (errors, parsing and HIR) C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

Successfully merging a pull request may close this issue.