Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Mercury repository line-ending policy.
#
# Default: treat all detected text files as text, normalize to LF in the
# index, and check out with LF in the working tree. This prevents Windows
# checkouts (with core.autocrlf=true) from injecting CRLF into shell
# scripts, .mgnuc_opts files, configure scripts, Mercury sources, etc.
# Shell-script-style consumers (e.g. scripts/mgnuc reading .mgnuc_opts)
# break when CRLF leaks in, so LF-everywhere is the safe default.
* text=auto eol=lf

# Binary files: skip all normalization.
*.png binary
*.jpg binary
*.jpeg binary
*.gif binary
*.ico binary
*.pdf binary
21 changes: 14 additions & 7 deletions Documentation/README.MS-VisualC.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ Mercury with Microsoft Visual C++
This file documents the port of Mercury to Windows that uses Microsoft Visual
C++ (MSVC) as a C compiler.

With MSVC, you can install a Mercury compiler that generates either x86
(32-bit) or x64 (64-bit) Windows native code in C grades, but not both.
(You can, of course, have multiple Mercury installations that use MSVC,
and have one that targets x86 and another that targets x64.)
With MSVC, you can install a Mercury compiler that generates x86 (32-bit),
x64 (64-bit), or ARM64 Windows native code in C grades, but only one per
installation. (You can, of course, have multiple Mercury installations that
use MSVC, each targeting a different architecture.)

Contents
--------
Expand Down Expand Up @@ -47,13 +47,20 @@ following:
Start Menu
└── Visual Studio 2022
├── x64 Native Tools Command Prompt for VS 2022
└── x86 Native Tools Command Prompt for VS 2022
├── x86 Native Tools Command Prompt for VS 2022
└── ARM64 Native Tools Command Prompt for VS 2022

Select x64 to target 64-bit Windows or x86 to target 32-bit Windows.
Select x64 to target 64-bit Windows, x86 to target 32-bit Windows, or
ARM64 to target Windows on ARM64.

If you prefer not to use the Start Menu shortcuts, then you can manually set
up the environment variables by running one of the batch files supplied with
Visual Studio (e.g. `vcvars32.bat` for x86, `vcvars64.bat` for x64).
Visual Studio (e.g. `vcvars32.bat` for x86, `vcvars64.bat` for x64,
`vcvarsarm64.bat` for ARM64).

To install the ARM64 port, your Visual Studio installation needs the
"MSVC v143 - VS 2022 C++ ARM64/ARM64EC build tools" individual component
(in addition to "Desktop development with C++").

2. Start the MSYS2 shell using this command:

Expand Down
20 changes: 20 additions & 0 deletions Documentation/README.MSYS2.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,26 @@ all other MSYS2 environments. A common problem is accidentally using the `MSYS`
compilers. This happens if you forgot to install the compiler package for your
specific environment (e.g. `UCRT64`).

### Readline Library

The Mercury debugger (`mdb`) links to GNU readline if `configure` detects it.
Because the `readline` package shipped in the `MSYS` environment is visible
on the `PATH` of every other MSYS2 environment, `configure` will detect a
copy that is not usable for linking from `UCRT64`, `MINGW64`, `MINGW32`,
`CLANG64` or `CLANGARM64`, and the build will then fail in
`mercury_trace_readline.c`. To avoid this, either install the readline
package matching your chosen environment via `pacman`, or pass
`--without-readline` to `configure`. For example, for `CLANGARM64`:

pacman -S mingw-w64-clang-aarch64-readline

The corresponding packages for the other environments are
`mingw-w64-clang-x86_64-readline` (`CLANG64`),
`mingw-w64-ucrt-x86_64-readline` (`UCRT64`),
`mingw-w64-x86_64-readline` (`MINGW64`),
`mingw-w64-i686-readline` (`MINGW32`),
and `readline` (`MSYS`).

### Documentation Packages

To build the Mercury documentation, you need the following packages:
Expand Down
5 changes: 3 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1954,8 +1954,9 @@ Changes to the Mercury implementation
Portability improvements
------------------------

* We now support using the 64-bit (i.e. x64) version of Microsoft Visual C++
as a C compiler with Mercury.
* We now support using the 64-bit (x64) and ARM64 versions of Microsoft Visual
C++ as a C compiler with Mercury, including building Mercury installations
targeting Windows on ARM64.
See [README.MS-VisualC.md](Documentation/README.MS-VisualC.md) for further
details.

Expand Down
2 changes: 1 addition & 1 deletion boehm_gc
Submodule boehm_gc updated 1 files
+7 −0 NT_MAKEFILE
1 change: 1 addition & 0 deletions compiler/check_options.m
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@
"clang",
"msvc_x86",
"msvc_x64",
"msvc_arm64",
"unknown"
],
CCTpec =
Expand Down
2 changes: 2 additions & 0 deletions compiler/compile_target_code.m
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@
% XXX Check whether we need to do anything for these C compilers?
( C_CompilerType = cc_cl_x86(_)
; C_CompilerType = cc_cl_x64(_)
; C_CompilerType = cc_cl_arm64(_)
),
C_FnAlignOpt = ""
;
Expand Down Expand Up @@ -496,6 +497,7 @@
;
( C_CompilerType = cc_cl_x86(_)
; C_CompilerType = cc_cl_x64(_)
; C_CompilerType = cc_cl_arm64(_)
),
globals.lookup_accumulating_option(Globals, msvc_flags, FlagsList)
;
Expand Down
11 changes: 11 additions & 0 deletions compiler/globals.m
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
; cc_clang(maybe(clang_version))
; cc_cl_x86(maybe(int)) % MSVC targeting x86.
; cc_cl_x64(maybe(int)) % MSVC targeting x86_64 (x64).
; cc_cl_arm64(maybe(int)) % MSVC targeting ARM64 (aarch64).
; cc_unknown.

:- type clang_version
Expand Down Expand Up @@ -682,6 +683,7 @@
convert_c_compiler_type_simple("msvc", cc_cl_x86(no)).
convert_c_compiler_type_simple("msvc_x86", cc_cl_x86(no)).
convert_c_compiler_type_simple("msvc_x64", cc_cl_x64(no)).
convert_c_compiler_type_simple("msvc_arm64", cc_cl_arm64(no)).
convert_c_compiler_type_simple("unknown", cc_unknown).

:- pred convert_c_compiler_type_with_version(string::in, c_compiler_type::out)
Expand All @@ -701,6 +703,8 @@
convert_msvc_x86_version(Version, C_CompilerType)
else if Tokens = ["msvc", "x64", Version] then
convert_msvc_x64_version(Version, C_CompilerType)
else if Tokens = ["msvc", "arm64", Version] then
convert_msvc_arm64_version(Version, C_CompilerType)
else
false
).
Expand Down Expand Up @@ -798,6 +802,13 @@
Version > 0,
C_CompilerType = cc_cl_x64(yes(Version)).

:- pred convert_msvc_arm64_version(string::in, c_compiler_type::out) is semidet.

convert_msvc_arm64_version(VersionStr, C_CompilerType) :-
string.to_int(VersionStr, Version),
Version > 0,
C_CompilerType = cc_cl_arm64(yes(Version)).

convert_csharp_compiler_type("microsoft", csharp_microsoft).
convert_csharp_compiler_type("mono", csharp_mono).
convert_csharp_compiler_type("unknown", csharp_unknown).
Expand Down
16 changes: 16 additions & 0 deletions compiler/link_target_code.m
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,7 @@
;
( C_CompilerType = cc_cl_x86(_)
; C_CompilerType = cc_cl_x64(_)
; C_CompilerType = cc_cl_arm64(_)
),
string.format("-stack:%d", [i(ReserveStackSize)], Flags)
)
Expand Down Expand Up @@ -959,6 +960,18 @@
],
join_string_list(RestrictedCmdLinkFlags, "", "", " ",
RestrictedCmdLinkOpts)
;
C_CompilerType = cc_cl_arm64(_),
RestrictedCmdLinkFlags = [
"-nologo",
"-ignore:4001",
"-subsystem:console",
"-machine:arm64",
"-entry:wmainCRTStartup",
"-defaultlib:libcmt"
],
join_string_list(RestrictedCmdLinkFlags, "", "", " ",
RestrictedCmdLinkOpts)
;
( C_CompilerType = cc_gcc(_, _, _)
; C_CompilerType = cc_clang(_)
Expand Down Expand Up @@ -1076,6 +1089,7 @@
(
( C_CompilerType = cc_cl_x86(_)
; C_CompilerType = cc_cl_x64(_)
; C_CompilerType = cc_cl_arm64(_)
),
( if LinkedTargetType = executable then
% NOTE: -Fe _must not_ be separated from its argument by any
Expand Down Expand Up @@ -1211,6 +1225,7 @@
% lib tool.
( C_CompilerType = cc_cl_x86(_)
; C_CompilerType = cc_cl_x64(_)
; C_CompilerType = cc_cl_arm64(_)
),
ArOutputSpace = ""
;
Expand Down Expand Up @@ -1674,6 +1689,7 @@
;
( CCompilerType = cc_cl_x86(_)
; CCompilerType = cc_cl_x64(_)
; CCompilerType = cc_cl_arm64(_)
),
LinkOpt = "",
LibSuffix = ".lib"
Expand Down
2 changes: 1 addition & 1 deletion compiler/options.m
Original file line number Diff line number Diff line change
Expand Up @@ -4573,7 +4573,7 @@
w("Specify which C compiler to use.")])).
optdb(oc_target_c, c_compiler_type, string("gcc"),
priv_arg_help("c-compiler-type",
"{gcc,clang,msvc_x86,msvc_x64,unknown}", [])).
"{gcc,clang,msvc_x86,msvc_x64,msvc_arm64,unknown}", [])).
% The `mmc' script will override the default with a value
% determined at configuration time for the above two options.
% XXX That argues for this option being oc_config.
Expand Down
3 changes: 2 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ case "$mercury_cv_cc_type" in
C_COMPILER_TYPE="gcc_${mercury_cv_gcc_version}"
;;

msvc_x86|msvc_x64)
msvc_x86|msvc_x64|msvc_arm64)
MERCURY_HAVE_MSVC=yes
MERCURY_MSVC_VERSION
C_COMPILER_TYPE="${mercury_cv_cc_type}_${mercury_cv_msvc_version}"
Expand All @@ -206,6 +206,7 @@ esac

case "$mercury_cv_cc_type" in
msvc_x64) BOEHM_WINDOWS_CPU_TYPE="x64" ;;
msvc_arm64) BOEHM_WINDOWS_CPU_TYPE="ARM64" ;;
*) BOEHM_WINDOWS_CPU_TYPE="x86" ;;
esac

Expand Down
2 changes: 2 additions & 0 deletions m4/mercury.m4
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,8 @@ int main(int argc, char **argv)
printf("msvc_x86");
#elif defined(_M_X64)
printf("msvc_x64");
#elif defined(_M_ARM64)
printf("msvc_arm64");
#else
printf("unknown");
#endif
Expand Down
2 changes: 1 addition & 1 deletion tests/warnings/help_text.err_exp
Original file line number Diff line number Diff line change
Expand Up @@ -2650,7 +2650,7 @@ Options for target language compilation
Specify which C compiler to use.

PRIVATE OPTION
--c-compiler-type {gcc,clang,msvc_x86,msvc_x64,unknown}
--c-compiler-type {gcc,clang,msvc_x86,msvc_x64,msvc_arm64,unknown}
There is no help text available.

--c-optimize
Expand Down