diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2023-06-14 15:20:21 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 18:55:58 +0100 |
commit | e3360d2ba200e334a320cb8d49257e084b4e5233 (patch) | |
tree | ad215e776247138a1b6a8371772e1ac305be2f36 /gcc/rust/rust-session-manager.cc | |
parent | 7e74b450d24074519c8c93dc55c507931b329c5a (diff) | |
download | gcc-e3360d2ba200e334a320cb8d49257e084b4e5233.zip gcc-e3360d2ba200e334a320cb8d49257e084b4e5233.tar.gz gcc-e3360d2ba200e334a320cb8d49257e084b4e5233.tar.bz2 |
gccrs: import: Add cli extern crate resolution
This commit add the ability to specify the path to an extern crate
through the -frust-extern cli option. Path given as cli argument
shall resolve to the exact extern crate location.
gcc/rust/ChangeLog:
* metadata/rust-imports.h: Make the function to load a given
file public.
* rust-session-manager.cc (Session::load_extern_crate): Change
path resolution depending on extern crate declaration in cli
arguments.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc/rust/rust-session-manager.cc')
-rw-r--r-- | gcc/rust/rust-session-manager.cc | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc index af57d57..cc3a208 100644 --- a/gcc/rust/rust-session-manager.cc +++ b/gcc/rust/rust-session-manager.cc @@ -973,12 +973,26 @@ Session::load_extern_crate (const std::string &crate_name, location_t locus) } std::string relative_import_path = ""; - Import::Stream *s - = Import::open_package (crate_name, locus, relative_import_path); + std::string import_name = crate_name; + + // The path to the extern crate might have been specified by the user using + // -frust-extern + auto cli_extern_crate = extern_crates.find (crate_name); + + Import::Stream *s; + if (cli_extern_crate != extern_crates.end ()) + { + auto path = cli_extern_crate->second; + s = Import::try_package_in_directory (path, locus); + } + else + { + s = Import::open_package (import_name, locus, relative_import_path); + } if (s == NULL) { rust_error_at (locus, "failed to locate crate %<%s%>", - crate_name.c_str ()); + import_name.c_str ()); return UNKNOWN_NODEID; } |