Skip to content

Commit 09af9b1

Browse files
bors[bot]mathstuf
andauthored
Merge #788
788: gccrs: add the `-frust-crate=` option to set the crate name r=philberty a=mathstuf Signed-off-by: Ben Boeckel <[email protected]> Fixes: #627 Co-authored-by: Ben Boeckel <[email protected]>
2 parents 9b46e47 + 2fc460a commit 09af9b1

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

gcc/rust/lang.opt

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ L
3434
Rust Joined Separate
3535
; Not documented
3636

37+
frust-crate=
38+
Rust Joined RejectNegative
39+
-frust-crate=<name> Set the crate name for the compilation
40+
3741
frust-debug
3842
Rust Var(flag_rust_debug)
3943
Dump various Rust front end internals.

gcc/rust/rust-session-manager.cc

+11-3
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ const char *kHIRDumpFile = "gccrs.hir.dump";
7070
const char *kHIRTypeResolutionDumpFile = "gccrs.type-resolution.dump";
7171
const char *kTargetOptionsDumpFile = "gccrs.target-options.dump";
7272

73-
// FIME in the imports/visibility milestone - this needs to be command line
74-
// option
7573
const std::string kDefaultCrateName = "TestCrate";
7674

7775
// Implicitly enable a target_feature (and recursively enable dependencies).
@@ -330,6 +328,9 @@ Session::init ()
330328
// setup backend to GCC GIMPLE
331329
backend = rust_get_backend ();
332330

331+
// set the default crate name
332+
options.set_crate_name (kDefaultCrateName);
333+
333334
// the constant folder uses gcc
334335
ConstFold::Context::init (backend);
335336
}
@@ -359,6 +360,13 @@ Session::handle_option (
359360
case OPT_L:
360361
// TODO: add library link path or something
361362
break;
363+
case OPT_frust_crate_:
364+
// set the crate name
365+
if (arg != nullptr)
366+
ret = options.set_crate_name (arg);
367+
else
368+
ret = false;
369+
break;
362370
case OPT_frust_dump_:
363371
// enable dump and return whether this was successful
364372
if (arg != nullptr)
@@ -451,7 +459,7 @@ void
451459
Session::parse_files (int num_files, const char **files)
452460
{
453461
auto mappings = Analysis::Mappings::get ();
454-
CrateNum crate_num = mappings->setup_crate_mappings (kDefaultCrateName);
462+
CrateNum crate_num = mappings->setup_crate_mappings (options.crate_name);
455463
mappings->set_current_crate (crate_num);
456464

457465
for (int i = 0; i < num_files; i++)

gcc/rust/rust-session-manager.h

+8
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ struct CompileOptions
180180
* whatever data related to target arch, features, os, family, env, endian,
181181
* pointer width, vendor */
182182
TargetOptions target_data;
183+
std::string crate_name;
183184
bool enable_test = false;
184185
bool debug_assertions = false;
185186
bool proc_macro = false;
@@ -203,6 +204,13 @@ struct CompileOptions
203204
enable_dump_option (DumpOption::HIR_DUMP);
204205
enable_dump_option (DumpOption::TYPE_RESOLUTION_DUMP);
205206
}
207+
208+
bool set_crate_name (std::string name)
209+
{
210+
// TODO: validate the crate name?
211+
crate_name = std::move (name);
212+
return true;
213+
}
206214
};
207215

208216
/* Defines a compiler session. This is for a single compiler invocation, so

0 commit comments

Comments
 (0)