From 0eb782d3834ed581b45d951749be1ae393aaff31 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Sun, 5 May 2024 20:54:37 +0200 Subject: [PATCH 01/29] Document all Apple targets in rustc's platform support - Fixed std support in top-level docs. - Added `*-apple-darwin` docs. - Added `i686-apple-darwin` docs. - Moved `aarch64-apple-ios-sim` to `*-apple-ios` and document all the iOS targets there. - Added `*-apple-ios-macabi` docs. - Add myself (madsmtm) as co-maintainer of most of these targets. --- .../rustc_target/src/spec/base/apple/mod.rs | 5 ++ src/doc/rustc/src/SUMMARY.md | 15 ++-- src/doc/rustc/src/platform-support.md | 26 +++--- .../platform-support/aarch64-apple-ios-sim.md | 55 ------------- .../src/platform-support/apple-darwin.md | 59 ++++++++++++++ .../src/platform-support/apple-ios-macabi.md | 58 ++++++++++++++ .../rustc/src/platform-support/apple-ios.md | 74 +++++++++++++++++ .../rustc/src/platform-support/apple-tvos.md | 79 +++++++++---------- .../src/platform-support/apple-visionos.md | 60 ++++++++------ .../src/platform-support/apple-watchos.md | 71 +++++++++-------- .../platform-support/arm64e-apple-darwin.md | 2 + .../src/platform-support/arm64e-apple-ios.md | 3 +- .../src/platform-support/i686-apple-darwin.md | 41 ++++++++++ .../platform-support/x86_64h-apple-darwin.md | 5 +- 14 files changed, 376 insertions(+), 177 deletions(-) delete mode 100644 src/doc/rustc/src/platform-support/aarch64-apple-ios-sim.md create mode 100644 src/doc/rustc/src/platform-support/apple-darwin.md create mode 100644 src/doc/rustc/src/platform-support/apple-ios-macabi.md create mode 100644 src/doc/rustc/src/platform-support/apple-ios.md create mode 100644 src/doc/rustc/src/platform-support/i686-apple-darwin.md diff --git a/compiler/rustc_target/src/spec/base/apple/mod.rs b/compiler/rustc_target/src/spec/base/apple/mod.rs index d667bad44e3..b12d3f22d8d 100644 --- a/compiler/rustc_target/src/spec/base/apple/mod.rs +++ b/compiler/rustc_target/src/spec/base/apple/mod.rs @@ -271,6 +271,7 @@ fn macos_default_deployment_target(arch: Arch) -> (u32, u32) { fn macos_deployment_target(arch: Arch) -> (u32, u32) { // If you are looking for the default deployment target, prefer `rustc --print deployment-target`. + // Note: If bumping this version, remember to update it in the rustc/platform-support docs. from_set_deployment_target("MACOSX_DEPLOYMENT_TARGET") .unwrap_or_else(|| macos_default_deployment_target(arch)) } @@ -319,6 +320,7 @@ fn link_env_remove(os: &'static str) -> StaticCow<[StaticCow]> { fn ios_deployment_target(arch: Arch, abi: &str) -> (u32, u32) { // If you are looking for the default deployment target, prefer `rustc --print deployment-target`. + // Note: If bumping this version, remember to update it in the rustc/platform-support docs. let (major, minor) = match (arch, abi) { (Arm64e, _) => (14, 0), // Mac Catalyst defaults to 13.1 in Clang. @@ -351,6 +353,7 @@ pub fn ios_sim_llvm_target(arch: Arch) -> String { fn tvos_deployment_target() -> (u32, u32) { // If you are looking for the default deployment target, prefer `rustc --print deployment-target`. + // Note: If bumping this version, remember to update it in the rustc platform-support docs. from_set_deployment_target("TVOS_DEPLOYMENT_TARGET").unwrap_or((10, 0)) } @@ -366,6 +369,7 @@ pub fn tvos_sim_llvm_target(arch: Arch) -> String { fn watchos_deployment_target() -> (u32, u32) { // If you are looking for the default deployment target, prefer `rustc --print deployment-target`. + // Note: If bumping this version, remember to update it in the rustc platform-support docs. from_set_deployment_target("WATCHOS_DEPLOYMENT_TARGET").unwrap_or((5, 0)) } @@ -381,6 +385,7 @@ pub fn watchos_sim_llvm_target(arch: Arch) -> String { fn visionos_deployment_target() -> (u32, u32) { // If you are looking for the default deployment target, prefer `rustc --print deployment-target`. + // Note: If bumping this version, remember to update it in the rustc platform-support docs. from_set_deployment_target("XROS_DEPLOYMENT_TARGET").unwrap_or((1, 0)) } diff --git a/src/doc/rustc/src/SUMMARY.md b/src/doc/rustc/src/SUMMARY.md index c9c0ee4067f..a309110e875 100644 --- a/src/doc/rustc/src/SUMMARY.md +++ b/src/doc/rustc/src/SUMMARY.md @@ -16,13 +16,17 @@ - [Platform Support](platform-support.md) - [Target Tier Policy](target-tier-policy.md) - [Template for Target-specific Documentation](platform-support/TEMPLATE.md) - - [arm64e-apple-ios.md](platform-support/arm64e-apple-ios.md) - - [arm64e-apple-darwin.md](platform-support/arm64e-apple-darwin.md) - - [aarch64-apple-ios-sim](platform-support/aarch64-apple-ios-sim.md) - [arm64ec-pc-windows-msvc](platform-support/arm64ec-pc-windows-msvc.md) + - [\*-apple-darwin](platform-support/apple-darwin.md) + - [i686-apple-darwin](platform-support/i686-apple-darwin.md) + - [x86_64h-apple-darwin](platform-support/x86_64h-apple-darwin.md) + - [arm64e-apple-darwin.md](platform-support/arm64e-apple-darwin.md) + - [\*-apple-ios](platform-support/apple-ios.md) + - [\*-apple-ios-macabi](platform-support/apple-ios-macabi.md) + - [arm64e-apple-ios.md](platform-support/arm64e-apple-ios.md) - [\*-apple-tvos](platform-support/apple-tvos.md) - - [\*-apple-watchos\*](platform-support/apple-watchos.md) - - [aarch64-apple-visionos\*](platform-support/apple-visionos.md) + - [\*-apple-watchos](platform-support/apple-watchos.md) + - [\*-apple-visionos](platform-support/apple-visionos.md) - [aarch64-nintendo-switch-freestanding](platform-support/aarch64-nintendo-switch-freestanding.md) - [armeb-unknown-linux-gnueabi](platform-support/armeb-unknown-linux-gnueabi.md) - [arm-none-eabi](platform-support/arm-none-eabi.md) @@ -75,7 +79,6 @@ - [\*-win7-windows-msvc](platform-support/win7-windows-msvc.md) - [x86_64-fortanix-unknown-sgx](platform-support/x86_64-fortanix-unknown-sgx.md) - [x86_64-unknown-none](platform-support/x86_64-unknown-none.md) - - [x86_64h-apple-darwin](platform-support/x86_64h-apple-darwin.md) - [Targets](targets/index.md) - [Built-in Targets](targets/built-in.md) - [Custom Targets](targets/custom.md) diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index 764798a80e6..5c8789d03df 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -36,7 +36,7 @@ target | notes `i686-pc-windows-gnu` | 32-bit MinGW (Windows 10+) [^x86_32-floats-return-ABI] `i686-pc-windows-msvc` | 32-bit MSVC (Windows 10+) [^x86_32-floats-return-ABI] `i686-unknown-linux-gnu` | 32-bit Linux (kernel 3.2+, glibc 2.17+) [^x86_32-floats-return-ABI] -`x86_64-apple-darwin` | 64-bit macOS (10.12+, Sierra+) +[`x86_64-apple-darwin`](platform-support/apple-darwin.md) | 64-bit macOS (10.12+, Sierra+) `x86_64-pc-windows-gnu` | 64-bit MinGW (Windows 10+) `x86_64-pc-windows-msvc` | 64-bit MSVC (Windows 10+) `x86_64-unknown-linux-gnu` | 64-bit Linux (kernel 3.2+, glibc 2.17+) @@ -86,7 +86,7 @@ so Rustup may install the documentation for a similar tier 1 target instead. target | notes -------|------- -`aarch64-apple-darwin` | ARM64 macOS (11.0+, Big Sur+) +[`aarch64-apple-darwin`](platform-support/apple-darwin.md) | ARM64 macOS (11.0+, Big Sur+) `aarch64-pc-windows-msvc` | ARM64 Windows MSVC `aarch64-unknown-linux-musl` | ARM64 Linux with musl 1.2.3 `arm-unknown-linux-gnueabi` | Armv6 Linux (kernel 3.2, glibc 2.17) @@ -133,8 +133,8 @@ so Rustup may install the documentation for a similar tier 1 target instead. target | std | notes -------|:---:|------- -`aarch64-apple-ios` | ✓ | ARM64 iOS -[`aarch64-apple-ios-sim`](platform-support/aarch64-apple-ios-sim.md) | ✓ | Apple iOS Simulator on ARM64 +[`aarch64-apple-ios`](platform-support/apple-ios.md) | ✓ | ARM64 iOS +[`aarch64-apple-ios-sim`](platform-support/apple-ios.md) | ✓ | Apple iOS Simulator on ARM64 `aarch64-fuchsia` | ✓ | Alias for `aarch64-unknown-fuchsia` [`aarch64-unknown-fuchsia`](platform-support/fuchsia.md) | ✓ | ARM64 Fuchsia [`aarch64-linux-android`](platform-support/android.md) | ✓ | ARM64 Android @@ -192,7 +192,7 @@ target | std | notes `wasm32-wasi` | ✓ | WebAssembly with WASI (undergoing a [rename to `wasm32-wasip1`][wasi-rename]) [`wasm32-wasip1`](platform-support/wasm32-wasip1.md) | ✓ | WebAssembly with WASI [`wasm32-wasip1-threads`](platform-support/wasm32-wasip1-threads.md) | ✓ | | WebAssembly with WASI Preview 1 and threads -`x86_64-apple-ios` | ✓ | 64-bit x86 iOS +[`x86_64-apple-ios`](platform-support/apple-ios.md) | ✓ | 64-bit x86 iOS [`x86_64-fortanix-unknown-sgx`](platform-support/x86_64-fortanix-unknown-sgx.md) | ✓ | [Fortanix ABI] for 64-bit Intel SGX `x86_64-fuchsia` | ✓ | Alias for `x86_64-unknown-fuchsia` [`x86_64-unknown-fuchsia`](platform-support/fuchsia.md) | ✓ | 64-bit x86 Fuchsia @@ -241,9 +241,9 @@ target | std | host | notes [`arm64e-apple-ios`](platform-support/arm64e-apple-ios.md) | ✓ | | ARM64e Apple iOS [`arm64e-apple-darwin`](platform-support/arm64e-apple-darwin.md) | ✓ | ✓ | ARM64e Apple Darwin [`arm64ec-pc-windows-msvc`](platform-support/arm64ec-pc-windows-msvc.md) | ? | | Arm64EC Windows MSVC -`aarch64-apple-ios-macabi` | ? | | Apple Catalyst on ARM64 -[`aarch64-apple-tvos`](platform-support/apple-tvos.md) | ? | | ARM64 tvOS -[`aarch64-apple-tvos-sim`](platform-support/apple-tvos.md) | ? | | ARM64 tvOS Simulator +[`aarch64-apple-ios-macabi`](platform-support/apple-ios-macabi.md) | ✓ | | Apple Catalyst on ARM64 +[`aarch64-apple-tvos`](platform-support/apple-tvos.md) | ✓ | | ARM64 tvOS +[`aarch64-apple-tvos-sim`](platform-support/apple-tvos.md) | ✓ | | ARM64 tvOS Simulator [`aarch64-apple-watchos`](platform-support/apple-watchos.md) | ✓ | | ARM64 Apple WatchOS [`aarch64-apple-watchos-sim`](platform-support/apple-watchos.md) | ✓ | | ARM64 Apple WatchOS Simulator [`aarch64-apple-visionos`](platform-support/apple-visionos.md) | ✓ | | ARM64 Apple visionOS @@ -283,7 +283,7 @@ target | std | host | notes [`armv7a-kmc-solid_asp3-eabihf`](platform-support/kmc-solid.md) | ✓ | | ARM SOLID with TOPPERS/ASP3, hardfloat [`armv7a-none-eabihf`](platform-support/arm-none-eabi.md) | * | | Bare Armv7-A, hardfloat [`armv7k-apple-watchos`](platform-support/apple-watchos.md) | ✓ | | Armv7-A Apple WatchOS -`armv7s-apple-ios` | ✓ | | Armv7-A Apple-A6 Apple iOS +[`armv7s-apple-ios`](platform-support/apple-ios.md) | ✓ | | Armv7-A Apple-A6 Apple iOS [`armv8r-none-eabihf`](platform-support/armv8r-none-eabihf.md) | * | | Bare Armv8-R, hardfloat `avr-unknown-gnu-atmega328` | * | | AVR. Requires `-Z build-std=core` `bpfeb-unknown-none` | * | | BPF (big endian) @@ -292,10 +292,10 @@ target | std | host | notes `csky-unknown-linux-gnuabiv2hf` | ✓ | | C-SKY abiv2 Linux, hardfloat (little endian) [`hexagon-unknown-none-elf`](platform-support/hexagon-unknown-none-elf.md)| * | | Bare Hexagon (v60+, HVX) [`hexagon-unknown-linux-musl`](platform-support/hexagon-unknown-linux-musl.md) | ✓ | | Hexagon Linux with musl 1.2.3 -`i386-apple-ios` | ✓ | | 32-bit x86 iOS [^x86_32-floats-return-ABI] +[`i386-apple-ios`](platform-support/apple-ios.md) | ✓ | | 32-bit x86 iOS [^x86_32-floats-return-ABI] [`i586-pc-nto-qnx700`](platform-support/nto-qnx.md) | * | | 32-bit x86 QNX Neutrino 7.0 RTOS [^x86_32-floats-return-ABI] [`i586-unknown-netbsd`](platform-support/netbsd.md) | ✓ | | 32-bit x86, restricted to Pentium -`i686-apple-darwin` | ✓ | ✓ | 32-bit macOS (10.12+, Sierra+) [^x86_32-floats-return-ABI] +[`i686-apple-darwin`](platform-support/apple-darwin.md) | ✓ | ✓ | 32-bit macOS (10.12+, Sierra+) [^x86_32-floats-return-ABI] `i686-unknown-haiku` | ✓ | ✓ | 32-bit Haiku [^x86_32-floats-return-ABI] [`i686-unknown-hurd-gnu`](platform-support/hurd.md) | ✓ | ✓ | 32-bit GNU/Hurd [^x86_32-floats-return-ABI] [`i686-unknown-netbsd`](platform-support/netbsd.md) | ✓ | ✓ | NetBSD/i386 with SSE2 [^x86_32-floats-return-ABI] @@ -367,8 +367,8 @@ target | std | host | notes `thumbv7neon-unknown-linux-musleabihf` | ? | | Thumb2-mode Armv7-A Linux with NEON, musl 1.2.3 [`wasm32-wasip2`](platform-support/wasm32-wasip2.md) | ✓ | | WebAssembly [`wasm64-unknown-unknown`](platform-support/wasm64-unknown-unknown.md) | ? | | WebAssembly -`x86_64-apple-ios-macabi` | ✓ | | Apple Catalyst on x86_64 -[`x86_64-apple-tvos`](platform-support/apple-tvos.md) | ? | | x86 64-bit tvOS +[`x86_64-apple-ios-macabi`](platform-support/apple-ios-macabi.md) | ✓ | | Apple Catalyst on x86_64 +[`x86_64-apple-tvos`](platform-support/apple-tvos.md) | ✓ | | x86 64-bit tvOS [`x86_64-apple-watchos-sim`](platform-support/apple-watchos.md) | ✓ | | x86 64-bit Apple WatchOS simulator [`x86_64-pc-nto-qnx710`](platform-support/nto-qnx.md) | ✓ | | x86 64-bit QNX Neutrino 7.1 RTOS | [`x86_64-unikraft-linux-musl`](platform-support/unikraft-linux-musl.md) | ✓ | | 64-bit Unikraft with musl 1.2.3 diff --git a/src/doc/rustc/src/platform-support/aarch64-apple-ios-sim.md b/src/doc/rustc/src/platform-support/aarch64-apple-ios-sim.md deleted file mode 100644 index 3f29e2c5e1f..00000000000 --- a/src/doc/rustc/src/platform-support/aarch64-apple-ios-sim.md +++ /dev/null @@ -1,55 +0,0 @@ -# aarch64-apple-ios-sim - -**Tier: 2** - -Apple iOS Simulator on ARM64. - -## Designated Developers - -* [@badboy](https://github.com/badboy) -* [@deg4uss3r](https://github.com/deg4uss3r) - -## Requirements - -This target is cross-compiled. -To build this target Xcode 12 or higher on macOS is required. - -## Building - -The target can be built by enabling it for a `rustc` build: - -```toml -[build] -build-stage = 1 -target = ["aarch64-apple-ios-sim"] -``` - -## Cross-compilation - -This target can be cross-compiled from `x86_64` or `aarch64` macOS hosts. - -Other hosts are not supported for cross-compilation, but might work when also providing the required Xcode SDK. - -## Testing - -Currently there is no support to run the rustc test suite for this target. - - -## Building Rust programs - -*Note: Building for this target requires the corresponding iOS SDK, as provided by Xcode 12+.* - -From Rust Nightly 1.56.0 (2021-08-03) on the artifacts are shipped pre-compiled: - -```text -rustup target add aarch64-apple-ios-sim --toolchain nightly -``` - -Rust programs can be built for that target: - -```text -rustc --target aarch64-apple-ios-sim your-code.rs -``` - -There is no easy way to run simple programs in the iOS simulator. -Static library builds can be embedded into iOS applications. diff --git a/src/doc/rustc/src/platform-support/apple-darwin.md b/src/doc/rustc/src/platform-support/apple-darwin.md new file mode 100644 index 00000000000..0fb86949a4b --- /dev/null +++ b/src/doc/rustc/src/platform-support/apple-darwin.md @@ -0,0 +1,59 @@ +# `*-apple-darwin` + +Apple macOS targets. + +**Tier: 1** + +- `x86_64-apple-darwin`: macOS on 64-bit x86. + +**Tier: 2 (with Host Tools)** + +- `aarch64-apple-darwin`: macOS on ARM64 (M1-family or later Apple Silicon CPUs). + +## Target maintainers + +- [@thomcc](https://github.com/thomcc) +- [@madsmtm](https://github.com/madsmtm) + +## Requirements + +### OS version + +The minimum supported version is macOS 10.12 Sierra on x86, and macOS 11.0 Big +Sur on ARM64. + +This version can be raised per-binary by changing the [deployment target], +which might yield more performance optimizations. `rustc` respects the common +environment variables used by Xcode to do so, in this case +`MACOSX_DEPLOYMENT_TARGET`. + +The current default deployment target for `rustc` can be retrieved with +[`rustc --print=deployment-target`][rustc-print]. + +[deployment target]: https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/cross_development/Configuring/configuring.html +[rustc-print]: ../command-line-arguments.md#option-print + +### Binary format + +The default binary format is Mach-O, the executable format used on Apple's +platforms. + +## Building + +These targets are distributed through `rustup`, and otherwise require no +special configuration. + +## Testing + +There are no special requirements for testing and running this target. + +x86 binaries can be run on Apple Silicon by using Rosetta. + +## Cross-compilation toolchains and C code + +Cross-compilation of these targets are supported using Clang, but may require +Xcode or the macOS SDK (`MacOSX.sdk`) to be available to compile C code and +to link. + +The path to the SDK can be passed to `rustc` using the common `SDKROOT` +environment variable. diff --git a/src/doc/rustc/src/platform-support/apple-ios-macabi.md b/src/doc/rustc/src/platform-support/apple-ios-macabi.md new file mode 100644 index 00000000000..278ee94b6d4 --- /dev/null +++ b/src/doc/rustc/src/platform-support/apple-ios-macabi.md @@ -0,0 +1,58 @@ +# `*-apple-ios-macabi` + +Apple Mac Catalyst targets. + +**Tier: 3** + +- `aarch64-apple-ios-macabi`: Mac Catalyst on ARM64. +- `x86_64-apple-ios-macabi`: Mac Catalyst on 64-bit x86. + +## Target maintainers + +- [@madsmtm](https://github.com/madsmtm) + +## Requirements + +These targets are cross-compiled, and require the corresponding macOS SDK +(`MacOSX.sdk`) which contain `./System/iOSSupport` headers to allow linking to +iOS-specific headers, as provided by Xcode 11 or higher. + +The path to the SDK can be passed to `rustc` using the common `SDKROOT` +environment variable. + +### OS version + +The minimum supported version is iOS 13.1. + +This can be raised per-binary by changing the deployment target. `rustc` +respects the common environment variables used by Xcode to do so, in this +case `IPHONEOS_DEPLOYMENT_TARGET`. + +## Building the target + +The targets can be built by enabling them for a `rustc` build in +`config.toml`, by adding, for example: + +```toml +[build] +target = ["aarch64-apple-ios-macabi", "x86_64-apple-ios-macabi"] +``` + +Using the unstable `-Zbuild-std` with a nightly Cargo may also work. + +## Building Rust programs + +Rust programs can be built for these targets by specifying `--target`, if +`rustc` has been built with support for them. For example: + +```console +$ rustc --target aarch64-apple-ios-macabi your-code.rs +``` + +## Testing + +Mac Catalyst binaries can be run directly on macOS 10.15 Catalina or newer. + +x86 binaries can be run on Apple Silicon by using Rosetta. + +Note that using certain UIKit functionality requires the binary to be bundled. diff --git a/src/doc/rustc/src/platform-support/apple-ios.md b/src/doc/rustc/src/platform-support/apple-ios.md new file mode 100644 index 00000000000..5045f810400 --- /dev/null +++ b/src/doc/rustc/src/platform-support/apple-ios.md @@ -0,0 +1,74 @@ +# `*-apple-ios` + +Apple iOS / iPadOS targets. + +**Tier: 2 (without Host Tools)** + +- `aarch64-apple-ios`: Apple iOS on ARM64. +- `aarch64-apple-ios-sim`: Apple iOS Simulator on ARM64. +- `x86_64-apple-ios`: Apple iOS Simulator on 64-bit x86. + +**Tier: 3** + +- `armv7s-apple-ios`: Apple iOS on Armv7-A. +- `i386-apple-ios`: Apple iOS Simulator on 32-bit x86. + +## Target maintainers + +- [@badboy](https://github.com/badboy) +- [@deg4uss3r](https://github.com/deg4uss3r) +- [@madsmtm](https://github.com/madsmtm) + +## Requirements + +These targets are cross-compiled, and require the corresponding iOS SDK +(`iPhoneOS.sdk` or `iPhoneSimulator.sdk`), as provided by Xcode. To build the +ARM64 targets, Xcode 12 or higher is required. + +The path to the SDK can be passed to `rustc` using the common `SDKROOT` +environment variable. + +### OS version + +The minimum supported version is iOS 10.0. + +This can be raised per-binary by changing the deployment target. `rustc` +respects the common environment variables used by Xcode to do so, in this +case `IPHONEOS_DEPLOYMENT_TARGET`. + +## Building the target + +The tier 2 targets are distributed through `rustup`, and can be installed +using one of: +```console +$ rustup target add aarch64-apple-ios +$ rustup target add aarch64-apple-ios-sim +$ rustup target add x86_64-apple-ios +``` + +The tier 3 targets can be built by enabling them for a `rustc` build in +`config.toml`, by adding, for example: + +```toml +[build] +target = ["armv7s-apple-ios", "i386-apple-ios"] +``` + +Using the unstable `-Zbuild-std` with a nightly Cargo may also work. + +## Building Rust programs + +Rust programs can be built for these targets by specifying `--target`, if +`rustc` has been built with support for them. For example: + +```console +$ rustc --target aarch64-apple-ios your-code.rs +``` + +## Testing + +There is no support for running the Rust or standard library testsuite at the +moment. Testing has mostly been done manually with builds of static libraries +embedded into applications called from Xcode or a simulator. + +It hopefully will be possible to improve this in the future. diff --git a/src/doc/rustc/src/platform-support/apple-tvos.md b/src/doc/rustc/src/platform-support/apple-tvos.md index e7ea109df1b..7a3b601579a 100644 --- a/src/doc/rustc/src/platform-support/apple-tvos.md +++ b/src/doc/rustc/src/platform-support/apple-tvos.md @@ -1,40 +1,44 @@ # `*-apple-tvos` -- aarch64-apple-tvos -- x86_64-apple-tvos + +Apple tvOS targets. **Tier: 3** -Apple tvOS targets: -- Apple tvOS on aarch64 -- Apple tvOS Simulator on x86_64 +- `aarch64-apple-tvos`: Apple tvOS on ARM64. +- `aarch64-apple-tvos-sim`: Apple tvOS Simulator on ARM64. +- `x86_64-apple-tvos`: Apple tvOS Simulator on x86_64. ## Target maintainers -* [@thomcc](https://github.com/thomcc) +- [@thomcc](https://github.com/thomcc) +- [@madsmtm](https://github.com/madsmtm) ## Requirements -These targets are cross-compiled. You will need appropriate versions of Xcode -and the SDKs for tvOS (`AppleTVOS.sdk`) and/or the tvOS Simulator -(`AppleTVSimulator.sdk`) to build a toolchain and target these platforms. +These targets are cross-compiled, and require the corresponding tvOS SDK +(`AppleTVOS.sdk` or `AppleTVSimulator.sdk`), as provided by Xcode. To build the +ARM64 targets, Xcode 12 or higher is required. -The targets support most (see below) of the standard library including the -allocator to the best of my knowledge, however they are very new, not yet -well-tested, and it is possible that there are various bugs. +The path to the SDK can be passed to `rustc` using the common `SDKROOT` +environment variable. -In theory we support back to tvOS version 7.0, although the actual minimum -version you can target may be newer than this, for example due to the versions -of Xcode and your SDKs. +### OS version -As with the other Apple targets, `rustc` respects the common environment -variables used by Xcode to configure this, in this case -`TVOS_DEPLOYMENT_TARGET`. +The minimum supported version is tvOS 10.0, although the actual minimum version +you can target may be newer than this, for example due to the versions of Xcode +and your SDKs. -#### Incompletely supported library functionality +The version can be raised per-binary by changing the deployment target. `rustc` +respects the common environment variables used by Xcode to do so, in this +case `TVOS_DEPLOYMENT_TARGET`. -As mentioned, "most" of the standard library is supported, which means that some portions -are known to be unsupported. The following APIs are currently known to have -missing or incomplete support: +### Incompletely supported library functionality + +The targets support most of the standard library including the allocator to the +best of my knowledge, however they are very new, not yet well-tested, and it is +possible that there are various bugs. + +The following APIs are currently known to have missing or incomplete support: - `std::process::Command`'s API will return an error if it is configured in a manner which cannot be performed using `posix_spawn` -- this is because the @@ -47,41 +51,30 @@ missing or incomplete support: ## Building the target -The targets can be built by enabling them for a `rustc` build in `config.toml`, by adding, for example: +The targets can be built by enabling them for a `rustc` build in +`config.toml`, by adding, for example: ```toml [build] build-stage = 1 -target = ["aarch64-apple-tvos", "x86_64-apple-tvos", "aarch64-apple-tvos-sim"] +target = ["aarch64-apple-tvos", "aarch64-apple-tvos-sim"] ``` -It's possible that cargo under `-Zbuild-std` may also be used to target them. +Using the unstable `-Zbuild-std` with a nightly Cargo may also work. ## Building Rust programs -*Note: Building for this target requires the corresponding TVOS SDK, as provided by Xcode.* +Rust programs can be built for these targets by specifying `--target`, if +`rustc` has been built with support for them. For example: -Rust programs can be built for these targets - -```text +```console $ rustc --target aarch64-apple-tvos your-code.rs -... -$ rustc --target x86_64-apple-tvos your-code.rs -... -$ rustc --target aarch64-apple-tvos-sim your-code.rs ``` ## Testing -There is no support for running the Rust or standard library testsuite on tvOS -or the simulators at the moment. Testing has mostly been done manually with -builds of static libraries called from Xcode or a simulator. +There is no support for running the Rust or standard library testsuite at the +moment. Testing has mostly been done manually with builds of static libraries +embedded into applications called from Xcode or a simulator. It hopefully will be possible to improve this in the future. - -## Cross-compilation toolchains and C code - -This target can be cross-compiled from x86_64 or aarch64 macOS hosts. - -Other hosts are not supported for cross-compilation, but might work when also -providing the required Xcode SDK. diff --git a/src/doc/rustc/src/platform-support/apple-visionos.md b/src/doc/rustc/src/platform-support/apple-visionos.md index 9874126e42f..56224d7e20d 100644 --- a/src/doc/rustc/src/platform-support/apple-visionos.md +++ b/src/doc/rustc/src/platform-support/apple-visionos.md @@ -1,53 +1,67 @@ -# aarch64-apple-visionos\* +# `*-apple-visionos` -- aarch64-apple-visionos -- aarch64-apple-visionos-sim +Apple visionOS / xrOS targets. **Tier: 3** -Apple visionOS targets: - -- Apple visionOS on arm64 -- Apple visionOS Simulator on arm64 +- `aarch64-apple-visionos`: Apple visionOS on arm64. +- `aarch64-apple-visionos-sim`: Apple visionOS Simulator on arm64. ## Target maintainers -- [@agg23](https://github.com/agg23) -- [@madsmtm](https://github.com/madsmtm) +- [@agg23](https://github.com/agg23) +- [@madsmtm](https://github.com/madsmtm) ## Requirements -These targets are cross-compiled. -To build these targets Xcode 15 or higher on macOS is required, along with LLVM 18. +These targets are cross-compiled, and require the corresponding visionOS SDK +(`XROS.sdk` or `XRSimulator.sdk`), as provided by Xcode 15 or newer. + +The path to the SDK can be passed to `rustc` using the common `SDKROOT` +environment variable. + +### OS version + +The minimum supported version is visionOS 1.0. + +This can be raised per-binary by changing the deployment target. `rustc` +respects the common environment variables used by Xcode to do so, in this +case `XROS_DEPLOYMENT_TARGET`. ## Building the target -The targets can be built by enabling them for a `rustc` build, for example: +The targets can be built by enabling them for a `rustc` build in +`config.toml`, by adding, for example: ```toml [build] -build-stage = 1 -target = ["aarch64-apple-visionos-sim"] +target = ["aarch64-apple-visionos", "aarch64-apple-visionos-sim"] ``` +Using the unstable `-Zbuild-std` with a nightly Cargo may also work. + +Note: Currently, a newer version of `libc` and `cc` may be required, this will +be fixed in [#124560](https://github.com/rust-lang/rust/pull/124560). + ## Building Rust programs -_Note: Building for this target requires the corresponding visionOS SDK, as provided by Xcode 15+._ +Rust programs can be built for these targets by specifying `--target`, if +`rustc` has been built with support for them. For example: -Rust programs can be built for these targets, if `rustc` has been built with support for them, for example: - -```text -rustc --target aarch64-apple-visionos-sim your-code.rs +```console +$ rustc --target aarch64-apple-visionos-sim your-code.rs ``` ## Testing -There is no support for running the Rust testsuite on visionOS or the simulators. +There is no support for running the Rust or standard library testsuite at the +moment. Testing has mostly been done manually with builds of static libraries +embedded into applications called from Xcode or a simulator. -There is no easy way to run simple programs on visionOS or the visionOS simulators. Static library builds can be embedded into visionOS applications. +It hopefully will be possible to improve this in the future. ## Cross-compilation toolchains and C code -This target can be cross-compiled from x86_64 or aarch64 macOS hosts. +The Clang target is suffixed with `-xros` for historical reasons. -Other hosts are not supported for cross-compilation, but might work when also providing the required Xcode SDK. +LLVM 18 or newer is required to build this target. diff --git a/src/doc/rustc/src/platform-support/apple-watchos.md b/src/doc/rustc/src/platform-support/apple-watchos.md index 7be2467352c..8ba35f70b85 100644 --- a/src/doc/rustc/src/platform-support/apple-watchos.md +++ b/src/doc/rustc/src/platform-support/apple-watchos.md @@ -1,58 +1,65 @@ -# *-apple-watchos -- arm64_32-apple-watchos -- armv7k-apple-watchos -- aarch64-apple-watchos -- aarch64-apple-watchos-sim -- x86_64-apple-watchos-sim +# `*-apple-watchos` + +Apple watchOS targets. **Tier: 3** -Apple WatchOS targets: -- Apple WatchOS on Arm 64_32 -- Apple WatchOS on Arm v7k -- Apple WatchOS on Arm 64 -- Apple WatchOS Simulator on arm64 -- Apple WatchOS Simulator on x86_64 +- `aarch64-apple-watchos`: Apple WatchOS on ARM64. +- `aarch64-apple-watchos-sim`: Apple WatchOS Simulator on ARM64. +- `x86_64-apple-watchos-sim`: Apple WatchOS Simulator on 64-bit x86. +- `arm64_32-apple-watchos`: Apple WatchOS on Arm 64_32. +- `armv7k-apple-watchos`: Apple WatchOS on Armv7k. ## Target maintainers -* [@deg4uss3r](https://github.com/deg4uss3r) -* [@vladimir-ea](https://github.com/vladimir-ea) -* [@leohowell](https://github.com/leohowell) +- [@deg4uss3r](https://github.com/deg4uss3r) +- [@vladimir-ea](https://github.com/vladimir-ea) +- [@leohowell](https://github.com/leohowell) +- [@madsmtm](https://github.com/madsmtm) ## Requirements -These targets are cross-compiled. -To build these targets Xcode 12 or higher on macOS is required. +These targets are cross-compiled, and require the corresponding watchOS SDK +(`WatchOS.sdk` or `WatchSimulator.sdk`), as provided by Xcode. To build the +ARM64 targets, Xcode 12 or higher is required. + +The path to the SDK can be passed to `rustc` using the common `SDKROOT` +environment variable. + +### OS version + +The minimum supported version is watchOS 5.0. + +This can be raised per-binary by changing the deployment target. `rustc` +respects the common environment variables used by Xcode to do so, in this +case `WATCHOS_DEPLOYMENT_TARGET`. ## Building the target -The targets can be built by enabling them for a `rustc` build, for example: +The targets can be built by enabling them for a `rustc` build in +`config.toml`, by adding, for example: ```toml [build] build-stage = 1 -target = ["aarch64-apple-watchos-sim"] +target = ["aarch64-apple-watchos", "aarch64-apple-watchos-sim"] ``` +Using the unstable `-Zbuild-std` with a nightly Cargo may also work. + ## Building Rust programs -*Note: Building for this target requires the corresponding WatchOS SDK, as provided by Xcode 12+.* +Rust programs can be built for these targets by specifying `--target`, if +`rustc` has been built with support for them. For example: -Rust programs can be built for these targets, if `rustc` has been built with support for them, for example: - -```text -rustc --target aarch64-apple-watchos-sim your-code.rs +```console +$ rustc --target aarch64-apple-watchos-sim your-code.rs ``` ## Testing -There is no support for running the Rust testsuite on WatchOS or the simulators. +There is no support for running the Rust or standard library testsuite at the +moment. Testing has mostly been done manually with builds of static libraries +embedded into applications called from Xcode or a simulator. -There is no easy way to run simple programs on WatchOS or the WatchOS simulators. Static library builds can be embedded into WatchOS applications. - -## Cross-compilation toolchains and C code - -This target can be cross-compiled from x86_64 or aarch64 macOS hosts. - -Other hosts are not supported for cross-compilation, but might work when also providing the required Xcode SDK. +It hopefully will be possible to improve this in the future. diff --git a/src/doc/rustc/src/platform-support/arm64e-apple-darwin.md b/src/doc/rustc/src/platform-support/arm64e-apple-darwin.md index d9b9aeae1ae..4d98b3a6098 100644 --- a/src/doc/rustc/src/platform-support/arm64e-apple-darwin.md +++ b/src/doc/rustc/src/platform-support/arm64e-apple-darwin.md @@ -12,6 +12,8 @@ ARM64e macOS (11.0+, Big Sur+) Target for `macOS` on late-generation `M` series Apple chips. +See the docs on [`*-apple-darwin`](apple-darwin.md) for general macOS requirements. + ## Building the target You can build Rust with support for the targets by adding it to the `target` list in `config.toml`: diff --git a/src/doc/rustc/src/platform-support/arm64e-apple-ios.md b/src/doc/rustc/src/platform-support/arm64e-apple-ios.md index 0215621be3d..3c878f7250e 100644 --- a/src/doc/rustc/src/platform-support/arm64e-apple-ios.md +++ b/src/doc/rustc/src/platform-support/arm64e-apple-ios.md @@ -10,8 +10,7 @@ ARM64e iOS (12.0+) ## Requirements -These targets only support cross-compilation. -The targets do support `std`. +See the docs on [`*-apple-ios`](apple-ios.md) for general iOS requirements. ## Building the target diff --git a/src/doc/rustc/src/platform-support/i686-apple-darwin.md b/src/doc/rustc/src/platform-support/i686-apple-darwin.md new file mode 100644 index 00000000000..d69fa97ce63 --- /dev/null +++ b/src/doc/rustc/src/platform-support/i686-apple-darwin.md @@ -0,0 +1,41 @@ +# `i686-apple-darwin` + +Apple macOS on 32-bit x86. + +## Target maintainers + +- [@thomcc](https://github.com/thomcc) +- [@madsmtm](https://github.com/madsmtm) + +## Requirements + +See the docs on [`*-apple-darwin`](apple-darwin.md) for general macOS requirements. + +## Building the target + +You'll need the macOS 10.13 SDK shipped with Xcode 9. The location of the SDK +can be passed to `rustc` using the common `SDKROOT` environment variable. + +Once you have that, you can build Rust with support for the target by adding +it to the `target` list in `config.toml`: + +```toml +[build] +target = ["i686-apple-darwin"] +``` + +Using the unstable `-Zbuild-std` with a nightly Cargo may also work. + +## Building Rust programs + +Rust [no longer] ships pre-compiled artifacts for this target. To compile for +this target, you will either need to build Rust with the target enabled (see +"Building the target" above), or build your own copy using `build-std` or +similar. + +[no longer]: https://blog.rust-lang.org/2020/01/03/reducing-support-for-32-bit-apple-targets.html + +## Testing + +Running this target requires an Intel Macbook running macOS 10.14 or earlier, +as later versions removed support for running 32-bit binaries. diff --git a/src/doc/rustc/src/platform-support/x86_64h-apple-darwin.md b/src/doc/rustc/src/platform-support/x86_64h-apple-darwin.md index 0fe9d4edaca..6c2a6a41101 100644 --- a/src/doc/rustc/src/platform-support/x86_64h-apple-darwin.md +++ b/src/doc/rustc/src/platform-support/x86_64h-apple-darwin.md @@ -23,9 +23,8 @@ default or user-defined allocators). This target is probably most useful when targeted via cross-compilation (including from `x86_64-apple-darwin`), but if built manually, the host tools work. -It is similar to `x86_64-apple-darwin` in nearly all respects, although the -minimum supported OS version is slightly higher (it requires 10.8 rather than -`x86_64-apple-darwin`'s 10.7). +It is similar to [`x86_64-apple-darwin`](apple-darwin.md) in nearly all +respects. ## Building the target From 1d1981b7b05f7883d23b4edcdc73868333bd318a Mon Sep 17 00:00:00 2001 From: Dion Dokter Date: Sat, 11 May 2024 14:07:19 +0200 Subject: [PATCH 02/29] Add opt-for-size core lib feature flag --- library/core/Cargo.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/library/core/Cargo.toml b/library/core/Cargo.toml index a02fcf50416..11d33971f25 100644 --- a/library/core/Cargo.toml +++ b/library/core/Cargo.toml @@ -31,6 +31,8 @@ rand_xorshift = { version = "0.3.0", default-features = false } [features] # Make panics and failed asserts immediately abort without formatting any message panic_immediate_abort = [] +# Choose algorithms that are optimized for binary size instead of runtime performance +optimize_for_size = [] # Make `RefCell` store additional debugging information, which is printed out when # a borrow error occurs debug_refcell = [] From 579266a6be892d2b2e7410fe992308a9a8896193 Mon Sep 17 00:00:00 2001 From: Dion Dokter Date: Sat, 11 May 2024 14:20:03 +0200 Subject: [PATCH 03/29] Add flag to std and alloc too --- library/alloc/Cargo.toml | 2 ++ library/std/Cargo.toml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/library/alloc/Cargo.toml b/library/alloc/Cargo.toml index e8afed6b35a..4548a27b420 100644 --- a/library/alloc/Cargo.toml +++ b/library/alloc/Cargo.toml @@ -38,3 +38,5 @@ compiler-builtins-mangled-names = ["compiler_builtins/mangled-names"] compiler-builtins-weak-intrinsics = ["compiler_builtins/weak-intrinsics"] # Make panics and failed asserts immediately abort without formatting any message panic_immediate_abort = [] +# Choose algorithms that are optimized for binary size instead of runtime performance +optimize_for_size = [] diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml index 52729ba1f84..81fd26692a5 100644 --- a/library/std/Cargo.toml +++ b/library/std/Cargo.toml @@ -81,6 +81,8 @@ system-llvm-libunwind = ["unwind/system-llvm-libunwind"] # Make panics and failed asserts immediately abort without formatting any message panic_immediate_abort = ["core/panic_immediate_abort", "alloc/panic_immediate_abort"] +# Choose algorithms that are optimized for binary size instead of runtime performance +optimize_for_size = ["core/optimize_for_size", "alloc/optimize_for_size"] # Enable std_detect default features for stdarch/crates/std_detect: # https://github.com/rust-lang/stdarch/blob/master/crates/std_detect/Cargo.toml From 9ab0af820dddae34405252869597d3d853896ed0 Mon Sep 17 00:00:00 2001 From: Dion Dokter Date: Sat, 11 May 2024 14:31:55 +0200 Subject: [PATCH 04/29] Add flag to sysroot --- library/sysroot/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/library/sysroot/Cargo.toml b/library/sysroot/Cargo.toml index 6ff24a8db59..1ddacd92e6b 100644 --- a/library/sysroot/Cargo.toml +++ b/library/sysroot/Cargo.toml @@ -22,6 +22,7 @@ llvm-libunwind = ["std/llvm-libunwind"] system-llvm-libunwind = ["std/system-llvm-libunwind"] panic-unwind = ["std/panic_unwind"] panic_immediate_abort = ["std/panic_immediate_abort"] +optimize_for_size = ["std/optimize_for_size"] profiler = ["std/profiler"] std_detect_file_io = ["std/std_detect_file_io"] std_detect_dlsym_getauxval = ["std/std_detect_dlsym_getauxval"] From b8b68983f392ece653ef1173a7f4d7cbdfe0a9ac Mon Sep 17 00:00:00 2001 From: Dion Dokter Date: Mon, 13 May 2024 22:20:32 +0200 Subject: [PATCH 05/29] Forward alloc features to core --- library/alloc/Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/alloc/Cargo.toml b/library/alloc/Cargo.toml index 4548a27b420..2e7fcb9dbd3 100644 --- a/library/alloc/Cargo.toml +++ b/library/alloc/Cargo.toml @@ -37,6 +37,6 @@ compiler-builtins-no-asm = ["compiler_builtins/no-asm"] compiler-builtins-mangled-names = ["compiler_builtins/mangled-names"] compiler-builtins-weak-intrinsics = ["compiler_builtins/weak-intrinsics"] # Make panics and failed asserts immediately abort without formatting any message -panic_immediate_abort = [] +panic_immediate_abort = ["core/panic_immediate_abort"] # Choose algorithms that are optimized for binary size instead of runtime performance -optimize_for_size = [] +optimize_for_size = ["core/optimize_for_size"] From b964b0066833bc4deb8ebc3bae218a5298da82a9 Mon Sep 17 00:00:00 2001 From: Dion Dokter Date: Fri, 17 May 2024 11:47:18 +0200 Subject: [PATCH 06/29] Run tests with the flag enabled --- src/ci/docker/scripts/x86_64-gnu-llvm.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/ci/docker/scripts/x86_64-gnu-llvm.sh b/src/ci/docker/scripts/x86_64-gnu-llvm.sh index 2eb751ca376..1f4ba498673 100755 --- a/src/ci/docker/scripts/x86_64-gnu-llvm.sh +++ b/src/ci/docker/scripts/x86_64-gnu-llvm.sh @@ -6,10 +6,15 @@ set -ex if [[ -z "${PR_CI_JOB}" ]]; then # When running gcc backend tests, we need to install `libgccjit` and to not run llvm codegen # tests as it will fail them. + # The tests are run a second time with the size optimizations enabled. if [[ "${ENABLE_GCC_CODEGEN}" == "1" ]]; then ../x.py --stage 1 test --skip src/tools/tidy --skip tests/codegen + ../x.py --stage 1 test --skip src/tools/tidy --skip tests/codegen \ + --rustc-args "--cfg feature=\"optimize_for_size\"" else ../x.py --stage 1 test --skip src/tools/tidy + ../x.py --stage 1 test --skip src/tools/tidy --rustc-args \ + "--cfg feature=\"optimize_for_size\"" fi # Run the `mir-opt` tests again but this time for a 32-bit target. From 5c301429bd5fe54351f2c88a6c9b4114abcb1880 Mon Sep 17 00:00:00 2001 From: Dion Dokter Date: Fri, 17 May 2024 12:02:21 +0200 Subject: [PATCH 07/29] Only test std, alloc and core --- src/ci/docker/scripts/x86_64-gnu-llvm.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ci/docker/scripts/x86_64-gnu-llvm.sh b/src/ci/docker/scripts/x86_64-gnu-llvm.sh index 1f4ba498673..fe545e1d5f7 100755 --- a/src/ci/docker/scripts/x86_64-gnu-llvm.sh +++ b/src/ci/docker/scripts/x86_64-gnu-llvm.sh @@ -9,12 +9,12 @@ if [[ -z "${PR_CI_JOB}" ]]; then # The tests are run a second time with the size optimizations enabled. if [[ "${ENABLE_GCC_CODEGEN}" == "1" ]]; then ../x.py --stage 1 test --skip src/tools/tidy --skip tests/codegen - ../x.py --stage 1 test --skip src/tools/tidy --skip tests/codegen \ + ../x.py --stage 1 test library/std library/alloc library/core \ --rustc-args "--cfg feature=\"optimize_for_size\"" else ../x.py --stage 1 test --skip src/tools/tidy - ../x.py --stage 1 test --skip src/tools/tidy --rustc-args \ - "--cfg feature=\"optimize_for_size\"" + ../x.py --stage 1 test library/std library/alloc library/core \ + --rustc-args "--cfg feature=\"optimize_for_size\"" fi # Run the `mir-opt` tests again but this time for a 32-bit target. From f0b8da4430971ce1a34848852849b8b4e3f20778 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Fri, 17 May 2024 13:29:43 -0400 Subject: [PATCH 08/29] rewrite no-intermediate-extras --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - .../run-make/no-intermediate-extras/Makefile | 8 ------- .../run-make/no-intermediate-extras/rmake.rs | 21 +++++++++++++++++++ 3 files changed, 21 insertions(+), 9 deletions(-) delete mode 100644 tests/run-make/no-intermediate-extras/Makefile create mode 100644 tests/run-make/no-intermediate-extras/rmake.rs diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 1a3d6f8d813..4f0397357ae 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -179,7 +179,6 @@ run-make/no-alloc-shim/Makefile run-make/no-builtins-attribute/Makefile run-make/no-builtins-lto/Makefile run-make/no-duplicate-libs/Makefile -run-make/no-intermediate-extras/Makefile run-make/obey-crate-type-flag/Makefile run-make/optimization-remarks-dir-pgo/Makefile run-make/optimization-remarks-dir/Makefile diff --git a/tests/run-make/no-intermediate-extras/Makefile b/tests/run-make/no-intermediate-extras/Makefile deleted file mode 100644 index 83b5cedcf2a..00000000000 --- a/tests/run-make/no-intermediate-extras/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -# ignore-cross-compile -# Regression test for issue #10973 - -include ../tools.mk - -all: - $(RUSTC) --crate-type=rlib --test foo.rs - rm $(TMPDIR)/foo.bc && exit 1 || exit 0 diff --git a/tests/run-make/no-intermediate-extras/rmake.rs b/tests/run-make/no-intermediate-extras/rmake.rs new file mode 100644 index 00000000000..4ca95a1538d --- /dev/null +++ b/tests/run-make/no-intermediate-extras/rmake.rs @@ -0,0 +1,21 @@ +// When using the --test flag with an rlib, this used to generate +// an unwanted .bc file, which should not exist. This test checks +// that the bug causing the generation of this file has not returned. +// See https://github.com/rust-lang/rust/issues/10973 + +//@ ignore-cross-compile + +use run_make_support::{rustc, tmp_dir}; + +fn main() { + rustc().crate_type("rlib").arg("--test").input("foo.rs").run(); + match fs::remove_file(tmp_dir().join("foo.bc")) { + Ok(_) => { + println!("An unwanted .bc file was created by run-make/no-intermediate-extras."); + std::process::exit(0); + }, + Err(e) => { + std::process::exit(1); + } + } +} From abdaed2fa9b0927b1b26183fd7f8ee23ef92e4c9 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Fri, 17 May 2024 14:06:38 -0400 Subject: [PATCH 09/29] tidy fix --- tests/run-make/no-intermediate-extras/rmake.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/run-make/no-intermediate-extras/rmake.rs b/tests/run-make/no-intermediate-extras/rmake.rs index 4ca95a1538d..dffe423296a 100644 --- a/tests/run-make/no-intermediate-extras/rmake.rs +++ b/tests/run-make/no-intermediate-extras/rmake.rs @@ -8,12 +8,12 @@ use run_make_support::{rustc, tmp_dir}; fn main() { - rustc().crate_type("rlib").arg("--test").input("foo.rs").run(); + rustc().crate_type("rlib").arg("--test").input("foo.rs").run(); match fs::remove_file(tmp_dir().join("foo.bc")) { Ok(_) => { println!("An unwanted .bc file was created by run-make/no-intermediate-extras."); std::process::exit(0); - }, + } Err(e) => { std::process::exit(1); } From 9d0b75f75e760e3fd9c31933439b55c38a8fb00d Mon Sep 17 00:00:00 2001 From: Julien <96022417+Oneirical@users.noreply.github.com> Date: Fri, 17 May 2024 14:55:14 -0400 Subject: [PATCH 10/29] missing import --- tests/run-make/no-intermediate-extras/rmake.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/run-make/no-intermediate-extras/rmake.rs b/tests/run-make/no-intermediate-extras/rmake.rs index dffe423296a..615a217cd13 100644 --- a/tests/run-make/no-intermediate-extras/rmake.rs +++ b/tests/run-make/no-intermediate-extras/rmake.rs @@ -6,6 +6,7 @@ //@ ignore-cross-compile use run_make_support::{rustc, tmp_dir}; +use std::fs; fn main() { rustc().crate_type("rlib").arg("--test").input("foo.rs").run(); From 8c43e54ad96b7cf2d6b57d0857325165f8ac5114 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Fri, 17 May 2024 15:42:33 -0400 Subject: [PATCH 11/29] fix: swap the error codes --- tests/run-make/no-intermediate-extras/rmake.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/run-make/no-intermediate-extras/rmake.rs b/tests/run-make/no-intermediate-extras/rmake.rs index 615a217cd13..bc82b18c4cf 100644 --- a/tests/run-make/no-intermediate-extras/rmake.rs +++ b/tests/run-make/no-intermediate-extras/rmake.rs @@ -13,10 +13,10 @@ fn main() { match fs::remove_file(tmp_dir().join("foo.bc")) { Ok(_) => { println!("An unwanted .bc file was created by run-make/no-intermediate-extras."); - std::process::exit(0); + std::process::exit(1); } Err(e) => { - std::process::exit(1); + std::process::exit(0); } } } From 6016bad0636f3597851bf4d8e2b7262932dfb777 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Fri, 17 May 2024 22:11:50 +0200 Subject: [PATCH 12/29] Use `_NSGetEnviron` instead of `environ` on iOS/tvOS/watchOS/visionOS This should be slightly more correct, and matches the implementation in other programming languages: - [Python's `os.environ`](https://github.com/python/cpython/blob/v3.12.3/Modules/posixmodule.c#L1562-L1566). - [Swift's `Darwin.environ`](https://github.com/apple/swift-corelibs-foundation/blob/swift-5.10-RELEASE/CoreFoundation/Base.subproj/CFPlatform.c#L1811-L1812), though that library is bundled on the system, so they can change it if they want. - [Dart/Flutter](https://github.com/dart-lang/sdk/blob/3.4.0/runtime/bin/platform_macos.cc#L205-L234), doesn't support environment variables on iOS. - Node seems to not be entirely consistent with it: - [`process.c`](https://github.com/nodejs/node/blob/v22.1.0/deps/uv/src/unix/process.c#L38). - [`unix/core.c`](https://github.com/nodejs/node/blob/v22.1.0/deps/uv/src/unix/core.c#L59). - [.NET/Xamarin](https://github.com/dotnet/runtime/blob/v8.0.5/src/native/libs/configure.cmake#L1099-L1106). - [OpenJDK](https://github.com/openjdk/jdk/blob/jdk-23%2B22/src/java.base/unix/native/libjava/ProcessEnvironment_md.c#L31-L33). --- library/std/src/sys/pal/unix/os.rs | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/library/std/src/sys/pal/unix/os.rs b/library/std/src/sys/pal/unix/os.rs index 3a281525f8d..8afc49f5227 100644 --- a/library/std/src/sys/pal/unix/os.rs +++ b/library/std/src/sys/pal/unix/os.rs @@ -576,12 +576,36 @@ impl Iterator for Env { } } -#[cfg(target_os = "macos")] +// Use `_NSGetEnviron` on Apple platforms. +// +// `_NSGetEnviron` is the documented alternative (see `man environ`), and has +// been available since the first versions of both macOS and iOS. +// +// Nowadays, specifically since macOS 10.8, `environ` has been exposed through +// `libdyld.dylib`, which is linked via. `libSystem.dylib`: +// +// +// So in the end, it likely doesn't really matter which option we use, but the +// performance cost of using `_NSGetEnviron` is extremely miniscule, and it +// might be ever so slightly more supported, so let's just use that. +// +// NOTE: The header where this is defined (`crt_externs.h`) was added to the +// iOS 13.0 SDK, which has been the source of a great deal of confusion in the +// past about the availability of this API. +// +// NOTE(madsmtm): Neither this nor using `environ` has been verified to not +// cause App Store rejections; if this is found to be the case, an alternative +// implementation of this is possible using `[NSProcessInfo environment]` +// - which internally uses `_NSGetEnviron` and a system-wide lock on the +// environment variables to protect against `setenv`, so using that might be +// desirable anyhow? Though it also means that we have to link to Foundation. +#[cfg(target_vendor = "apple")] pub unsafe fn environ() -> *mut *const *const c_char { libc::_NSGetEnviron() as *mut *const *const c_char } -#[cfg(not(target_os = "macos"))] +// Use the `environ` static which is part of POSIX. +#[cfg(not(target_vendor = "apple"))] pub unsafe fn environ() -> *mut *const *const c_char { extern "C" { static mut environ: *const *const c_char; From 8f18e4fe4bd8cce290c42b662e8db6897b47582d Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Fri, 17 May 2024 22:01:54 +0200 Subject: [PATCH 13/29] Use `_NSGetArgc`/`_NSGetArgv` on iOS/tvOS/watchOS/visionOS If we're comfortable using `_NSGetEnviron` from `crt_externs.h`, there shouldn't be an issue with using these either, and then we can merge with the macOS implementation. This also fixes two test cases on Mac Catalyst: - `tests/ui/command/command-argv0.rs`, maybe because `[[NSProcessInfo processInfo] arguments]` somehow converts the name of the first argument? - `tests/ui/env-funky-keys.rs` since we no longer link to Foundation. --- library/std/src/sys/pal/unix/args.rs | 92 +++++----------------------- library/std/src/sys/pal/unix/mod.rs | 11 ++-- 2 files changed, 19 insertions(+), 84 deletions(-) diff --git a/library/std/src/sys/pal/unix/args.rs b/library/std/src/sys/pal/unix/args.rs index 2a3298e8b4c..66ee45be1a9 100644 --- a/library/std/src/sys/pal/unix/args.rs +++ b/library/std/src/sys/pal/unix/args.rs @@ -168,16 +168,28 @@ mod imp { } } +// Use `_NSGetArgc` and `_NSGetArgv` on Apple platforms. +// +// Even though these have underscores in their names, they've been available +// since since the first versions of both macOS and iOS, and are declared in +// the header `crt_externs.h`. +// +// NOTE: This header was added to the iOS 13.0 SDK, which has been the source +// of a great deal of confusion in the past about the availability of these +// APIs. +// +// NOTE(madsmtm): This has not strictly been verified to not cause App Store +// rejections; if this is found to be the case, the previous implementation +// of this used `[[NSProcessInfo processInfo] arguments]`. #[cfg(target_vendor = "apple")] mod imp { use super::Args; use crate::ffi::CStr; + use crate::os::unix::prelude::*; pub unsafe fn init(_argc: isize, _argv: *const *const u8) {} - #[cfg(target_os = "macos")] pub fn args() -> Args { - use crate::os::unix::prelude::*; extern "C" { // These functions are in crt_externs.h. fn _NSGetArgc() -> *mut libc::c_int; @@ -196,82 +208,6 @@ mod imp { }; Args { iter: vec.into_iter() } } - - // As _NSGetArgc and _NSGetArgv aren't mentioned in iOS docs - // and use underscores in their names - they're most probably - // are considered private and therefore should be avoided. - // Here is another way to get arguments using the Objective-C - // runtime. - // - // In general it looks like: - // res = Vec::new() - // let args = [[NSProcessInfo processInfo] arguments] - // for i in (0..[args count]) - // res.push([args objectAtIndex:i]) - // res - #[cfg(not(target_os = "macos"))] - pub fn args() -> Args { - use crate::ffi::{c_char, c_void, OsString}; - use crate::mem; - use crate::str; - - type Sel = *const c_void; - type NsId = *const c_void; - type NSUInteger = usize; - - extern "C" { - fn sel_registerName(name: *const c_char) -> Sel; - fn objc_getClass(class_name: *const c_char) -> NsId; - - // This must be transmuted to an appropriate function pointer type before being called. - fn objc_msgSend(); - } - - const MSG_SEND_PTR: unsafe extern "C" fn() = objc_msgSend; - const MSG_SEND_NO_ARGUMENTS_RETURN_PTR: unsafe extern "C" fn(NsId, Sel) -> *const c_void = - unsafe { mem::transmute(MSG_SEND_PTR) }; - const MSG_SEND_NO_ARGUMENTS_RETURN_NSUINTEGER: unsafe extern "C" fn( - NsId, - Sel, - ) -> NSUInteger = unsafe { mem::transmute(MSG_SEND_PTR) }; - const MSG_SEND_NSINTEGER_ARGUMENT_RETURN_PTR: unsafe extern "C" fn( - NsId, - Sel, - NSUInteger, - ) - -> *const c_void = unsafe { mem::transmute(MSG_SEND_PTR) }; - - let mut res = Vec::new(); - - unsafe { - let process_info_sel = sel_registerName(c"processInfo".as_ptr()); - let arguments_sel = sel_registerName(c"arguments".as_ptr()); - let count_sel = sel_registerName(c"count".as_ptr()); - let object_at_index_sel = sel_registerName(c"objectAtIndex:".as_ptr()); - let utf8string_sel = sel_registerName(c"UTF8String".as_ptr()); - - let klass = objc_getClass(c"NSProcessInfo".as_ptr()); - // `+[NSProcessInfo processInfo]` returns an object with +0 retain count, so no need to manually `retain/release`. - let info = MSG_SEND_NO_ARGUMENTS_RETURN_PTR(klass, process_info_sel); - - // `-[NSProcessInfo arguments]` returns an object with +0 retain count, so no need to manually `retain/release`. - let args = MSG_SEND_NO_ARGUMENTS_RETURN_PTR(info, arguments_sel); - - let cnt = MSG_SEND_NO_ARGUMENTS_RETURN_NSUINTEGER(args, count_sel); - for i in 0..cnt { - // `-[NSArray objectAtIndex:]` returns an object whose lifetime is tied to the array, so no need to manually `retain/release`. - let ns_string = - MSG_SEND_NSINTEGER_ARGUMENT_RETURN_PTR(args, object_at_index_sel, i); - // The lifetime of this pointer is tied to the NSString, as well as the current autorelease pool, which is why we heap-allocate the string below. - let utf_c_str: *const c_char = - MSG_SEND_NO_ARGUMENTS_RETURN_PTR(ns_string, utf8string_sel).cast(); - let bytes = CStr::from_ptr(utf_c_str).to_bytes(); - res.push(OsString::from(str::from_utf8(bytes).unwrap())) - } - } - - Args { iter: res.into_iter() } - } } #[cfg(any(target_os = "espidf", target_os = "vita"))] diff --git a/library/std/src/sys/pal/unix/mod.rs b/library/std/src/sys/pal/unix/mod.rs index 21f233e2262..735ed96bc7b 100644 --- a/library/std/src/sys/pal/unix/mod.rs +++ b/library/std/src/sys/pal/unix/mod.rs @@ -399,14 +399,13 @@ cfg_if::cfg_if! { // Use libumem for the (malloc-compatible) allocator #[link(name = "umem")] extern "C" {} - } else if #[cfg(target_os = "macos")] { + } else if #[cfg(target_vendor = "apple")] { + // Link to `libSystem.dylib`. + // + // Don't get confused by the presence of `System.framework`, + // it is a deprecated wrapper over the dynamic library. #[link(name = "System")] extern "C" {} - } else if #[cfg(all(target_vendor = "apple", not(target_os = "macos")))] { - #[link(name = "System")] - #[link(name = "objc")] - #[link(name = "Foundation", kind = "framework")] - extern "C" {} } else if #[cfg(target_os = "fuchsia")] { #[link(name = "zircon")] #[link(name = "fdio")] From 1914c722b56c347e838765d1df33d74de8a97d72 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Sat, 18 May 2024 17:56:49 -0700 Subject: [PATCH 14/29] compiler: add simd_ctpop intrinsic --- compiler/rustc_codegen_llvm/src/intrinsic.rs | 48 +++++++++++-------- .../rustc_hir_analysis/src/check/intrinsic.rs | 1 + compiler/rustc_span/src/symbol.rs | 1 + library/core/src/intrinsics/simd.rs | 7 +++ .../ui/simd/intrinsic/generic-arithmetic-2.rs | 23 ++++----- .../intrinsic/generic-arithmetic-2.stderr | 26 ++++++---- .../simd/intrinsic/generic-arithmetic-pass.rs | 10 ++++ 7 files changed, 76 insertions(+), 40 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/intrinsic.rs b/compiler/rustc_codegen_llvm/src/intrinsic.rs index c0a1208a8c7..7e6d7491798 100644 --- a/compiler/rustc_codegen_llvm/src/intrinsic.rs +++ b/compiler/rustc_codegen_llvm/src/intrinsic.rs @@ -2336,7 +2336,10 @@ fn generic_simd_intrinsic<'ll, 'tcx>( } // Unary integer intrinsics - if matches!(name, sym::simd_bswap | sym::simd_bitreverse | sym::simd_ctlz | sym::simd_cttz) { + if matches!( + name, + sym::simd_bswap | sym::simd_bitreverse | sym::simd_ctlz | sym::simd_ctpop | sym::simd_cttz + ) { let vec_ty = bx.cx.type_vector( match *in_elem.kind() { ty::Int(i) => bx.cx.type_int_from_ty(i), @@ -2354,31 +2357,38 @@ fn generic_simd_intrinsic<'ll, 'tcx>( sym::simd_bswap => "bswap", sym::simd_bitreverse => "bitreverse", sym::simd_ctlz => "ctlz", + sym::simd_ctpop => "ctpop", sym::simd_cttz => "cttz", _ => unreachable!(), }; let int_size = in_elem.int_size_and_signed(bx.tcx()).0.bits(); let llvm_intrinsic = &format!("llvm.{}.v{}i{}", intrinsic_name, in_len, int_size,); - return if name == sym::simd_bswap && int_size == 8 { + return match name { // byte swap is no-op for i8/u8 - Ok(args[0].immediate()) - } else if matches!(name, sym::simd_ctlz | sym::simd_cttz) { - let fn_ty = bx.type_func(&[vec_ty, bx.type_i1()], vec_ty); - let f = bx.declare_cfn(llvm_intrinsic, llvm::UnnamedAddr::No, fn_ty); - Ok(bx.call( - fn_ty, - None, - None, - f, - &[args[0].immediate(), bx.const_int(bx.type_i1(), 0)], - None, - None, - )) - } else { - let fn_ty = bx.type_func(&[vec_ty], vec_ty); - let f = bx.declare_cfn(llvm_intrinsic, llvm::UnnamedAddr::No, fn_ty); - Ok(bx.call(fn_ty, None, None, f, &[args[0].immediate()], None, None)) + sym::simd_bswap if int_size == 8 => Ok(args[0].immediate()), + sym::simd_ctlz | sym::simd_cttz => { + // this fun bonus i1 arg means "poison if the arg vector contains zero" + let fn_ty = bx.type_func(&[vec_ty, bx.type_i1()], vec_ty); + let f = bx.declare_cfn(llvm_intrinsic, llvm::UnnamedAddr::No, fn_ty); + Ok(bx.call( + fn_ty, + None, + None, + f, + // simd_ctlz and simd_cttz are exposed to safe code, so let's not poison anything + &[args[0].immediate(), bx.const_int(bx.type_i1(), 0)], + None, + None, + )) + } + sym::simd_bswap | sym::simd_bitreverse | sym::simd_ctpop => { + // simple unary argument cases + let fn_ty = bx.type_func(&[vec_ty], vec_ty); + let f = bx.declare_cfn(llvm_intrinsic, llvm::UnnamedAddr::No, fn_ty); + Ok(bx.call(fn_ty, None, None, f, &[args[0].immediate()], None, None)) + } + _ => unreachable!(), }; } diff --git a/compiler/rustc_hir_analysis/src/check/intrinsic.rs b/compiler/rustc_hir_analysis/src/check/intrinsic.rs index d829e720d9e..50fe20346cf 100644 --- a/compiler/rustc_hir_analysis/src/check/intrinsic.rs +++ b/compiler/rustc_hir_analysis/src/check/intrinsic.rs @@ -607,6 +607,7 @@ pub fn check_intrinsic_type( | sym::simd_bitreverse | sym::simd_ctlz | sym::simd_cttz + | sym::simd_ctpop | sym::simd_fsqrt | sym::simd_fsin | sym::simd_fcos diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 68b1b32baf2..203d24185c6 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1681,6 +1681,7 @@ symbols! { simd_cast_ptr, simd_ceil, simd_ctlz, + simd_ctpop, simd_cttz, simd_div, simd_eq, diff --git a/library/core/src/intrinsics/simd.rs b/library/core/src/intrinsics/simd.rs index ceea6790129..d1be534eaf0 100644 --- a/library/core/src/intrinsics/simd.rs +++ b/library/core/src/intrinsics/simd.rs @@ -569,6 +569,13 @@ extern "rust-intrinsic" { #[rustc_nounwind] pub fn simd_ctlz(x: T) -> T; + /// Count the number of ones in each element. + /// + /// `T` must be a vector of integers. + #[rustc_nounwind] + #[cfg(not(bootstrap))] + pub fn simd_ctpop(x: T) -> T; + /// Count the trailing zeros of each element. /// /// `T` must be a vector of integers. diff --git a/tests/ui/simd/intrinsic/generic-arithmetic-2.rs b/tests/ui/simd/intrinsic/generic-arithmetic-2.rs index 4ad98d56711..fc3087cbf75 100644 --- a/tests/ui/simd/intrinsic/generic-arithmetic-2.rs +++ b/tests/ui/simd/intrinsic/generic-arithmetic-2.rs @@ -30,6 +30,7 @@ extern "rust-intrinsic" { fn simd_bswap(x: T) -> T; fn simd_bitreverse(x: T) -> T; fn simd_ctlz(x: T) -> T; + fn simd_ctpop(x: T) -> T; fn simd_cttz(x: T) -> T; } @@ -77,7 +78,6 @@ fn main() { simd_cttz(x); simd_cttz(y); - simd_add(0, 0); //~^ ERROR expected SIMD input type, found non-SIMD `i32` simd_sub(0, 0); @@ -108,24 +108,25 @@ fn main() { simd_cttz(0); //~^ ERROR expected SIMD input type, found non-SIMD `i32` - simd_shl(z, z); -//~^ ERROR unsupported operation on `f32x4` with element `f32` + //~^ ERROR unsupported operation on `f32x4` with element `f32` simd_shr(z, z); -//~^ ERROR unsupported operation on `f32x4` with element `f32` + //~^ ERROR unsupported operation on `f32x4` with element `f32` simd_and(z, z); -//~^ ERROR unsupported operation on `f32x4` with element `f32` + //~^ ERROR unsupported operation on `f32x4` with element `f32` simd_or(z, z); -//~^ ERROR unsupported operation on `f32x4` with element `f32` + //~^ ERROR unsupported operation on `f32x4` with element `f32` simd_xor(z, z); -//~^ ERROR unsupported operation on `f32x4` with element `f32` + //~^ ERROR unsupported operation on `f32x4` with element `f32` simd_bswap(z); -//~^ ERROR unsupported operation on `f32x4` with element `f32` + //~^ ERROR unsupported operation on `f32x4` with element `f32` simd_bitreverse(z); -//~^ ERROR unsupported operation on `f32x4` with element `f32` + //~^ ERROR unsupported operation on `f32x4` with element `f32` simd_ctlz(z); -//~^ ERROR unsupported operation on `f32x4` with element `f32` + //~^ ERROR unsupported operation on `f32x4` with element `f32` + simd_ctpop(z); + //~^ ERROR unsupported operation on `f32x4` with element `f32` simd_cttz(z); -//~^ ERROR unsupported operation on `f32x4` with element `f32` + //~^ ERROR unsupported operation on `f32x4` with element `f32` } } diff --git a/tests/ui/simd/intrinsic/generic-arithmetic-2.stderr b/tests/ui/simd/intrinsic/generic-arithmetic-2.stderr index db26f3417c9..6f5f86d7d37 100644 --- a/tests/ui/simd/intrinsic/generic-arithmetic-2.stderr +++ b/tests/ui/simd/intrinsic/generic-arithmetic-2.stderr @@ -83,59 +83,65 @@ LL | simd_cttz(0); | ^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shl` intrinsic: unsupported operation on `f32x4` with element `f32` - --> $DIR/generic-arithmetic-2.rs:112:9 + --> $DIR/generic-arithmetic-2.rs:111:9 | LL | simd_shl(z, z); | ^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shr` intrinsic: unsupported operation on `f32x4` with element `f32` - --> $DIR/generic-arithmetic-2.rs:114:9 + --> $DIR/generic-arithmetic-2.rs:113:9 | LL | simd_shr(z, z); | ^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_and` intrinsic: unsupported operation on `f32x4` with element `f32` - --> $DIR/generic-arithmetic-2.rs:116:9 + --> $DIR/generic-arithmetic-2.rs:115:9 | LL | simd_and(z, z); | ^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_or` intrinsic: unsupported operation on `f32x4` with element `f32` - --> $DIR/generic-arithmetic-2.rs:118:9 + --> $DIR/generic-arithmetic-2.rs:117:9 | LL | simd_or(z, z); | ^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_xor` intrinsic: unsupported operation on `f32x4` with element `f32` - --> $DIR/generic-arithmetic-2.rs:120:9 + --> $DIR/generic-arithmetic-2.rs:119:9 | LL | simd_xor(z, z); | ^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_bswap` intrinsic: unsupported operation on `f32x4` with element `f32` - --> $DIR/generic-arithmetic-2.rs:122:9 + --> $DIR/generic-arithmetic-2.rs:121:9 | LL | simd_bswap(z); | ^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_bitreverse` intrinsic: unsupported operation on `f32x4` with element `f32` - --> $DIR/generic-arithmetic-2.rs:124:9 + --> $DIR/generic-arithmetic-2.rs:123:9 | LL | simd_bitreverse(z); | ^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_ctlz` intrinsic: unsupported operation on `f32x4` with element `f32` - --> $DIR/generic-arithmetic-2.rs:126:9 + --> $DIR/generic-arithmetic-2.rs:125:9 | LL | simd_ctlz(z); | ^^^^^^^^^^^^ +error[E0511]: invalid monomorphization of `simd_ctpop` intrinsic: unsupported operation on `f32x4` with element `f32` + --> $DIR/generic-arithmetic-2.rs:127:9 + | +LL | simd_ctpop(z); + | ^^^^^^^^^^^^^ + error[E0511]: invalid monomorphization of `simd_cttz` intrinsic: unsupported operation on `f32x4` with element `f32` - --> $DIR/generic-arithmetic-2.rs:128:9 + --> $DIR/generic-arithmetic-2.rs:129:9 | LL | simd_cttz(z); | ^^^^^^^^^^^^ -error: aborting due to 23 previous errors +error: aborting due to 24 previous errors For more information about this error, try `rustc --explain E0511`. diff --git a/tests/ui/simd/intrinsic/generic-arithmetic-pass.rs b/tests/ui/simd/intrinsic/generic-arithmetic-pass.rs index 33143b1f7b5..60dfa627414 100644 --- a/tests/ui/simd/intrinsic/generic-arithmetic-pass.rs +++ b/tests/ui/simd/intrinsic/generic-arithmetic-pass.rs @@ -47,6 +47,7 @@ extern "rust-intrinsic" { fn simd_bswap(x: T) -> T; fn simd_bitreverse(x: T) -> T; fn simd_ctlz(x: T) -> T; + fn simd_ctpop(x: T) -> T; fn simd_cttz(x: T) -> T; } @@ -57,6 +58,8 @@ fn main() { let x2 = i32x4(2, 3, 4, 5); let y2 = U32::<4>([2, 3, 4, 5]); let z2 = f32x4(2.0, 3.0, 4.0, 5.0); + let x3 = i32x4(0, i32::MAX, i32::MIN, -1_i32); + let y3 = U32::<4>([0, i32::MAX as _, i32::MIN as _, -1_i32 as _]); unsafe { all_eq!(simd_add(x1, x2), i32x4(3, 5, 7, 9)); @@ -147,6 +150,13 @@ fn main() { all_eq!(simd_ctlz(x1), i32x4(31, 30, 30, 29)); all_eq_!(simd_ctlz(y1), U32::<4>([31, 30, 30, 29])); + all_eq!(simd_ctpop(x1), i32x4(1, 1, 2, 1)); + all_eq_!(simd_ctpop(y1), U32::<4>([1, 1, 2, 1])); + all_eq!(simd_ctpop(x2), i32x4(1, 2, 1, 2)); + all_eq_!(simd_ctpop(y2), U32::<4>([1, 2, 1, 2])); + all_eq!(simd_ctpop(x3), i32x4(0, 31, 1, 32)); + all_eq_!(simd_ctpop(y3), U32::<4>([0, 31, 1, 32])); + all_eq!(simd_cttz(x1), i32x4(0, 1, 0, 2)); all_eq_!(simd_cttz(y1), U32::<4>([0, 1, 0, 2])); } From abd5d0e37bfe54543aa80c86de30db829dd10ed2 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Sun, 19 May 2024 04:18:51 +0200 Subject: [PATCH 15/29] Add NULL check in argument parsing on Apple platforms --- library/std/src/sys/pal/unix/args.rs | 58 +++++++++++++++++++++------- 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/library/std/src/sys/pal/unix/args.rs b/library/std/src/sys/pal/unix/args.rs index 66ee45be1a9..b7e8534eea8 100644 --- a/library/std/src/sys/pal/unix/args.rs +++ b/library/std/src/sys/pal/unix/args.rs @@ -184,28 +184,58 @@ mod imp { #[cfg(target_vendor = "apple")] mod imp { use super::Args; - use crate::ffi::CStr; + use crate::ffi::{c_char, c_int, CStr}; use crate::os::unix::prelude::*; - pub unsafe fn init(_argc: isize, _argv: *const *const u8) {} + pub unsafe fn init(_argc: isize, _argv: *const *const u8) { + // No need to initialize anything in here, `libdyld.dylib` has already + // done the work for us. + } pub fn args() -> Args { extern "C" { // These functions are in crt_externs.h. - fn _NSGetArgc() -> *mut libc::c_int; - fn _NSGetArgv() -> *mut *mut *mut libc::c_char; + fn _NSGetArgc() -> *mut c_int; + fn _NSGetArgv() -> *mut *mut *mut c_char; + } + + // SAFETY: The returned pointer points to a static initialized early + // in the program lifetime by `libdyld.dylib`, and as such is always + // valid. + // + // NOTE: Similar to `_NSGetEnviron`, there technically isn't anything + // protecting us against concurrent modifications to this, and there + // doesn't exist a lock that we can take. Instead, it is generally + // expected that it's only modified in `main` / before other code + // runs, so reading this here should be fine. + let argc = unsafe { _NSGetArgc().read() }; + // SAFETY: Same as above. + let argv = unsafe { _NSGetArgv().read() }; + + let mut vec = Vec::with_capacity(argc as usize); + + for i in 0..argc { + // SAFETY: `argv` is at least as long as `argc`, so reading from + // it should be safe. + let ptr = unsafe { argv.offset(i as isize).read() }; + + // Entries may have been removed from `argv` by setting them to + // NULL, without updating `argc`. + if ptr.is_null() { + // We continue instead of break here, as an argument may have + // been set to `NULL` in the middle, instead of at the end of + // the list. + // + // This is the same as what `-[NSProcessInfo arguments]` does. + continue; + } + + // SAFETY: Just checked that the pointer is not NULL, and + // arguments are otherwise guaranteed to be valid C strings. + let cstr = unsafe { CStr::from_ptr(ptr) }; + vec.push(OsStringExt::from_vec(cstr.to_bytes().to_vec())); } - let vec = unsafe { - let (argc, argv) = - (*_NSGetArgc() as isize, *_NSGetArgv() as *const *const libc::c_char); - (0..argc as isize) - .map(|i| { - let bytes = CStr::from_ptr(*argv.offset(i)).to_bytes().to_vec(); - OsStringExt::from_vec(bytes) - }) - .collect::>() - }; Args { iter: vec.into_iter() } } } From 1185a6486c1a982a0d39880f2e389bd2cb35f078 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Sun, 19 May 2024 18:48:06 -0700 Subject: [PATCH 16/29] miri: support simd_ctpop --- src/tools/miri/src/intrinsics/simd.rs | 2 ++ .../miri/tests/pass/intrinsics/portable-simd.rs | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/tools/miri/src/intrinsics/simd.rs b/src/tools/miri/src/intrinsics/simd.rs index d0a78429ca8..5c7132e9e60 100644 --- a/src/tools/miri/src/intrinsics/simd.rs +++ b/src/tools/miri/src/intrinsics/simd.rs @@ -42,6 +42,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { | "flog2" | "flog10" | "ctlz" + | "ctpop" | "cttz" | "bswap" | "bitreverse" @@ -68,6 +69,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { "round" => Op::Round(rustc_apfloat::Round::NearestTiesToAway), "trunc" => Op::Round(rustc_apfloat::Round::TowardZero), "ctlz" => Op::Numeric(sym::ctlz), + "ctpop" => Op::Numeric(sym::ctpop), "cttz" => Op::Numeric(sym::cttz), "bswap" => Op::Numeric(sym::bswap), "bitreverse" => Op::Numeric(sym::bitreverse), diff --git a/src/tools/miri/tests/pass/intrinsics/portable-simd.rs b/src/tools/miri/tests/pass/intrinsics/portable-simd.rs index 1fc713d48dc..248a57d6850 100644 --- a/src/tools/miri/tests/pass/intrinsics/portable-simd.rs +++ b/src/tools/miri/tests/pass/intrinsics/portable-simd.rs @@ -505,6 +505,21 @@ fn simd_intrinsics() { assert!(simd_reduce_all(i32x4::splat(-1))); assert!(!simd_reduce_all(i32x2::from_array([0, -1]))); + assert_eq!( + simd_ctlz(i32x4::from_array([0, i32::MAX, i32::MIN, -1_i32])), + i32x4::from_array([32, 1, 0, 0]) + ); + + assert_eq!( + simd_ctpop(i32x4::from_array([0, i32::MAX, i32::MIN, -1_i32])), + i32x4::from_array([0, 31, 1, 32]) + ); + + assert_eq!( + simd_cttz(i32x4::from_array([0, i32::MAX, i32::MIN, -1_i32])), + i32x4::from_array([32, 0, 31, 0]) + ); + assert_eq!( simd_select(i8x4::from_array([0, -1, -1, 0]), a, b), i32x4::from_array([1, 10, 10, 4]) From 9557b903b8dec3873bf93f68b65248e3e4374cfd Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Sun, 19 May 2024 18:50:42 -0700 Subject: [PATCH 17/29] cg_clif: support simd_ctpop --- compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs b/compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs index 452b5988dab..b17f191ce26 100644 --- a/compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs +++ b/compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs @@ -348,6 +348,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( | sym::simd_bswap | sym::simd_bitreverse | sym::simd_ctlz + | sym::simd_ctpop | sym::simd_cttz => { intrinsic_args!(fx, args => (a); intrinsic); @@ -367,6 +368,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( (ty::Uint(_) | ty::Int(_), sym::simd_bswap) => fx.bcx.ins().bswap(lane), (ty::Uint(_) | ty::Int(_), sym::simd_bitreverse) => fx.bcx.ins().bitrev(lane), (ty::Uint(_) | ty::Int(_), sym::simd_ctlz) => fx.bcx.ins().clz(lane), + (ty::Uint(_) | ty::Int(_), sym::simd_ctpop) => fx.bcx.ins().popcnt(lane), (ty::Uint(_) | ty::Int(_), sym::simd_cttz) => fx.bcx.ins().ctz(lane), _ => unreachable!(), From 213351ae9e7d6745a70457925546cd032d4f0c51 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Sun, 19 May 2024 19:04:03 -0700 Subject: [PATCH 18/29] clarify the second arg to llvm.ctlz and cttz --- compiler/rustc_codegen_llvm/src/intrinsic.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/intrinsic.rs b/compiler/rustc_codegen_llvm/src/intrinsic.rs index 7e6d7491798..80e863af893 100644 --- a/compiler/rustc_codegen_llvm/src/intrinsic.rs +++ b/compiler/rustc_codegen_llvm/src/intrinsic.rs @@ -2368,16 +2368,16 @@ fn generic_simd_intrinsic<'ll, 'tcx>( // byte swap is no-op for i8/u8 sym::simd_bswap if int_size == 8 => Ok(args[0].immediate()), sym::simd_ctlz | sym::simd_cttz => { - // this fun bonus i1 arg means "poison if the arg vector contains zero" + // for the (int, i1 immediate) pair, the second arg adds `(0, true) => poison` let fn_ty = bx.type_func(&[vec_ty, bx.type_i1()], vec_ty); + let dont_poison_on_zero = bx.const_int(bx.type_i1(), 0); let f = bx.declare_cfn(llvm_intrinsic, llvm::UnnamedAddr::No, fn_ty); Ok(bx.call( fn_ty, None, None, f, - // simd_ctlz and simd_cttz are exposed to safe code, so let's not poison anything - &[args[0].immediate(), bx.const_int(bx.type_i1(), 0)], + &[args[0].immediate(), dont_poison_on_zero], None, None, )) From 38ad85160314b446a08705974d3b03cc29c338c9 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Mon, 20 May 2024 04:54:27 +0200 Subject: [PATCH 19/29] Make NULL check in argument parsing the same on all unix platforms --- library/std/src/sys/pal/unix/args.rs | 138 ++++++++++++--------------- 1 file changed, 63 insertions(+), 75 deletions(-) diff --git a/library/std/src/sys/pal/unix/args.rs b/library/std/src/sys/pal/unix/args.rs index b7e8534eea8..db2ec73148e 100644 --- a/library/std/src/sys/pal/unix/args.rs +++ b/library/std/src/sys/pal/unix/args.rs @@ -5,8 +5,9 @@ #![allow(dead_code)] // runtime init functions not used during testing -use crate::ffi::OsString; +use crate::ffi::{CStr, OsString}; use crate::fmt; +use crate::os::unix::ffi::OsStringExt; use crate::vec; /// One-time global initialization. @@ -16,7 +17,46 @@ pub unsafe fn init(argc: isize, argv: *const *const u8) { /// Returns the command line arguments pub fn args() -> Args { - imp::args() + let (argc, argv) = imp::argc_argv(); + + let mut vec = Vec::with_capacity(argc as usize); + + for i in 0..argc { + // SAFETY: `argv` is non-null if `argc` is positive, and it is + // guaranteed to be at least as long as `argc`, so reading from it + // should be safe. + let ptr = unsafe { argv.offset(i).read() }; + + // Some C commandline parsers (e.g. GLib and Qt) are replacing already + // handled arguments in `argv` with `NULL` and move them to the end. + // + // Since they can't directly ensure updates to `argc` as well, this + // means that `argc` might be bigger than the actual number of + // non-`NULL` pointers in `argv` at this point. + // + // To handle this we simply stop iterating at the first `NULL` + // argument. `argv` is also guaranteed to be `NULL`-terminated so any + // non-`NULL` arguments after the first `NULL` can safely be ignored. + if ptr.is_null() { + // NOTE: On Apple platforms, `-[NSProcessInfo arguments]` does not + // stop iterating here, but instead `continue`, always iterating + // up until it reached `argc`. + // + // This difference will only matter in very specific circumstances + // where `argc`/`argv` have been modified, but in unexpected ways, + // so it likely doesn't really matter which option we choose. + // See the following PR for further discussion: + // + break; + } + + // SAFETY: Just checked that the pointer is not NULL, and arguments + // are otherwise guaranteed to be valid C strings. + let cstr = unsafe { CStr::from_ptr(ptr) }; + vec.push(OsStringExt::from_vec(cstr.to_bytes().to_vec())); + } + + Args { iter: vec.into_iter() } } pub struct Args { @@ -75,9 +115,7 @@ impl DoubleEndedIterator for Args { target_os = "hurd", ))] mod imp { - use super::Args; - use crate::ffi::{CStr, OsString}; - use crate::os::unix::prelude::*; + use crate::ffi::c_char; use crate::ptr; use crate::sync::atomic::{AtomicIsize, AtomicPtr, Ordering}; @@ -126,45 +164,19 @@ mod imp { init_wrapper }; - pub fn args() -> Args { - Args { iter: clone().into_iter() } - } + pub fn argc_argv() -> (isize, *const *const c_char) { + // Load ARGC and ARGV, which hold the unmodified system-provided + // argc/argv, so we can read the pointed-to memory without atomics or + // synchronization. + // + // If either ARGC or ARGV is still zero or null, then either there + // really are no arguments, or someone is asking for `args()` before + // initialization has completed, and we return an empty list. + let argv = ARGV.load(Ordering::Relaxed); + let argc = if argv.is_null() { 0 } else { ARGC.load(Ordering::Relaxed) }; - fn clone() -> Vec { - unsafe { - // Load ARGC and ARGV, which hold the unmodified system-provided - // argc/argv, so we can read the pointed-to memory without atomics - // or synchronization. - // - // If either ARGC or ARGV is still zero or null, then either there - // really are no arguments, or someone is asking for `args()` - // before initialization has completed, and we return an empty - // list. - let argv = ARGV.load(Ordering::Relaxed); - let argc = if argv.is_null() { 0 } else { ARGC.load(Ordering::Relaxed) }; - let mut args = Vec::with_capacity(argc as usize); - for i in 0..argc { - let ptr = *argv.offset(i) as *const libc::c_char; - - // Some C commandline parsers (e.g. GLib and Qt) are replacing already - // handled arguments in `argv` with `NULL` and move them to the end. That - // means that `argc` might be bigger than the actual number of non-`NULL` - // pointers in `argv` at this point. - // - // To handle this we simply stop iterating at the first `NULL` argument. - // - // `argv` is also guaranteed to be `NULL`-terminated so any non-`NULL` arguments - // after the first `NULL` can safely be ignored. - if ptr.is_null() { - break; - } - - let cstr = CStr::from_ptr(ptr); - args.push(OsStringExt::from_vec(cstr.to_bytes().to_vec())); - } - - args - } + // Cast from `*mut *const u8` to `*const *const c_char` + (argc, argv.cast()) } } @@ -183,16 +195,14 @@ mod imp { // of this used `[[NSProcessInfo processInfo] arguments]`. #[cfg(target_vendor = "apple")] mod imp { - use super::Args; - use crate::ffi::{c_char, c_int, CStr}; - use crate::os::unix::prelude::*; + use crate::ffi::{c_char, c_int}; pub unsafe fn init(_argc: isize, _argv: *const *const u8) { // No need to initialize anything in here, `libdyld.dylib` has already // done the work for us. } - pub fn args() -> Args { + pub fn argc_argv() -> (isize, *const *const c_char) { extern "C" { // These functions are in crt_externs.h. fn _NSGetArgc() -> *mut c_int; @@ -212,42 +222,20 @@ mod imp { // SAFETY: Same as above. let argv = unsafe { _NSGetArgv().read() }; - let mut vec = Vec::with_capacity(argc as usize); - - for i in 0..argc { - // SAFETY: `argv` is at least as long as `argc`, so reading from - // it should be safe. - let ptr = unsafe { argv.offset(i as isize).read() }; - - // Entries may have been removed from `argv` by setting them to - // NULL, without updating `argc`. - if ptr.is_null() { - // We continue instead of break here, as an argument may have - // been set to `NULL` in the middle, instead of at the end of - // the list. - // - // This is the same as what `-[NSProcessInfo arguments]` does. - continue; - } - - // SAFETY: Just checked that the pointer is not NULL, and - // arguments are otherwise guaranteed to be valid C strings. - let cstr = unsafe { CStr::from_ptr(ptr) }; - vec.push(OsStringExt::from_vec(cstr.to_bytes().to_vec())); - } - - Args { iter: vec.into_iter() } + // Cast from `*mut *mut c_char` to `*const *const c_char` + (argc as isize, argv.cast()) } } #[cfg(any(target_os = "espidf", target_os = "vita"))] mod imp { - use super::Args; + use crate::ffi::c_char; + use crate::ptr; #[inline(always)] pub unsafe fn init(_argc: isize, _argv: *const *const u8) {} - pub fn args() -> Args { - Args { iter: Vec::new().into_iter() } + pub fn argc_argv() -> (isize, *const *const c_char) { + (0, ptr::null()) } } From 0d23a71ec2c79bc2da6b3fa8fa6386817e5856c5 Mon Sep 17 00:00:00 2001 From: Dion Dokter Date: Mon, 20 May 2024 12:18:24 +0200 Subject: [PATCH 20/29] Deduplicate test command --- src/ci/docker/scripts/x86_64-gnu-llvm.sh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/ci/docker/scripts/x86_64-gnu-llvm.sh b/src/ci/docker/scripts/x86_64-gnu-llvm.sh index fe545e1d5f7..8f5f7fdbe47 100755 --- a/src/ci/docker/scripts/x86_64-gnu-llvm.sh +++ b/src/ci/docker/scripts/x86_64-gnu-llvm.sh @@ -6,17 +6,16 @@ set -ex if [[ -z "${PR_CI_JOB}" ]]; then # When running gcc backend tests, we need to install `libgccjit` and to not run llvm codegen # tests as it will fail them. - # The tests are run a second time with the size optimizations enabled. if [[ "${ENABLE_GCC_CODEGEN}" == "1" ]]; then ../x.py --stage 1 test --skip src/tools/tidy --skip tests/codegen - ../x.py --stage 1 test library/std library/alloc library/core \ - --rustc-args "--cfg feature=\"optimize_for_size\"" else ../x.py --stage 1 test --skip src/tools/tidy - ../x.py --stage 1 test library/std library/alloc library/core \ - --rustc-args "--cfg feature=\"optimize_for_size\"" fi + # The tests are run a second time with the size optimizations enabled. + ../x.py --stage 1 test library/std library/alloc library/core \ + --rustc-args "--cfg feature=\"optimize_for_size\"" + # Run the `mir-opt` tests again but this time for a 32-bit target. # This enforces that tests using `// EMIT_MIR_FOR_EACH_BIT_WIDTH` have # both 32-bit and 64-bit outputs updated by the PR author, before From bd71c71ea04b4a4f954e579c2a6d44113274846a Mon Sep 17 00:00:00 2001 From: Dion Dokter Date: Mon, 20 May 2024 12:50:37 +0200 Subject: [PATCH 21/29] Move tests to more opportune point --- src/ci/docker/scripts/x86_64-gnu-llvm.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ci/docker/scripts/x86_64-gnu-llvm.sh b/src/ci/docker/scripts/x86_64-gnu-llvm.sh index 8f5f7fdbe47..876b300d35c 100755 --- a/src/ci/docker/scripts/x86_64-gnu-llvm.sh +++ b/src/ci/docker/scripts/x86_64-gnu-llvm.sh @@ -12,10 +12,6 @@ if [[ -z "${PR_CI_JOB}" ]]; then ../x.py --stage 1 test --skip src/tools/tidy fi - # The tests are run a second time with the size optimizations enabled. - ../x.py --stage 1 test library/std library/alloc library/core \ - --rustc-args "--cfg feature=\"optimize_for_size\"" - # Run the `mir-opt` tests again but this time for a 32-bit target. # This enforces that tests using `// EMIT_MIR_FOR_EACH_BIT_WIDTH` have # both 32-bit and 64-bit outputs updated by the PR author, before @@ -27,6 +23,10 @@ if [[ -z "${PR_CI_JOB}" ]]; then # Run `ui-fulldeps` in `--stage=1`, which actually uses the stage0 # compiler, and is sensitive to the addition of new flags. ../x.py --stage 1 test tests/ui-fulldeps + + # The tests are run a second time with the size optimizations enabled. + ../x.py --stage 1 test library/std library/alloc library/core \ + --rustc-args "--cfg feature=\"optimize_for_size\"" fi # When running gcc backend tests, we need to install `libgccjit` and to not run llvm codegen From f6cf103da2d08c9c8598a83da1fc83391bcd1119 Mon Sep 17 00:00:00 2001 From: Tobias Bucher Date: Tue, 21 May 2024 00:36:52 +0200 Subject: [PATCH 22/29] Small fixes to `std::path::absolute` docs --- library/std/src/path.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/library/std/src/path.rs b/library/std/src/path.rs index 79d800ff072..f835b69f0cf 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -3323,7 +3323,7 @@ impl Error for StripPrefixError { /// /// # Examples /// -/// ## Posix paths +/// ## POSIX paths /// /// ``` /// # #[cfg(unix)] @@ -3369,9 +3369,12 @@ impl Error for StripPrefixError { /// ``` /// /// For verbatim paths this will simply return the path as given. For other -/// paths this is currently equivalent to calling [`GetFullPathNameW`][windows-path] -/// This may change in the future. +/// paths this is currently equivalent to calling +/// [`GetFullPathNameW`][windows-path]. /// +/// Note that this [may change in the future][changes]. +/// +/// [changes]: io#platform-specific-behavior /// [posix-semantics]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13 /// [windows-path]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfullpathnamew #[stable(feature = "absolute_path", since = "1.79.0")] From 95c47d3396c324b32ffaedc2681a370107aeb6be Mon Sep 17 00:00:00 2001 From: Oneirical Date: Mon, 20 May 2024 21:30:48 -0400 Subject: [PATCH 23/29] simplify --- tests/run-make/no-intermediate-extras/rmake.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/tests/run-make/no-intermediate-extras/rmake.rs b/tests/run-make/no-intermediate-extras/rmake.rs index bc82b18c4cf..19479e3bd5b 100644 --- a/tests/run-make/no-intermediate-extras/rmake.rs +++ b/tests/run-make/no-intermediate-extras/rmake.rs @@ -10,13 +10,8 @@ use std::fs; fn main() { rustc().crate_type("rlib").arg("--test").input("foo.rs").run(); - match fs::remove_file(tmp_dir().join("foo.bc")) { - Ok(_) => { - println!("An unwanted .bc file was created by run-make/no-intermediate-extras."); - std::process::exit(1); - } - Err(e) => { - std::process::exit(0); - } - } + assert!( + fs::remove_file(tmp_dir().join("foo.bc")).is_err(), + "An unwanted .bc file was created by run-make/no-intermediate-extras." + ); } From eb10eb2b451343c053b5d4e856701a51cd7cde32 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 24 Apr 2024 16:46:57 +1000 Subject: [PATCH 24/29] Reorder top-level attributes. And remove an unnecessary `feature(try_blocks)`. --- compiler/rustc_metadata/src/lib.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_metadata/src/lib.rs b/compiler/rustc_metadata/src/lib.rs index 99584845e49..00bb4c435c8 100644 --- a/compiler/rustc_metadata/src/lib.rs +++ b/compiler/rustc_metadata/src/lib.rs @@ -1,21 +1,22 @@ +// tidy-alphabetical-start +#![allow(internal_features)] +#![allow(rustc::potential_query_instability)] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(rust_logo)] -#![feature(rustdoc_internals)] -#![allow(internal_features)] +#![feature(coroutines)] #![feature(decl_macro)] #![feature(error_iter)] #![feature(extract_if)] -#![feature(coroutines)] +#![feature(if_let_guard)] #![feature(iter_from_coroutine)] #![feature(let_chains)] -#![feature(if_let_guard)] -#![feature(proc_macro_internals)] #![feature(macro_metavar_expr)] #![feature(min_specialization)] -#![feature(trusted_len)] -#![feature(try_blocks)] #![feature(never_type)] -#![allow(rustc::potential_query_instability)] +#![feature(proc_macro_internals)] +#![feature(rustdoc_internals)] +#![feature(trusted_len)] +// tidy-alphabetical-end extern crate proc_macro; From d8ea4689943aa8cd7e949b10f16ebec6a8ac7132 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 25 Apr 2024 10:48:59 +1000 Subject: [PATCH 25/29] Reorder some `use` items. --- compiler/rustc_metadata/src/rmeta/mod.rs | 25 ++++++++++-------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index 79e4ff81093..825034cf96a 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -1,15 +1,13 @@ use crate::creader::CrateMetadataRef; -use decoder::Metadata; +pub(crate) use decoder::{CrateMetadata, CrateNumMap, MetadataBlob}; +use decoder::{DecodeContext, Metadata}; use def_path_hash_map::DefPathHashMapRef; -use rustc_data_structures::fx::FxHashMap; -use rustc_macros::{Decodable, Encodable, TyDecodable, TyEncodable}; -use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerFile; -use rustc_middle::middle::lib_features::FeatureStability; -use table::TableBuilder; - +use encoder::EncodeContext; +pub use encoder::{encode_metadata, rendered_const, EncodedMetadata}; use rustc_ast as ast; use rustc_ast::expand::StrippedCfgItem; use rustc_attr as attr; +use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::svh::Svh; use rustc_hir as hir; use rustc_hir::def::{CtorKind, DefKind, DocLinkResMap}; @@ -18,10 +16,13 @@ use rustc_hir::definitions::DefKey; use rustc_hir::lang_items::LangItem; use rustc_index::bit_set::BitSet; use rustc_index::IndexVec; +use rustc_macros::{Decodable, Encodable, TyDecodable, TyEncodable}; use rustc_macros::{MetadataDecodable, MetadataEncodable}; use rustc_middle::metadata::ModChild; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs; +use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerFile; use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo}; +use rustc_middle::middle::lib_features::FeatureStability; use rustc_middle::middle::resolve_bound_vars::ObjectLifetimeDefault; use rustc_middle::mir; use rustc_middle::trivially_parameterized_over_tcx; @@ -33,20 +34,14 @@ use rustc_serialize::opaque::FileEncoder; use rustc_session::config::SymbolManglingVersion; use rustc_session::cstore::{CrateDepKind, ForeignModule, LinkagePreference, NativeLib}; use rustc_span::edition::Edition; -use rustc_span::hygiene::{ExpnIndex, MacroKind}; +use rustc_span::hygiene::{ExpnIndex, MacroKind, SyntaxContextData}; use rustc_span::symbol::{Ident, Symbol}; use rustc_span::{self, ExpnData, ExpnHash, ExpnId, Span}; use rustc_target::abi::{FieldIdx, VariantIdx}; use rustc_target::spec::{PanicStrategy, TargetTriple}; - use std::marker::PhantomData; use std::num::NonZero; - -use decoder::DecodeContext; -pub(crate) use decoder::{CrateMetadata, CrateNumMap, MetadataBlob}; -use encoder::EncodeContext; -pub use encoder::{encode_metadata, rendered_const, EncodedMetadata}; -use rustc_span::hygiene::SyntaxContextData; +use table::TableBuilder; mod decoder; mod def_path_hash_map; From ce222328d717d63e09a1fe38d8d4c20f7f5c6779 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 1 May 2024 07:56:44 +1000 Subject: [PATCH 26/29] Minor `pub` and whitespace cleanups. --- compiler/rustc_passes/src/check_attr.rs | 9 +++------ compiler/rustc_passes/src/lang_items.rs | 5 +++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index aadbd747313..b1438a542ac 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -42,12 +42,9 @@ use std::collections::hash_map::Entry; #[derive(LintDiagnostic)] #[diag(passes_diagnostic_diagnostic_on_unimplemented_only_for_traits)] -pub struct DiagnosticOnUnimplementedOnlyForTraits; +struct DiagnosticOnUnimplementedOnlyForTraits; -pub(crate) fn target_from_impl_item<'tcx>( - tcx: TyCtxt<'tcx>, - impl_item: &hir::ImplItem<'_>, -) -> Target { +fn target_from_impl_item<'tcx>(tcx: TyCtxt<'tcx>, impl_item: &hir::ImplItem<'_>) -> Target { match impl_item.kind { hir::ImplItemKind::Const(..) => Target::AssocConst, hir::ImplItemKind::Fn(..) => { @@ -99,7 +96,7 @@ struct CheckAttrVisitor<'tcx> { } impl<'tcx> CheckAttrVisitor<'tcx> { - pub fn dcx(&self) -> &'tcx DiagCtxt { + fn dcx(&self) -> &'tcx DiagCtxt { self.tcx.dcx() } diff --git a/compiler/rustc_passes/src/lang_items.rs b/compiler/rustc_passes/src/lang_items.rs index a5fa94faead..b3722e99e16 100644 --- a/compiler/rustc_passes/src/lang_items.rs +++ b/compiler/rustc_passes/src/lang_items.rs @@ -149,8 +149,9 @@ impl<'ast, 'tcx> LanguageItemCollector<'ast, 'tcx> { } }; - // When there's a duplicate lang item, something went very wrong and there's no value in recovering or doing anything. - // Give the user the one message to let them debug the mess they created and then wish them farewell. + // When there's a duplicate lang item, something went very wrong and there's no value + // in recovering or doing anything. Give the user the one message to let them debug the + // mess they created and then wish them farewell. self.tcx.dcx().emit_fatal(DuplicateLangItem { local_span: item_span, lang_item_name, From c1d5b6a480072f34bd47c3c6241a19f996c0c38c Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 1 May 2024 08:42:51 +1000 Subject: [PATCH 27/29] Remove erroneous comment. The comment was originally in `src/librustc_mir/lib.rs`, but now that it's in `compiler/rustc_const_eval/src/lib.rs` it's no longer appropriate. --- compiler/rustc_const_eval/src/lib.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/compiler/rustc_const_eval/src/lib.rs b/compiler/rustc_const_eval/src/lib.rs index a525b838afa..7b293e2b533 100644 --- a/compiler/rustc_const_eval/src/lib.rs +++ b/compiler/rustc_const_eval/src/lib.rs @@ -1,9 +1,3 @@ -/*! - -Rust MIR: a lowered representation of Rust. - -*/ - #![allow(internal_features)] #![allow(rustc::diagnostic_outside_of_impl)] #![feature(rustdoc_internals)] From ac847b2583055c05a327c59d5bf800134e4ea357 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 1 May 2024 08:56:25 +1000 Subject: [PATCH 28/29] Remove unused features from `rustc_middle`. --- compiler/rustc_middle/src/lib.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/compiler/rustc_middle/src/lib.rs b/compiler/rustc_middle/src/lib.rs index 04fd4c8d0f7..27843459353 100644 --- a/compiler/rustc_middle/src/lib.rs +++ b/compiler/rustc_middle/src/lib.rs @@ -35,8 +35,8 @@ #![feature(const_type_name)] #![feature(discriminant_kind)] #![feature(coroutines)] -#![feature(stmt_expr_attributes)] #![feature(if_let_guard)] +#![feature(intra_doc_pointers)] #![feature(iter_from_coroutine)] #![feature(negative_impls)] #![feature(never_type)] @@ -48,12 +48,10 @@ #![feature(type_alias_impl_trait)] #![feature(strict_provenance)] #![feature(rustc_attrs)] -#![feature(control_flow_enum)] #![feature(trait_upcasting)] #![feature(try_blocks)] #![feature(decl_macro)] #![feature(extract_if)] -#![feature(intra_doc_pointers)] #![feature(yeet_expr)] #![feature(const_option)] #![feature(ptr_alignment_type)] From 3ac816a1ca69a19fbb37e1866035ea84082f9f06 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 1 May 2024 08:57:41 +1000 Subject: [PATCH 29/29] Sort `rustc_middle` attributes. As is already done in several other crates, such as `rustc_errors`. --- compiler/rustc_middle/src/lib.rs | 46 +++++++++++++++++--------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/compiler/rustc_middle/src/lib.rs b/compiler/rustc_middle/src/lib.rs index 27843459353..70437fdcb6f 100644 --- a/compiler/rustc_middle/src/lib.rs +++ b/compiler/rustc_middle/src/lib.rs @@ -22,44 +22,46 @@ //! //! This API is completely unstable and subject to change. +// tidy-alphabetical-start +#![allow(internal_features)] +#![allow(rustc::diagnostic_outside_of_impl)] +#![allow(rustc::potential_query_instability)] +#![allow(rustc::untranslatable_diagnostic)] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(rust_logo)] -#![feature(min_exhaustive_patterns)] -#![feature(rustdoc_internals)] #![feature(allocator_api)] #![feature(array_windows)] #![feature(assert_matches)] #![feature(box_patterns)] #![feature(closure_track_caller)] -#![feature(core_intrinsics)] +#![feature(const_option)] #![feature(const_type_name)] -#![feature(discriminant_kind)] +#![feature(core_intrinsics)] #![feature(coroutines)] +#![feature(decl_macro)] +#![feature(discriminant_kind)] +#![feature(extern_types)] +#![feature(extract_if)] #![feature(if_let_guard)] #![feature(intra_doc_pointers)] #![feature(iter_from_coroutine)] +#![feature(let_chains)] +#![feature(macro_metavar_expr)] +#![feature(min_exhaustive_patterns)] +#![feature(min_specialization)] #![feature(negative_impls)] #![feature(never_type)] -#![feature(extern_types)] #![feature(new_uninit)] -#![feature(let_chains)] -#![feature(min_specialization)] -#![feature(trusted_len)] -#![feature(type_alias_impl_trait)] -#![feature(strict_provenance)] -#![feature(rustc_attrs)] -#![feature(trait_upcasting)] -#![feature(try_blocks)] -#![feature(decl_macro)] -#![feature(extract_if)] -#![feature(yeet_expr)] -#![feature(const_option)] #![feature(ptr_alignment_type)] -#![feature(macro_metavar_expr)] -#![allow(internal_features)] -#![allow(rustc::potential_query_instability)] -#![allow(rustc::diagnostic_outside_of_impl)] -#![allow(rustc::untranslatable_diagnostic)] +#![feature(rustc_attrs)] +#![feature(rustdoc_internals)] +#![feature(strict_provenance)] +#![feature(trait_upcasting)] +#![feature(trusted_len)] +#![feature(try_blocks)] +#![feature(type_alias_impl_trait)] +#![feature(yeet_expr)] +// tidy-alphabetical-end #[macro_use] extern crate tracing;