Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
rewrite compiler-lookup-paths to rmake
  • Loading branch information
Oneirical committed Jul 16, 2024
commit 9ce62297fafc4640351164be8b335ab6b6fb2880
8 changes: 8 additions & 0 deletions src/tools/run-make-support/src/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,14 @@ impl Rustc {
self
}

/// Add a directory to the library search path with a restriction. Equivalent to `-L KIND=PATH` in rustc.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: maybe specify that the restriction is the kind of search path? We could also link to https://doc.rust-lang.org/rustc/command-line-arguments.html#-l-add-a-directory-to-the-library-search-path.

Copy link
Contributor Author

@Oneirical Oneirical Jul 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't add the link, because it's over 100 characters and tidy would complain, but I did add a precision.

/// Add a directory to the library search path with a restriction, where `kind` is a dependency
/// type. Equivalent to `-L KIND=PATH` in rustc.

Copy link
Member

@jieyouxu jieyouxu Jul 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add // ignore-tidy-linelength (or was it // tidy-ignore-linelength?) to make tidy ignore the line length check for this file.

pub fn specific_library_search_path<P: AsRef<Path>>(&mut self, kind: &str, path: P) -> &mut Self {
assert!(["dependency", "native", "all", "framework", "crate"].contains(&kind));
let path = path.as_ref().to_string_lossy();
self.cmd.arg(format!("-L{kind}={path}"));
self
}

/// Override the system root. Equivalent to `--sysroot` in rustc.
pub fn sysroot<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
self.cmd.arg("--sysroot");
Expand Down
1 change: 0 additions & 1 deletion src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ run-make/c-unwind-abi-catch-panic/Makefile
run-make/cat-and-grep-sanity-check/Makefile
run-make/cdylib-dylib-linkage/Makefile
run-make/compiler-lookup-paths-2/Makefile
run-make/compiler-lookup-paths/Makefile
run-make/compiler-rt-works-on-mingw/Makefile
run-make/crate-hash-rustc-version/Makefile
run-make/cross-lang-lto-clang/Makefile
Expand Down
44 changes: 0 additions & 44 deletions tests/run-make/compiler-lookup-paths/Makefile

This file was deleted.

103 changes: 103 additions & 0 deletions tests/run-make/compiler-lookup-paths/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// Since #19941, rustc can accept specifications on its library search paths.
// This test runs Rust programs with varied library dependencies, expecting them
// to succeed or fail depending on the situation.
// The second part of the tests also checks that libraries with an incorrect hash
// fail to be used by the compiler.
// See https://github.com/rust-lang/rust/pull/19941

use run_make_support::fs_wrapper;
use run_make_support::{rmake_out_path, rustc};

fn main() {
assert!(rmake_out_path("libnative.a").exists());
fs_wrapper::create_dir_all(rmake_out_path("crate"));
fs_wrapper::create_dir_all(rmake_out_path("native"));
fs_wrapper::rename(rmake_out_path("libnative.a"), rmake_out_path("native"));
rustc().input("a.rs").run();
fs_wrapper::rename(rmake_out_path("liba.a"), rmake_out_path("crate"));
rustc()
.input("b.rs")
.specific_library_search_path("native", rmake_out_path("crate"))
.run_fail();
rustc()
.input("b.rs")
.specific_library_search_path("dependency", rmake_out_path("crate"))
.run_fail();
rustc().input("b.rs").specific_library_search_path("crate", rmake_out_path("crate")).run();
rustc().input("b.rs").specific_library_search_path("all", rmake_out_path("crate")).run();

rustc()
.input("c.rs")
.specific_library_search_path("native", rmake_out_path("crate"))
.run_fail();
rustc().input("c.rs").specific_library_search_path("crate", rmake_out_path("crate")).run_fail();
rustc().input("c.rs").specific_library_search_path("dependency", rmake_out_path("crate")).run();
rustc().input("c.rs").specific_library_search_path("all", rmake_out_path("crate")).run();

rustc()
.input("d.rs")
.specific_library_search_path("dependency", rmake_out_path("native"))
.run_fail();
rustc()
.input("d.rs")
.specific_library_search_path("crate", rmake_out_path("native"))
.run_fail();
rustc().input("d.rs").specific_library_search_path("native", rmake_out_path("native")).run();
rustc().input("d.rs").specific_library_search_path("all", rmake_out_path("native")).run();

// Deduplication tests.
fs_wrapper::create_dir_all(rmake_out_path("e1"));
fs_wrapper::create_dir_all(rmake_out_path("e2"));

rustc().input("e.rs").output(rmake_out_path("e1/libe.rlib")).run();
rustc().input("e.rs").output(rmake_out_path("e2/libe.rlib")).run();
// If the library hash is correct, compilation should succeed.
rustc()
.input("f.rs")
.library_search_path(rmake_out_path("e1"))
.library_search_path(rmake_out_path("e2"))
.run();
rustc()
.input("f.rs")
.specific_library_search_path("crate", rmake_out_path("e1"))
.library_search_path(rmake_out_path("e2"))
.run();
rustc()
.input("f.rs")
.specific_library_search_path("crate", rmake_out_path("e1"))
.specific_library_search_path("crate", rmake_out_path("e2"))
.run();
// If the library has a different hash, errors should occur.
rustc().input("e2.rs").output(rmake_out_path("e2/libe.rlib")).run();
rustc()
.input("f.rs")
.library_search_path(rmake_out_path("e1"))
.library_search_path(rmake_out_path("e2"))
.run_fail();
rustc()
.input("f.rs")
.specific_library_search_path("crate", rmake_out_path("e1"))
.library_search_path(rmake_out_path("e2"))
.run_fail();
rustc()
.input("f.rs")
.specific_library_search_path("crate", rmake_out_path("e1"))
.specific_library_search_path("crate", rmake_out_path("e2"))
.run_fail();
// Native and dependency paths do not cause errors.
rustc()
.input("f.rs")
.specific_library_search_path("native", rmake_out_path("e1"))
.library_search_path(rmake_out_path("e2"))
.run();
rustc()
.input("f.rs")
.specific_library_search_path("dependency", rmake_out_path("e1"))
.library_search_path(rmake_out_path("e2"))
.run();
rustc()
.input("f.rs")
.specific_library_search_path("dependency", rmake_out_path("e1"))
.specific_library_search_path("crate", rmake_out_path("e2"))
.run();
}