Skip to content

Commit 60d4e20

Browse files
committed
compiletest: add aux-crate directive
1 parent 590dd7d commit 60d4e20

File tree

11 files changed

+129
-116
lines changed

11 files changed

+129
-116
lines changed

src/test/run-make-fulldeps/extern-flag-noprelude/Makefile

-11
This file was deleted.

src/test/run-make-fulldeps/extern-flag-noprelude/foo.rs

-3
This file was deleted.

src/test/rustdoc/issue-66159.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
// aux-build:issue-66159-1.rs
1+
// aux-crate:priv:issue_66159_1=issue-66159-1.rs
22
// compile-flags:-Z unstable-options
3-
// extern-private:issue_66159_1
43

54
// The issue was an ICE which meant that we never actually generated the docs
65
// so if we have generated the docs, we're okay.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// check-pass
2+
// aux-crate:noprelude:somedep=somedep.rs
3+
// compile-flags: -Zunstable-options
4+
// edition:2018
5+
6+
// `extern crate` can be used to add to prelude.
7+
extern crate somedep;
8+
9+
fn main() {
10+
somedep::somefun();
11+
}

src/test/ui/extern-flag/noprelude.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// aux-crate:noprelude:somedep=somedep.rs
2+
// compile-flags: -Zunstable-options
3+
// edition:2018
4+
5+
fn main() {
6+
somedep::somefun(); //~ ERROR failed to resolve
7+
}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0433]: failed to resolve: use of undeclared type or module `somedep`
2+
--> $DIR/noprelude.rs:6:5
3+
|
4+
LL | somedep::somefun();
5+
| ^^^^^^^ use of undeclared type or module `somedep`
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0433`.

src/test/ui/privacy/pub-priv-dep/pub-priv1.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
// aux-build:priv_dep.rs
1+
// aux-crate:priv:priv_dep=priv_dep.rs
22
// aux-build:pub_dep.rs
3-
// extern-private:priv_dep
43
#![deny(exported_private_dependencies)]
54

65
// This crate is a private dependency
76
extern crate priv_dep;
8-
// This crate is a public dependenct
7+
// This crate is a public dependency
98
extern crate pub_dep;
109

1110
use priv_dep::{OtherType, OtherTrait};

src/test/ui/privacy/pub-priv-dep/pub-priv1.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
error: type `priv_dep::OtherType` from private dependency 'priv_dep' in public interface
2-
--> $DIR/pub-priv1.rs:21:5
2+
--> $DIR/pub-priv1.rs:20:5
33
|
44
LL | pub field: OtherType,
55
| ^^^^^^^^^^^^^^^^^^^^
66
|
77
note: lint level defined here
8-
--> $DIR/pub-priv1.rs:4:9
8+
--> $DIR/pub-priv1.rs:3:9
99
|
1010
LL | #![deny(exported_private_dependencies)]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212

1313
error: type `priv_dep::OtherType` from private dependency 'priv_dep' in public interface
14-
--> $DIR/pub-priv1.rs:28:5
14+
--> $DIR/pub-priv1.rs:27:5
1515
|
1616
LL | pub fn pub_fn(param: OtherType) {}
1717
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1818

1919
error: trait `priv_dep::OtherTrait` from private dependency 'priv_dep' in public interface
20-
--> $DIR/pub-priv1.rs:34:1
20+
--> $DIR/pub-priv1.rs:33:1
2121
|
2222
LL | / pub trait MyPubTrait {
2323
LL | | type Foo: OtherTrait;

src/tools/compiletest/src/header.rs

+20-9
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ pub struct EarlyProps {
7171
pub ignore: Ignore,
7272
pub should_fail: bool,
7373
pub aux: Vec<String>,
74+
pub aux_crate: Vec<(String, String)>,
7475
pub revisions: Vec<String>,
7576
}
7677

@@ -80,6 +81,7 @@ impl EarlyProps {
8081
ignore: Ignore::Run,
8182
should_fail: false,
8283
aux: Vec::new(),
84+
aux_crate: Vec::new(),
8385
revisions: vec![],
8486
};
8587

@@ -157,6 +159,10 @@ impl EarlyProps {
157159
props.aux.push(s);
158160
}
159161

162+
if let Some(ac) = config.parse_aux_crate(ln) {
163+
props.aux_crate.push(ac);
164+
}
165+
160166
if let Some(r) = config.parse_revisions(ln) {
161167
props.revisions.extend(r);
162168
}
@@ -311,10 +317,9 @@ pub struct TestProps {
311317
// directory as the test, but for backwards compatibility reasons
312318
// we also check the auxiliary directory)
313319
pub aux_builds: Vec<String>,
314-
// A list of crates to pass '--extern priv:name=PATH' flags for
315-
// This should be a subset of 'aux_build'
316-
// FIXME: Replace this with a better solution: https://github.com/rust-lang/rust/pull/54020
317-
pub extern_private: Vec<String>,
320+
// Similar to `aux_builds`, but a list of NAME=somelib.rs of dependencies
321+
// to build and pass with the `--extern` flag.
322+
pub aux_crates: Vec<(String, String)>,
318323
// Environment settings to use for compiling
319324
pub rustc_env: Vec<(String, String)>,
320325
// Environment variables to unset prior to compiling.
@@ -387,7 +392,7 @@ impl TestProps {
387392
run_flags: None,
388393
pp_exact: None,
389394
aux_builds: vec![],
390-
extern_private: vec![],
395+
aux_crates: vec![],
391396
revisions: vec![],
392397
rustc_env: vec![],
393398
unset_rustc_env: vec![],
@@ -514,8 +519,8 @@ impl TestProps {
514519
self.aux_builds.push(ab);
515520
}
516521

517-
if let Some(ep) = config.parse_extern_private(ln) {
518-
self.extern_private.push(ep);
522+
if let Some(ac) = config.parse_aux_crate(ln) {
523+
self.aux_crates.push(ac);
519524
}
520525

521526
if let Some(ee) = config.parse_env(ln, "exec-env") {
@@ -713,8 +718,14 @@ impl Config {
713718
.map(|r| r.trim().to_string())
714719
}
715720

716-
fn parse_extern_private(&self, line: &str) -> Option<String> {
717-
self.parse_name_value_directive(line, "extern-private")
721+
fn parse_aux_crate(&self, line: &str) -> Option<(String, String)> {
722+
self.parse_name_value_directive(line, "aux-crate").map(|r| {
723+
let mut parts = r.trim().splitn(2, '=');
724+
(
725+
parts.next().expect("aux-crate name").to_string(),
726+
parts.next().expect("aux-crate value").to_string(),
727+
)
728+
})
718729
}
719730

720731
fn parse_compile_flags(&self, line: &str) -> Option<String> {

src/tools/compiletest/src/runtest.rs

+75-84
Original file line numberDiff line numberDiff line change
@@ -1776,93 +1776,16 @@ impl<'test> TestCx<'test> {
17761776
create_dir_all(&aux_dir).unwrap();
17771777
}
17781778

1779-
// Use a Vec instead of a HashMap to preserve original order
1780-
let mut extern_priv = self.props.extern_private.clone();
1781-
1782-
let mut add_extern_priv = |priv_dep: &str, dylib: bool| {
1783-
let lib_name = get_lib_name(priv_dep, dylib);
1784-
rustc
1785-
.arg("--extern")
1786-
.arg(format!("priv:{}={}", priv_dep, aux_dir.join(lib_name).to_str().unwrap()));
1787-
};
1788-
17891779
for rel_ab in &self.props.aux_builds {
1790-
let aux_testpaths = self.compute_aux_test_paths(rel_ab);
1791-
let aux_props =
1792-
self.props
1793-
.from_aux_file(&aux_testpaths.file, self.revision, self.config);
1794-
let aux_output = TargetLocation::ThisDirectory(self.aux_output_dir_name());
1795-
let aux_cx = TestCx {
1796-
config: self.config,
1797-
props: &aux_props,
1798-
testpaths: &aux_testpaths,
1799-
revision: self.revision,
1800-
};
1801-
// Create the directory for the stdout/stderr files.
1802-
create_dir_all(aux_cx.output_base_dir()).unwrap();
1803-
let mut aux_rustc = aux_cx.make_compile_args(&aux_testpaths.file, aux_output);
1804-
1805-
let (dylib, crate_type) = if aux_props.no_prefer_dynamic {
1806-
(true, None)
1807-
} else if self.config.target.contains("cloudabi")
1808-
|| self.config.target.contains("emscripten")
1809-
|| (self.config.target.contains("musl")
1810-
&& !aux_props.force_host
1811-
&& !self.config.host.contains("musl"))
1812-
|| self.config.target.contains("wasm32")
1813-
|| self.config.target.contains("nvptx")
1814-
|| self.is_vxworks_pure_static()
1815-
{
1816-
// We primarily compile all auxiliary libraries as dynamic libraries
1817-
// to avoid code size bloat and large binaries as much as possible
1818-
// for the test suite (otherwise including libstd statically in all
1819-
// executables takes up quite a bit of space).
1820-
//
1821-
// For targets like MUSL or Emscripten, however, there is no support for
1822-
// dynamic libraries so we just go back to building a normal library. Note,
1823-
// however, that for MUSL if the library is built with `force_host` then
1824-
// it's ok to be a dylib as the host should always support dylibs.
1825-
(false, Some("lib"))
1826-
} else {
1827-
(true, Some("dylib"))
1828-
};
1829-
1830-
let trimmed = rel_ab.trim_end_matches(".rs").to_string();
1831-
1832-
// Normally, every 'extern-private' has a corresponding 'aux-build'
1833-
// entry. If so, we remove it from our list of private crates,
1834-
// and add an '--extern priv:NAME=PATH' flag to rustc
1835-
if extern_priv.remove_item(&trimmed).is_some() {
1836-
add_extern_priv(&trimmed, dylib);
1837-
}
1838-
1839-
if let Some(crate_type) = crate_type {
1840-
aux_rustc.args(&["--crate-type", crate_type]);
1841-
}
1842-
1843-
aux_rustc.arg("-L").arg(&aux_dir);
1844-
1845-
let auxres = aux_cx.compose_and_run(
1846-
aux_rustc,
1847-
aux_cx.config.compile_lib_path.to_str().unwrap(),
1848-
Some(aux_dir.to_str().unwrap()),
1849-
None,
1850-
);
1851-
if !auxres.status.success() {
1852-
self.fatal_proc_rec(
1853-
&format!(
1854-
"auxiliary build of {:?} failed to compile: ",
1855-
aux_testpaths.file.display()
1856-
),
1857-
&auxres,
1858-
);
1859-
}
1780+
self.build_auxiliary(rel_ab, &aux_dir);
18601781
}
18611782

1862-
// Add any '--extern' private entries without a matching
1863-
// 'aux-build'
1864-
for private_lib in extern_priv {
1865-
add_extern_priv(&private_lib, true);
1783+
for (aux_name, aux_path) in &self.props.aux_crates {
1784+
let is_dylib = self.build_auxiliary(&aux_path, &aux_dir);
1785+
let lib_name = get_lib_name(&aux_path.trim_end_matches(".rs").replace('-', "_"),
1786+
is_dylib);
1787+
rustc.arg("--extern")
1788+
.arg(format!("{}={}/{}", aux_name, aux_dir.display(), lib_name));
18661789
}
18671790

18681791
self.props.unset_rustc_env.clone()
@@ -1877,6 +1800,74 @@ impl<'test> TestCx<'test> {
18771800
)
18781801
}
18791802

1803+
/// Builds an aux dependency.
1804+
///
1805+
/// Returns whether or not it is a dylib.
1806+
fn build_auxiliary(&self, source_path: &str, aux_dir: &Path) -> bool {
1807+
let aux_testpaths = self.compute_aux_test_paths(source_path);
1808+
let aux_props =
1809+
self.props
1810+
.from_aux_file(&aux_testpaths.file, self.revision, self.config);
1811+
let aux_output = TargetLocation::ThisDirectory(self.aux_output_dir_name());
1812+
let aux_cx = TestCx {
1813+
config: self.config,
1814+
props: &aux_props,
1815+
testpaths: &aux_testpaths,
1816+
revision: self.revision,
1817+
};
1818+
// Create the directory for the stdout/stderr files.
1819+
create_dir_all(aux_cx.output_base_dir()).unwrap();
1820+
let mut aux_rustc = aux_cx.make_compile_args(&aux_testpaths.file, aux_output);
1821+
1822+
let (dylib, crate_type) = if aux_props.no_prefer_dynamic {
1823+
(true, None)
1824+
} else if self.config.target.contains("cloudabi")
1825+
|| self.config.target.contains("emscripten")
1826+
|| (self.config.target.contains("musl")
1827+
&& !aux_props.force_host
1828+
&& !self.config.host.contains("musl"))
1829+
|| self.config.target.contains("wasm32")
1830+
|| self.config.target.contains("nvptx")
1831+
|| self.is_vxworks_pure_static()
1832+
{
1833+
// We primarily compile all auxiliary libraries as dynamic libraries
1834+
// to avoid code size bloat and large binaries as much as possible
1835+
// for the test suite (otherwise including libstd statically in all
1836+
// executables takes up quite a bit of space).
1837+
//
1838+
// For targets like MUSL or Emscripten, however, there is no support for
1839+
// dynamic libraries so we just go back to building a normal library. Note,
1840+
// however, that for MUSL if the library is built with `force_host` then
1841+
// it's ok to be a dylib as the host should always support dylibs.
1842+
(false, Some("lib"))
1843+
} else {
1844+
(true, Some("dylib"))
1845+
};
1846+
1847+
if let Some(crate_type) = crate_type {
1848+
aux_rustc.args(&["--crate-type", crate_type]);
1849+
}
1850+
1851+
aux_rustc.arg("-L").arg(&aux_dir);
1852+
1853+
let auxres = aux_cx.compose_and_run(
1854+
aux_rustc,
1855+
aux_cx.config.compile_lib_path.to_str().unwrap(),
1856+
Some(aux_dir.to_str().unwrap()),
1857+
None,
1858+
);
1859+
if !auxres.status.success() {
1860+
self.fatal_proc_rec(
1861+
&format!(
1862+
"auxiliary build of {:?} failed to compile: ",
1863+
aux_testpaths.file.display()
1864+
),
1865+
&auxres,
1866+
);
1867+
}
1868+
dylib
1869+
}
1870+
18801871
fn compose_and_run(
18811872
&self,
18821873
mut command: Command,

0 commit comments

Comments
 (0)