Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
342 changes: 341 additions & 1 deletion tests/testsuite/standard_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct Setup {
real_sysroot: String,
}

fn setup() -> Setup {
pub(crate) fn publish_mock_std_registry_packages() {
// Our mock sysroot requires a few packages from crates.io, so make sure
// they're "published" to crates.io. Also edit their code a bit to make sure
// that they have access to our custom crates with custom apis.
Expand Down Expand Up @@ -83,6 +83,10 @@ fn setup() -> Setup {
.add_dep(Dependency::new("rustc-std-workspace-std", "*").optional(true))
.feature("mockbuild", &["rustc-std-workspace-std"])
.publish();
}

fn setup() -> Setup {
publish_mock_std_registry_packages();

let p = ProjectBuilder::new(paths::root().join("rustc-wrapper"))
.file(
Expand Down Expand Up @@ -384,6 +388,342 @@ fn check_core() {
.run();
}

#[cargo_test(build_std_mock)]
fn build_std_does_not_change_lockfile() {
let setup = setup();
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
edition = "2021"
"#,
)
.file(
"src/main.rs",
r#"
fn main() {
std::custom_api();
}
"#,
)
.build();

p.cargo("generate-lockfile").build_std(&setup).run();
let gen_lockfile = p.read_lockfile();

p.cargo("build").build_std(&setup).run();
let build_lockfile = p.read_lockfile();

assert_eq!(gen_lockfile, build_lockfile);
assert_eq!(
gen_lockfile,
r##"# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4

[[package]]
name = "foo"
version = "0.1.0"
"##
);
}

#[cargo_test(build_std_mock)]
fn builtins_do_not_show_in_package_diff_status_messages() {
let setup = setup();
let p = project()
.file("src/lib.rs", "#![no_std]")
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
edition = "2021"

[dependencies]
registry-dep-using-core = "1.0"
"#,
)
.build();

// New lockfile
p.cargo("generate-lockfile")
.build_std_arg(&setup, "std")
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 1 package [..]
"#]])
.run();

// Updating lockfile
p.cargo("add registry-dep-using-alloc")
.build_std_arg(&setup, "core")
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[ADDING] registry-dep-using-alloc v1.0.0 to dependencies
Features:
- mockbuild
- rustc-std-workspace-alloc
- rustc-std-workspace-core
[LOCKING] 1 package to highest compatible version
[ADDING] registry-dep-using-alloc v1.0.0

"#]])
.run();
}

#[cargo_test(build_std_mock)]
fn builtins_do_not_show_in_metadata() {
let setup = setup();
let p = project()
.file("src/lib.rs", "#![no_std]")
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"

[dependencies]
registry-dep-using-core = "1.0"
"#,
)
.build();

p.cargo("metadata")
.build_std_arg(&setup, "core")
.with_stdout_data(
str![[r#"
{
"packages": [
{
"name": "foo",
"version": "0.1.0",
"id": "path+[ROOTURL]/foo#0.1.0",
"license": null,
"license_file": null,
"description": null,
"source": null,
"dependencies": [
{
"name": "registry-dep-using-core",
"source": "registry+https://github.com/rust-lang/crates.io-index",
"req": "^1.0",
"kind": null,
"rename": null,
"optional": false,
"uses_default_features": true,
"features": [],
"target": null,
"registry": null
}
],
"targets": [
{
"kind": [
"lib"
],
"crate_types": [
"lib"
],
"name": "foo",
"src_path": "[ROOT]/foo/src/lib.rs",
"edition": "2015",
"doc": true,
"doctest": true,
"test": true
}
],
"features": {},
"manifest_path": "[ROOT]/foo/Cargo.toml",
"metadata": null,
"publish": null,
"authors": [],
"categories": [],
"keywords": [],
"readme": null,
"repository": null,
"homepage": null,
"documentation": null,
"edition": "2015",
"links": null,
"default_run": null,
"rust_version": null
},
{
"name": "registry-dep-using-core",
"version": "1.0.0",
"id": "registry+https://github.com/rust-lang/crates.io-index#registry-dep-using-core@1.0.0",
"license": null,
"license_file": null,
"description": null,
"source": "registry+https://github.com/rust-lang/crates.io-index",
"dependencies": [
{
"name": "rustc-std-workspace-core",
"source": "registry+https://github.com/rust-lang/crates.io-index",
"req": "*",
"kind": null,
"rename": null,
"optional": true,
"uses_default_features": true,
"features": [],
"target": null,
"registry": null
}
],
"targets": [
{
"kind": [
"lib"
],
"crate_types": [
"lib"
],
"name": "registry_dep_using_core",
"src_path": "[ROOT]/home/.cargo/registry/src/-[HASH]/registry-dep-using-core-1.0.0/src/lib.rs",
"edition": "2015",
"doc": true,
"doctest": true,
"test": true
}
],
"features": {
"mockbuild": [
"rustc-std-workspace-core"
],
"rustc-std-workspace-core": [
"dep:rustc-std-workspace-core"
]
},
"manifest_path": "[ROOT]/home/.cargo/registry/src/-[HASH]/registry-dep-using-core-1.0.0/Cargo.toml",
"metadata": null,
"publish": null,
"authors": [],
"categories": [],
"keywords": [],
"readme": null,
"repository": null,
"homepage": null,
"documentation": null,
"edition": "2015",
"links": null,
"default_run": null,
"rust_version": null
}
],
"workspace_members": [
"path+[ROOTURL]/foo#0.1.0"
],
"workspace_default_members": [
"path+[ROOTURL]/foo#0.1.0"
],
"resolve": {
"nodes": [
{
"id": "path+[ROOTURL]/foo#0.1.0",
"dependencies": [
"registry+https://github.com/rust-lang/crates.io-index#registry-dep-using-core@1.0.0"
],
"deps": [
{
"name": "registry_dep_using_core",
"pkg": "registry+https://github.com/rust-lang/crates.io-index#registry-dep-using-core@1.0.0",
"dep_kinds": [
{
"kind": null,
"target": null
}
]
}
],
"features": []
},
{
"id": "registry+https://github.com/rust-lang/crates.io-index#registry-dep-using-core@1.0.0",
"dependencies": [
],
"deps": [],
"features": []
}
],
"root": "path+[ROOTURL]/foo#0.1.0"
},
"target_directory": "[ROOT]/foo/target",
"build_directory": "[ROOT]/foo/target",
"version": 1,
"workspace_root": "[ROOT]/foo",
"metadata": null
}
"#]].is_json(),
)
.run();
}

#[cargo_test(build_std_mock)]
fn builtins_do_not_show_in_tree() {
let setup = setup();
let p = project()
.file("src/lib.rs", "#![no_std]")
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"

[dependencies]
registry-dep-using-core = "1.0"
"#,
)
.build();

p.cargo("tree")
.build_std_arg(&setup, "core")
.with_stdout_data(str![[r#"
foo v0.1.0 ([ROOT]/foo)
└── registry-dep-using-core v1.0.0

"#]])
.run();
}

#[cargo_test(build_std_mock)]
fn builtins_are_not_vendored() {
let setup = setup();
let p = project()
.file("src/lib.rs", "#![no_std]")
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"

[dependencies]
registry-dep-using-core = "1.0"
"#,
)
.build();

// --respect-source-config is required to use the crates.io replacement in the test harness
p.cargo("vendor --respect-source-config")
.build_std_arg(&setup, "core")
.run();

assert!(
p.root()
.join("vendor/registry-dep-using-core/Cargo.toml")
.is_file()
);
assert!(!p.root().join("vendor/core").exists());
assert!(!p.root().join("vendor/compiler_builtins").exists());
}

#[cargo_test(build_std_mock)]
fn build_std_with_no_arg_for_core_only_target() {
let target = "aarch64-unknown-none";
Expand Down
Loading