]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: cli: Add frust-extern option
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Tue, 18 Apr 2023 15:26:07 +0000 (17:26 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:34:15 +0000 (18:34 +0100)
Add a new option to gather extern crates location.

gcc/rust/ChangeLog:

* lang.opt: Add frust-extern option.
* rust-session-manager.cc (Session::handle_extern_option): Add
frust-extern option handler.
* rust-session-manager.h (struct Session): Add an unordered map
to store library name and locations.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/rust/lang.opt
gcc/rust/rust-session-manager.cc
gcc/rust/rust-session-manager.h

index 3a5981e4c852e8c2d88db09ef1742bbdf7244db9..4a6a011c6603c3d6b2313aa91ddee1b8ab9f3c18 100644 (file)
@@ -62,6 +62,10 @@ frust-crate=
 Rust Joined RejectNegative
 -frust-crate=<name>             Set the crate name for the compilation
 
+frust-extern=
+Rust RejectNegative Joined
+-frust-extern=              Specify where an external library is located
+
 frust-debug
 Rust Var(flag_rust_debug)
 Dump various Rust front end internals.
index c8d7b29229ca32a8268167d8eac0d84aba6aa9fe..fadb8fb434f431d85cfe06110f84ea7e585d8c4c 100644 (file)
@@ -190,6 +190,11 @@ Session::handle_option (
       }
       break;
 
+      case OPT_frust_extern_: {
+       std::string input (arg);
+       ret = handle_extern_option (input);
+      }
+      break;
     case OPT_frust_crate_:
       // set the crate name
       if (arg != nullptr)
@@ -249,6 +254,20 @@ Session::handle_option (
   return ret;
 }
 
+bool
+Session::handle_extern_option (std::string &input)
+{
+  auto pos = input.find ('=');
+  if (std::string::npos == pos)
+    return false;
+
+  std::string libname = input.substr (0, pos);
+  std::string path = input.substr (pos + 1);
+
+  extern_crates.insert ({libname, path});
+  return true;
+}
+
 bool
 Session::handle_cfg_option (std::string &input)
 {
index 910f097e0be4499020653c83ca20f093244a8cdc..7d8b14e57669d2a53199948390e5d007965ee617 100644 (file)
@@ -288,6 +288,7 @@ struct Session
   /* This should really be in a per-crate storage area but it is wiped with
    * every file so eh. */
   std::string injected_crate_name;
+  std::map<std::string, std::string> extern_crates;
 
   /* extra files get included during late stages of compilation (e.g. macro
    * expansion) */
@@ -366,6 +367,8 @@ private:
 
   // handle cfg_option
   bool handle_cfg_option (std::string &data);
+
+  bool handle_extern_option (std::string &data);
 };
 
 } // namespace Rust