[m-rev.] for review: add --mono-path-directory option

Julien Fischer jfischer at opturion.com
Tue Jul 22 22:06:14 AEST 2025


For review by anyone.

--------------------

Add --mono-path-directory option.

The launcher script we generate for the Mercury compiler in stage 1 does not
work since the CLR does not know where to find the assemblies for the standard
library, mdbcomp etc. This has not been an issue in the past, but it is now a
problem since the doc directory invokes the stage 1 compiler to generate
the invocation section of the user's guide.

If we are using the Mono CLR, then we can tell Mono where to find the library
assemblies by adding the appropriate directories to the value of the MONO_PATH
environment variable we set in the generated launcher script. This diff adds a
new command line option for doing that. Once it has bootstrapped, the
appropriate entries can be added to compiler/COMP_FLAGS.in.

compiler/options.m:
    Add the new option.

compiler/link_target_code.m:
    Include any search directories for Mono in the value of MONO_PATH
    set by the generated launcher script.

Julien.

diff --git a/compiler/link_target_code.m b/compiler/link_target_code.m
index de6513864..7ff11251b 100644
--- a/compiler/link_target_code.m
+++ b/compiler/link_target_code.m
@@ -1424,12 +1424,15 @@ construct_cli_shell_script_for_csharp(Globals,
ExeFileName, ContentStr) :-
     globals.lookup_string_option(Globals, cli_interpreter, CLI),
     globals.lookup_accumulating_option(Globals, link_library_directories,
         LinkLibraryDirectoriesList),
-    join_quoted_string_list(LinkLibraryDirectoriesList, "", "",
-        ":", LinkLibraryDirectories),
+    globals.lookup_accumulating_option(Globals, mono_path_directories,
+        MonoPathDirectoriesList),
+    AllSearchPaths = LinkLibraryDirectoriesList ++ MonoPathDirectoriesList,
+    join_quoted_string_list(AllSearchPaths, "", "",
+        ":", MonoPathDirectories),
     ContentStr = string.append_list([
         "#!/bin/sh\n",
         "DIR=${0%/*}\n",
-        "MONO_PATH=$MONO_PATH:", LinkLibraryDirectories, "\n",
+        "MONO_PATH=$MONO_PATH:", MonoPathDirectories, "\n",
         "export MONO_PATH\n",
         "CLI_INTERPRETER=${CLI_INTERPRETER:-", CLI, "}\n",
         "exec \"$CLI_INTERPRETER\" \"$DIR/", ExeFileName, "\" \"$@\"\n"
diff --git a/compiler/options.m b/compiler/options.m
index c48201714..56443d3cd 100644
--- a/compiler/options.m
+++ b/compiler/options.m
@@ -866,6 +866,7 @@
     ;       csharp_compiler_type
     ;       csharp_flags
     ;       quoted_csharp_flag
+    ;       mono_path_directories

 % Link options.
     % General link options.
@@ -4484,6 +4485,12 @@ optdb(oc_target_csharp, quoted_csharp_flag,
           string_special,
     arg_help("csharp-flag", "option", [
         w("Specify a single word option to be passed to the C# compiler."),
         w("The word will be quoted when passed to the shell.")])).
+optdb(oc_target_csharp, mono_path_directories,           accumulating([]),
+    alt_arg_help("mono-path-directory",
+        ["mono-path-dir"], "directory", [
+        w("Specify a directory to add to the runtime library assembly"),
+        w("search path passed to the Mono CLR using the"),
+        env("MONO_PATH"), w("environment variable.")])).

 %---------------------------------------------------------------------------%


More information about the reviews mailing list