Skip to content

Commit ecd7ea8

Browse files
authored
Merge branch 'rust-lang:master' into must-use-alloc-constructors
2 parents 58cc18c + 9e8356c commit ecd7ea8

File tree

15 files changed

+216
-61
lines changed

15 files changed

+216
-61
lines changed

compiler/rustc_codegen_llvm/src/callee.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ pub fn get_fn(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'tcx>) -> &'ll Value
175175
// should use dllimport for functions.
176176
if cx.use_dll_storage_attrs
177177
&& tcx.is_dllimport_foreign_item(instance_def_id)
178-
&& tcx.sess.target.env != "gnu"
178+
&& !matches!(tcx.sess.target.env.as_ref(), "gnu" | "uclibc")
179179
{
180180
llvm::LLVMSetDLLStorageClass(llfn, llvm::DLLStorageClass::DllImport);
181181
}

compiler/rustc_middle/src/ty/layout.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3012,7 +3012,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
30123012
};
30133013

30143014
let target = &self.tcx.sess.target;
3015-
let target_env_gnu_like = matches!(&target.env[..], "gnu" | "musl");
3015+
let target_env_gnu_like = matches!(&target.env[..], "gnu" | "musl" | "uclibc");
30163016
let win_x64_gnu = target.os == "windows" && target.arch == "x86_64" && target.env == "gnu";
30173017
let linux_s390x_gnu_like =
30183018
target.os == "linux" && target.arch == "s390x" && target_env_gnu_like;
@@ -3110,7 +3110,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
31103110
if arg.layout.is_zst() {
31113111
// For some forsaken reason, x86_64-pc-windows-gnu
31123112
// doesn't ignore zero-sized struct arguments.
3113-
// The same is true for {s390x,sparc64,powerpc}-unknown-linux-{gnu,musl}.
3113+
// The same is true for {s390x,sparc64,powerpc}-unknown-linux-{gnu,musl,uclibc}.
31143114
if is_return
31153115
|| rust_abi
31163116
|| (!win_x64_gnu
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use crate::spec::{Target, TargetOptions};
2+
3+
// This target is for uclibc Linux on ARMv7 without NEON or
4+
// thumb-mode. See the thumbv7neon variant for enabling both.
5+
6+
pub fn target() -> Target {
7+
let base = super::linux_uclibc_base::opts();
8+
Target {
9+
llvm_target: "armv7-unknown-linux-gnueabihf".to_string(),
10+
pointer_width: 32,
11+
data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(),
12+
arch: "arm".to_string(),
13+
14+
options: TargetOptions {
15+
// Info about features at https://wiki.debian.org/ArmHardFloatPort
16+
features: "+v7,+vfp3,-d32,+thumb2,-neon".to_string(),
17+
cpu: "generic".to_string(),
18+
max_atomic_width: Some(64),
19+
mcount: "_mcount".to_string(),
20+
abi: "eabihf".to_string(),
21+
..base
22+
},
23+
}
24+
}

compiler/rustc_target/src/spec/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,8 @@ supported_targets! {
952952
("bpfel-unknown-none", bpfel_unknown_none),
953953

954954
("armv6k-nintendo-3ds", armv6k_nintendo_3ds),
955+
956+
("armv7-unknown-linux-uclibceabihf", armv7_unknown_linux_uclibceabihf),
955957
}
956958

957959
/// Warnings encountered when parsing the target `json`.

library/std/src/sys/unix/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,9 @@ cfg_if::cfg_if! {
307307
#[link(name = "zircon")]
308308
#[link(name = "fdio")]
309309
extern "C" {}
310+
} else if #[cfg(all(target_os = "linux", target_env = "uclibc"))] {
311+
#[link(name = "dl")]
312+
extern "C" {}
310313
}
311314
}
312315

library/std/src/sys/unix/thread.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,8 @@ pub mod guard {
594594
Some(stackaddr - guardsize..stackaddr)
595595
} else if cfg!(all(target_os = "linux", target_env = "musl")) {
596596
Some(stackaddr - guardsize..stackaddr)
597-
} else if cfg!(all(target_os = "linux", target_env = "gnu")) {
597+
} else if cfg!(all(target_os = "linux", any(target_env = "gnu", target_env = "uclibc")))
598+
{
598599
// glibc used to include the guard area within the stack, as noted in the BUGS
599600
// section of `man pthread_attr_getguardsize`. This has been corrected starting
600601
// with glibc 2.27, and in some distro backports, so the guard is now placed at the

library/unwind/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ cfg_if::cfg_if! {
6363
// don't want to duplicate it here.
6464
#[cfg(all(
6565
target_os = "linux",
66-
target_env = "gnu",
66+
any(target_env = "gnu", target_env = "uclibc"),
6767
not(feature = "llvm-libunwind"),
6868
not(feature = "system-llvm-libunwind")
6969
))]
@@ -72,7 +72,7 @@ extern "C" {}
7272

7373
#[cfg(all(
7474
target_os = "linux",
75-
target_env = "gnu",
75+
any(target_env = "gnu", target_env = "uclibc"),
7676
not(feature = "llvm-libunwind"),
7777
feature = "system-llvm-libunwind"
7878
))]

src/doc/rustc/src/platform-support.md

+1
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ target | std | host | notes
220220
`armv6-unknown-netbsd-eabihf` | ? | |
221221
`armv6k-nintendo-3ds` | * | | ARMv6K Nintendo 3DS, Horizon (Requires devkitARM toolchain)
222222
`armv7-apple-ios` | ✓ | | ARMv7 iOS, Cortex-a8
223+
`armv7-unknown-linux-uclibceabihf` | ✓ | ? | ARMv7 Linux uClibc
223224
`armv7-unknown-freebsd` | ✓ | ✓ | ARMv7 FreeBSD
224225
`armv7-unknown-netbsd-eabihf` | ✓ | ✓ |
225226
`armv7-wrs-vxworks-eabihf` | ? | |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# armv7-unknown-linux-uclibceabihf
2+
3+
**Tier: 3**
4+
5+
This tier supports the ARMv7 processor running a Linux kernel and uClibc-ng standard library. It provides full support for rust and the rust standard library.
6+
7+
## Designated Developers
8+
9+
* [@skrap](https://github.com/skrap)
10+
11+
## Requirements
12+
13+
This target is cross compiled, and requires a cross toolchain. You can find suitable pre-built toolchains at [bootlin](https://toolchains.bootlin.com/) or build one yourself via [buildroot](https://buildroot.org).
14+
15+
## Building
16+
17+
### Get a C toolchain
18+
19+
Compiling rust for this target has been tested on `x86_64` linux hosts. Other host types have not been tested, but may work, if you can find a suitable cross compilation toolchain for them.
20+
21+
If you don't already have a suitable toolchain, download one [here](https://toolchains.bootlin.com/downloads/releases/toolchains/armv7-eabihf/tarballs/armv7-eabihf--uclibc--bleeding-edge-2020.08-1.tar.bz2), and unpack it into a directory.
22+
23+
### Configure rust
24+
25+
The target can be built by enabling it for a `rustc` build, by placing the following in `config.toml`:
26+
27+
```toml
28+
[build]
29+
target = ["armv7-unknown-linux-uclibceabihf"]
30+
stage = 2
31+
32+
[target.armv7-unknown-linux-uclibceabihf]
33+
# ADJUST THIS PATH TO POINT AT YOUR TOOLCHAIN
34+
cc = "/TOOLCHAIN_PATH/bin/arm-buildroot-linux-uclibcgnueabihf-gcc"
35+
```
36+
37+
### Build
38+
39+
```sh
40+
# in rust dir
41+
./x.py build --stage 2
42+
```
43+
44+
## Building and Running Rust Programs
45+
46+
To test cross-compiled binaries on a `x86_64` system, you can use the `qemu-arm` [userspace emulation](https://qemu-project.gitlab.io/qemu/user/main.html) program. This avoids having a full emulated ARM system by doing dynamic binary translation and dynamic system call translation. It lets you run ARM programs directly on your `x86_64` kernel. It's very convenient!
47+
48+
To use:
49+
50+
* Install `qemu-arm` according to your distro.
51+
* Link your built toolchain via:
52+
* `rustup toolchain link stage2 ${RUST}/build/x86_64-unknown-linux-gnu/stage2`
53+
* Create a test program
54+
55+
```sh
56+
cargo new hello_world
57+
cd hello_world
58+
```
59+
60+
* Build and run
61+
62+
```sh
63+
CARGO_TARGET_ARMV7_UNKNOWN_LINUX_UCLIBCEABIHF_RUNNER="qemu-arm -L ${TOOLCHAIN}/arm-buildroot-linux-uclibcgnueabihf/sysroot/" \
64+
CARGO_TARGET_ARMV7_UNKNOWN_LINUX_UCLIBCEABIHF_LINKER=${TOOLCHAIN}/bin/arm-buildroot-linux-uclibcgnueabihf-gcc \
65+
cargo +stage2 run --target armv7-unknown-linux-uclibceabihf
66+
```

src/librustdoc/html/render/context.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::cell::RefCell;
22
use std::collections::BTreeMap;
3-
use std::error::Error as StdError;
43
use std::io;
54
use std::path::{Path, PathBuf};
65
use std::rc::Rc;
@@ -16,6 +15,7 @@ use rustc_span::symbol::sym;
1615

1716
use super::cache::{build_index, ExternalLocation};
1817
use super::print_item::{full_path, item_path, print_item};
18+
use super::templates;
1919
use super::write_shared::write_shared;
2020
use super::{
2121
collect_spans_and_sources, print_sidebar, settings, AllTypes, LinkFromSrc, NameDoc, StylePath,
@@ -33,7 +33,6 @@ use crate::formats::FormatRenderer;
3333
use crate::html::escape::Escape;
3434
use crate::html::format::Buffer;
3535
use crate::html::markdown::{self, plain_text_summary, ErrorCodes, IdMap};
36-
use crate::html::static_files::PAGE;
3736
use crate::html::{layout, sources};
3837

3938
/// Major driving force in all rustdoc rendering. This contains information
@@ -225,7 +224,7 @@ impl<'tcx> Context<'tcx> {
225224
&self.shared.layout,
226225
&page,
227226
|buf: &mut _| print_sidebar(self, it, buf),
228-
|buf: &mut _| print_item(self, it, buf, &page),
227+
|buf: &mut _| print_item(self, &self.shared.templates, it, buf, &page),
229228
&self.shared.style_files,
230229
)
231230
} else {
@@ -416,12 +415,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
416415
};
417416
let mut issue_tracker_base_url = None;
418417
let mut include_sources = true;
419-
420-
let mut templates = tera::Tera::default();
421-
templates.add_raw_template("page.html", PAGE).map_err(|e| Error {
422-
file: "page.html".into(),
423-
error: format!("{}: {}", e, e.source().map(|e| e.to_string()).unwrap_or_default()),
424-
})?;
418+
let templates = templates::load()?;
425419

426420
// Crawl the crate attributes looking for attributes which control how we're
427421
// going to emit HTML

src/librustdoc/html/render/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ mod tests;
3131
mod context;
3232
mod print_item;
3333
mod span_map;
34+
mod templates;
3435
mod write_shared;
3536

3637
crate use context::*;

src/librustdoc/html/render/print_item.rs

+63-44
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,41 @@ use crate::html::highlight;
3232
use crate::html::layout::Page;
3333
use crate::html::markdown::{HeadingOffset, MarkdownSummaryLine};
3434

35+
use serde::Serialize;
36+
3537
const ITEM_TABLE_OPEN: &'static str = "<div class=\"item-table\">";
3638
const ITEM_TABLE_CLOSE: &'static str = "</div>";
3739
const ITEM_TABLE_ROW_OPEN: &'static str = "<div class=\"item-row\">";
3840
const ITEM_TABLE_ROW_CLOSE: &'static str = "</div>";
3941

40-
pub(super) fn print_item(cx: &Context<'_>, item: &clean::Item, buf: &mut Buffer, page: &Page<'_>) {
42+
// A component in a `use` path, like `string` in std::string::ToString
43+
#[derive(Serialize)]
44+
struct PathComponent<'a> {
45+
path: String,
46+
name: &'a str,
47+
}
48+
49+
#[derive(Serialize)]
50+
struct ItemVars<'a> {
51+
page: &'a Page<'a>,
52+
static_root_path: &'a str,
53+
typ: &'a str,
54+
name: &'a str,
55+
item_type: &'a str,
56+
path_components: Vec<PathComponent<'a>>,
57+
stability_since_raw: &'a str,
58+
src_href: Option<&'a str>,
59+
}
60+
61+
pub(super) fn print_item(
62+
cx: &Context<'_>,
63+
templates: &tera::Tera,
64+
item: &clean::Item,
65+
buf: &mut Buffer,
66+
page: &Page<'_>,
67+
) {
4168
debug_assert!(!item.is_stripped());
42-
// Write the breadcrumb trail header for the top
43-
buf.write_str("<h1 class=\"fqn\"><span class=\"in-band\">");
44-
let name = match *item.kind {
69+
let typ = match *item.kind {
4570
clean::ModuleItem(_) => {
4671
if item.is_crate() {
4772
"Crate "
@@ -73,60 +98,54 @@ pub(super) fn print_item(cx: &Context<'_>, item: &clean::Item, buf: &mut Buffer,
7398
unreachable!();
7499
}
75100
};
76-
buf.write_str(name);
77-
if !item.is_primitive() && !item.is_keyword() {
78-
let cur = &cx.current;
79-
let amt = if item.is_mod() { cur.len() - 1 } else { cur.len() };
80-
for (i, component) in cur.iter().enumerate().take(amt) {
81-
write!(
82-
buf,
83-
"<a href=\"{}index.html\">{}</a>::<wbr>",
84-
"../".repeat(cur.len() - i - 1),
85-
component
86-
);
87-
}
88-
}
89-
write!(buf, "<a class=\"{}\" href=\"#\">{}</a>", item.type_(), item.name.as_ref().unwrap());
90-
write!(
91-
buf,
92-
"<button id=\"copy-path\" onclick=\"copy_path(this)\" title=\"Copy item path to clipboard\">\
93-
<img src=\"{static_root_path}clipboard{suffix}.svg\" \
94-
width=\"19\" height=\"18\" \
95-
alt=\"Copy item path\">\
96-
</button>",
97-
static_root_path = page.get_static_root_path(),
98-
suffix = page.resource_suffix,
99-
);
100-
101-
buf.write_str("</span>"); // in-band
102-
buf.write_str("<span class=\"out-of-band\">");
101+
let mut stability_since_raw = Buffer::new();
103102
render_stability_since_raw(
104-
buf,
103+
&mut stability_since_raw,
105104
item.stable_since(cx.tcx()).as_deref(),
106105
item.const_stability(cx.tcx()),
107106
None,
108107
None,
109108
);
110-
buf.write_str(
111-
"<span id=\"render-detail\">\
112-
<a id=\"toggle-all-docs\" href=\"javascript:void(0)\" \
113-
title=\"collapse all docs\">\
114-
[<span class=\"inner\">&#x2212;</span>]\
115-
</a>\
116-
</span>",
117-
);
109+
let stability_since_raw: String = stability_since_raw.into_inner();
118110

119111
// Write `src` tag
120112
//
121113
// When this item is part of a `crate use` in a downstream crate, the
122114
// [src] link in the downstream documentation will actually come back to
123115
// this page, and this link will be auto-clicked. The `id` attribute is
124116
// used to find the link to auto-click.
125-
if cx.include_sources && !item.is_primitive() {
126-
write_srclink(cx, item, buf);
127-
}
117+
let src_href =
118+
if cx.include_sources && !item.is_primitive() { cx.src_href(item) } else { None };
119+
120+
let path_components = if item.is_primitive() || item.is_keyword() {
121+
vec![]
122+
} else {
123+
let cur = &cx.current;
124+
let amt = if item.is_mod() { cur.len() - 1 } else { cur.len() };
125+
cur.iter()
126+
.enumerate()
127+
.take(amt)
128+
.map(|(i, component)| PathComponent {
129+
path: "../".repeat(cur.len() - i - 1),
130+
name: component,
131+
})
132+
.collect()
133+
};
134+
135+
let item_vars = ItemVars {
136+
page: page,
137+
static_root_path: page.get_static_root_path(),
138+
typ: typ,
139+
name: &item.name.as_ref().unwrap().as_str(),
140+
item_type: &item.type_().to_string(),
141+
path_components: path_components,
142+
stability_since_raw: &stability_since_raw,
143+
src_href: src_href.as_deref(),
144+
};
128145

129-
buf.write_str("</span></h1>"); // out-of-band
146+
let teractx = tera::Context::from_serialize(item_vars).unwrap();
147+
let heading = templates.render("print_item.html", &teractx).unwrap();
148+
buf.write_str(&heading);
130149

131150
match *item.kind {
132151
clean::ModuleItem(ref m) => item_module(buf, cx, item, &m.items),
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use std::error::Error as StdError;
2+
3+
use crate::error::Error;
4+
5+
pub(crate) fn load() -> Result<tera::Tera, Error> {
6+
let mut templates = tera::Tera::default();
7+
8+
macro_rules! include_template {
9+
($file:literal, $fullpath:literal) => {
10+
templates.add_raw_template($file, include_str!($fullpath)).map_err(|e| Error {
11+
file: $file.into(),
12+
error: format!("{}: {}", e, e.source().map(|e| e.to_string()).unwrap_or_default()),
13+
})?
14+
};
15+
}
16+
17+
include_template!("page.html", "../templates/page.html");
18+
include_template!("print_item.html", "../templates/print_item.html");
19+
Ok(templates)
20+
}

src/librustdoc/html/static_files.rs

-2
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ crate static RUST_FAVICON_SVG: &[u8] = include_bytes!("static/images/favicon.svg
7070
crate static RUST_FAVICON_PNG_16: &[u8] = include_bytes!("static/images/favicon-16x16.png");
7171
crate static RUST_FAVICON_PNG_32: &[u8] = include_bytes!("static/images/favicon-32x32.png");
7272

73-
crate static PAGE: &str = include_str!("templates/page.html");
74-
7573
/// The built-in themes given to every documentation site.
7674
crate mod themes {
7775
/// The "light" theme, selected by default when no setting is available. Used as the basis for

0 commit comments

Comments
 (0)