|
| 1 | +//! Regression test for [rustc doesn't handle relative symlinks to libraries |
| 2 | +//! #13890](https://github.com/rust-lang/rust/issues/13890). |
| 3 | +//! |
| 4 | +//! `rustc` searches by default for libraries in its current directory, but used to have difficulty |
| 5 | +//! locating a library if it is provided behind a symlink, e.g. |
| 6 | +//! |
| 7 | +//! ```text |
| 8 | +//! actual_dir/ |
| 9 | +//! libfoo.rlib |
| 10 | +//! symlink_dir/ # $CWD set; rustc -L . bar.rs that depends on foo |
| 11 | +//! libfoo.rlib --> ../actual_dir/libfoo.rlib |
| 12 | +//! ``` |
| 13 | +//! |
| 14 | +//! Previously, if `rustc` was invoked with CWD set to `symlink_dir/`, it would fail to traverse the |
| 15 | +//! symlink to locate `actual_dir/libfoo.rlib`. |
| 16 | +
|
| 17 | +//@ ignore-cross-compile |
| 18 | + |
| 19 | +use run_make_support::{bare_rustc, cwd, path, rfs, rust_lib_name}; |
| 20 | + |
| 21 | +fn main() { |
| 22 | + let actual_lib_dir = path("actual_lib_dir"); |
| 23 | + let symlink_lib_dir = path("symlink_lib_dir"); |
| 24 | + rfs::create_dir_all(&actual_lib_dir); |
| 25 | + rfs::create_dir_all(&symlink_lib_dir); |
| 26 | + |
| 27 | + // NOTE: `bare_rustc` is used because it does not introduce an implicit `-L .` library search |
| 28 | + // flag. |
| 29 | + bare_rustc().input("foo.rs").output(actual_lib_dir.join(rust_lib_name("foo"))).run(); |
| 30 | + |
| 31 | + rfs::symlink_file( |
| 32 | + actual_lib_dir.join(rust_lib_name("foo")), |
| 33 | + symlink_lib_dir.join(rust_lib_name("foo")), |
| 34 | + ); |
| 35 | + |
| 36 | + // Make rustc's $CWD be in the directory containing the symlink-to-lib. |
| 37 | + bare_rustc() |
| 38 | + .current_dir(&symlink_lib_dir) |
| 39 | + .library_search_path(".") |
| 40 | + .input(cwd().join("bar.rs")) |
| 41 | + .run(); |
| 42 | +} |
0 commit comments