Skip to content

Commit

Permalink
Introduce infrastructure for generating target docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Noratrieb committed Feb 14, 2024
1 parent 502ce82 commit 1b9afad
Show file tree
Hide file tree
Showing 17 changed files with 1,092 additions and 3 deletions.
35 changes: 35 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1636,6 +1636,12 @@ version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"

[[package]]
name = "glob-match"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9985c9503b412198aa4197559e9a318524ebc4519c229bfa05a535828c950b9d"

[[package]]
name = "globset"
version = "0.4.13"
Expand Down Expand Up @@ -5026,6 +5032,19 @@ dependencies = [
"serde",
]

[[package]]
name = "serde_yaml"
version = "0.9.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adf8a49373e98a4c5f0ceb5d05aa7c648d75f63774981ed95b7c7443bbd50c6e"
dependencies = [
"indexmap",
"itoa",
"ryu",
"serde",
"unsafe-libyaml",
]

[[package]]
name = "sha1"
version = "0.10.6"
Expand Down Expand Up @@ -5372,6 +5391,16 @@ dependencies = [
"xattr",
]

[[package]]
name = "target-docs"
version = "0.1.0"
dependencies = [
"eyre",
"glob-match",
"serde",
"serde_yaml",
]

[[package]]
name = "tempfile"
version = "3.10.0"
Expand Down Expand Up @@ -5991,6 +6020,12 @@ dependencies = [
"diff",
]

[[package]]
name = "unsafe-libyaml"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab4c90930b95a82d00dc9e9ac071b4991924390d46cbd0dfe566148667605e4b"

[[package]]
name = "unstable-book-gen"
version = "0.1.0"
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ members = [
"src/tools/rustdoc-gui-test",
"src/tools/opt-dist",
"src/tools/coverage-dump",
"src/tools/target-docs",
]

exclude = [
Expand Down
26 changes: 23 additions & 3 deletions src/bootstrap/src/core/build_steps/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1139,13 +1139,14 @@ impl Step for RustcBook {

/// Builds the rustc book.
///
/// The lints are auto-generated by a tool, and then merged into the book
/// The lints and target docs are auto-generated by a tool, and then merged into the book
/// in the "md-doc" directory in the build output directory. Then
/// "rustbook" is used to convert it to HTML.
fn run(self, builder: &Builder<'_>) {
let out_base = builder.md_doc_out(self.target).join("rustc");
t!(fs::create_dir_all(&out_base));
let out_listing = out_base.join("src/lints");
let out_lints_listing = out_base.join("src/lints");
let out_src_listing = out_base.join("src");
builder.cp_r(&builder.src.join("src/doc/rustc"), &out_base);
builder.info(&format!("Generating lint docs ({})", self.target));

Expand All @@ -1157,7 +1158,7 @@ impl Step for RustcBook {
cmd.arg("--src");
cmd.arg(builder.src.join("compiler"));
cmd.arg("--out");
cmd.arg(&out_listing);
cmd.arg(&out_lints_listing);
cmd.arg("--rustc");
cmd.arg(&rustc);
cmd.arg("--rustc-target").arg(&self.target.rustc_target_arg());
Expand Down Expand Up @@ -1186,6 +1187,25 @@ impl Step for RustcBook {
builder.run(&mut cmd);
drop(doc_generator_guard);

// Run target-docs generator
let mut cmd = builder.tool_cmd(Tool::TargetDocs);
cmd.arg(builder.src.join("src/doc/rustc/target_infos"));
cmd.arg(&out_src_listing);
cmd.env("RUSTC", &rustc);
// For now, we just check that the files are correct but do not generate output.
// See #120745 for more info.
cmd.env("TARGET_CHECK_ONLY", "1");

let doc_generator_guard = builder.msg(
Kind::Run,
self.compiler.stage,
"target-docs",
self.compiler.host,
self.target,
);
builder.run(&mut cmd);
drop(doc_generator_guard);

// Run rustbook/mdbook to generate the HTML pages.
builder.ensure(RustbookSrc {
target: self.target,
Expand Down
1 change: 1 addition & 0 deletions src/bootstrap/src/core/build_steps/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ bootstrap_tool!(
RustdocTheme, "src/tools/rustdoc-themes", "rustdoc-themes";
ExpandYamlAnchors, "src/tools/expand-yaml-anchors", "expand-yaml-anchors";
LintDocs, "src/tools/lint-docs", "lint-docs";
TargetDocs, "src/tools/target-docs", "target-docs";
JsonDocCk, "src/tools/jsondocck", "jsondocck";
JsonDocLint, "src/tools/jsondoclint", "jsondoclint";
HtmlChecker, "src/tools/html-checker", "html-checker";
Expand Down
1 change: 1 addition & 0 deletions src/doc/rustc/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- [Platform Support](platform-support.md)
- [Target Tier Policy](target-tier-policy.md)
- [Template for Target-specific Documentation](platform-support/TEMPLATE.md)
- [List of Targets](platform-support/targets.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)
Expand Down
9 changes: 9 additions & 0 deletions src/doc/rustc/src/platform-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ All tier 1 targets with host tools support the full standard library.

target | notes
-------|-------
<!-- TIER1HOST SECTION START -->
<!-- See `src/tools/target-docs` -->
<!-- TIER1HOST SECTION END -->
`aarch64-unknown-linux-gnu` | ARM64 Linux (kernel 4.1, glibc 2.17+) [^missing-stack-probes]
`i686-pc-windows-gnu` | 32-bit MinGW (Windows 7+) [^windows-support] [^x86_32-floats-return-ABI]
`i686-pc-windows-msvc` | 32-bit MSVC (Windows 7+) [^windows-support] [^x86_32-floats-return-ABI]
Expand Down Expand Up @@ -92,6 +95,8 @@ so Rustup may install the documentation for a similar tier 1 target instead.

target | notes
-------|-------
<!-- TIER2HOST SECTION START -->
<!-- TIER2HOST SECTION END -->
`aarch64-apple-darwin` | ARM64 macOS (11.0+, Big Sur+)
`aarch64-pc-windows-msvc` | ARM64 Windows MSVC
`aarch64-unknown-linux-musl` | ARM64 Linux with MUSL
Expand Down Expand Up @@ -138,6 +143,8 @@ so Rustup may install the documentation for a similar tier 1 target instead.

target | std | notes
-------|:---:|-------
<!-- TIER2 SECTION START -->
<!-- TIER2 SECTION END -->
`aarch64-apple-ios` | ✓ | ARM64 iOS
[`aarch64-apple-ios-sim`](platform-support/aarch64-apple-ios-sim.md) | ✓ | Apple iOS Simulator on ARM64
`aarch64-fuchsia` | ✓ | Alias for `aarch64-unknown-fuchsia`
Expand Down Expand Up @@ -234,6 +241,8 @@ host tools.

target | std | host | notes
-------|:---:|:----:|-------
<!-- TIER3 SECTION START -->
<!-- TIER3 SECTION END -->
[`arm64e-apple-ios`](platform-support/arm64e-apple-ios.md) | ✓ | | ARM64e Apple iOS
[`arm64e-apple-darwin`](platform-support/arm64e-apple-darwin.md) | ✓ | ✓ | ARM64e Apple Darwin
`aarch64-apple-ios-macabi` | ? | | Apple Catalyst on ARM64
Expand Down
7 changes: 7 additions & 0 deletions src/doc/rustc/src/platform-support/targets.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# List of all targets

An alphabetical list of all targets.

<!-- TARGET SECTION START -->
<!-- See `src/tools/target-docs` -->
<!-- TARGET SECTION END -->
84 changes: 84 additions & 0 deletions src/doc/rustc/target_infos/*-apple-tvos.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
tier: "2"
maintainers: ["@thomcc"]
metadata:
- target: "aarch64-apple-tvos"
notes: "ARM64 tvOS"
std: "unknown"
host: false
---

## Overview

Apple tvOS targets:
- Apple tvOS on aarch64
- Apple tvOS Simulator on x86_64

## 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.

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.

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.

As with the other Apple targets, `rustc` respects the common environment
variables used by Xcode to configure this, 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:

- `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
more flexible `fork`/`exec`-based approach is prohibited on these platforms in
favor of `posix_spawn{,p}` (which still probably will get you rejected from
app stores, so is likely sideloading-only). A concrete set of cases where this
will occur is difficult to enumerate (and would quickly become stale), but in
some cases it may be worked around by tweaking the manner in which `Command`
is invoked.

## Building the target

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"]
```

It's possible that cargo under `-Zbuild-std` may also be used to target them.

## 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

```text
$ 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.

It hopefully will be possible to improve this in the future.

## 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.
20 changes: 20 additions & 0 deletions src/doc/rustc/target_infos/i686-pc-windows-gnu.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
tier: "1"
metadata:
- target: "i686-pc-windows-gnu"
notes: "32-bit MinGW (Windows 7+)"
std: true
host: true
footnotes:
- name: "x86_32-floats-return-ABI"
content: |
Due to limitations of the C ABI, floating-point support on `i686` targets is non-compliant:
floating-point return values are passed via an x87 register, so NaN payload bits can be lost.
See [issue #114479][https://github.com/rust-lang/rust/issues/114479].
- name: "windows-support"
content: "Only Windows 10 currently undergoes automated testing. Earlier versions of Windows rely on testing and support from the community."
---

## Overview

32-bit Windows using MinGW.
99 changes: 99 additions & 0 deletions src/doc/rustc/target_infos/loongarch*-unknown-linux-*.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
---
tier: "2"
maintainers:
- "[WANG Rui](https://github.com/heiher) `wangrui@loongson.cn`"
- "[ZHAI Xiang](https://github.com/xiangzhai) `zhaixiang@loongson.cn`"
- "[ZHAI Xiaojuan](https://github.com/zhaixiaojuan) `zhaixiaojuan@loongson.cn`"
- "[WANG Xuerui](https://github.com/xen0n) `git@xen0n.name`"
metadata:
- target: "loongarch64-unknown-linux-gnu"
notes: "LoongArch64 Linux, LP64D ABI (kernel 5.19, glibc 2.36)"
std: true
host: true
---

## Overview

[LoongArch] is a new RISC ISA developed by Loongson Technology Corporation Limited.

[LoongArch]: https://loongson.github.io/LoongArch-Documentation/README-EN.html

The target name follow this format: `<machine>-<vendor>-<os><fabi_suffix>`, where `<machine>` specifies the CPU family/model, `<vendor>` specifies the vendor and `<os>` the operating system name.
While the integer base ABI is implied by the machine field, the floating point base ABI type is encoded into the os field of the specifier using the string suffix `<fabi-suffix>`.

| `<fabi-suffix>` | `Description` |
|------------------------|--------------------------------------------------------------------|
| f64 | The base ABI use 64-bits FPRs for parameter passing. (lp64d)|
| f32 | The base ABI uses 32-bit FPRs for parameter passing. (lp64f)|
| sf | The base ABI uses no FPR for parameter passing. (lp64s) |

<br>

|`ABI type(Base ABI/ABI extension)`| `C library` | `kernel` | `target tuple` |
|----------------------------------|-------------|----------|----------------------------------|
| lp64d/base | glibc | linux | loongarch64-unknown-linux-gnu |
| lp64f/base | glibc | linux | loongarch64-unknown-linux-gnuf32 |
| lp64s/base | glibc | linux | loongarch64-unknown-linux-gnusf |
| lp64d/base | musl libc | linux | loongarch64-unknown-linux-musl|
| lp64f/base | musl libc | linux | loongarch64-unknown-linux-muslf32|
| lp64s/base | musl libc | linux | loongarch64-unknown-linux-muslsf |

## Requirements

This target is cross-compiled.
A GNU toolchain for LoongArch target is required. It can be downloaded from https://github.com/loongson/build-tools/releases, or built from the source code of GCC (12.1.0 or later) and Binutils (2.40 or later).

## Building the target

The target can be built by enabling it for a `rustc` build.

```toml
[build]
target = ["loongarch64-unknown-linux-gnu"]
```

Make sure `loongarch64-unknown-linux-gnu-gcc` can be searched from the directories specified in`$PATH`. Alternatively, you can use GNU LoongArch Toolchain by adding the following to `config.toml`:

```toml
[target.loongarch64-unknown-linux-gnu]
# ADJUST THIS PATH TO POINT AT YOUR TOOLCHAIN
cc = "/TOOLCHAIN_PATH/bin/loongarch64-unknown-linux-gnu-gcc"
cxx = "/TOOLCHAIN_PATH/bin/loongarch64-unknown-linux-gnu-g++"
ar = "/TOOLCHAIN_PATH/bin/loongarch64-unknown-linux-gnu-ar"
ranlib = "/TOOLCHAIN_PATH/bin/loongarch64-unknown-linux-gnu-ranlib"
linker = "/TOOLCHAIN_PATH/bin/loongarch64-unknown-linux-gnu-gcc"
```

## Cross compilation

This target can be cross-compiled on a `x86_64-unknown-linux-gnu` host. Cross-compilation on other hosts may work but is not tested.

## Testing
To test a cross-compiled binary on your build system, install the qemu binary that supports the LoongArch architecture and execute the following commands.
```text
CC_loongarch64_unknown_linux_gnu=/TOOLCHAIN_PATH/bin/loongarch64-unknown-linux-gnu-gcc \
CXX_loongarch64_unknown_linux_gnu=/TOOLCHAIN_PATH/bin/loongarch64-unknown-linux-gnu-g++ \
AR_loongarch64_unknown_linux_gnu=/TOOLCHAIN_PATH/bin/loongarch64-unknown-linux-gnu-gcc-ar \
CARGO_TARGET_LOONGARCH64_UNKNOWN_LINUX_GNUN_LINKER=/TOOLCHAIN_PATH/bin/loongarch64-unknown-linux-gnu-gcc \
# SET TARGET SYSTEM LIBRARY PATH
CARGO_TARGET_LOONGARCH64_UNKNOWN_LINUX_GNUN_RUNNER="qemu-loongarch64 -L /TOOLCHAIN_PATH/TARGET_LIBRARY_PATH" \
cargo run --target loongarch64-unknown-linux-gnu --release
```
Tested on x86 architecture, other architectures not tested.

## Building Rust programs

Rust does not yet ship 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 of `std` by using `build-std` or similar.

If `rustc` has support for that target and the library artifacts are available, then Rust static libraries can be built for that target:

```shell
$ rustc --target loongarch64-unknown-linux-gnu your-code.rs --crate-type staticlib
$ ls libyour_code.a
```

On Rust Nightly it's possible to build without the target artifacts available:

```text
cargo build -Z build-std --target loongarch64-unknown-linux-gnu
```
Loading

0 comments on commit 1b9afad

Please sign in to comment.