GNU bug report logs - #75939
bug in compile wrapper when using MSVC from Msys2

Previous Next

Package: automake;

Reported by: Kirill Makurin <maiddaisuki <at> outlook.com>

Date: Thu, 30 Jan 2025 04:59:02 UTC

Severity: normal

Done: Karl Berry <karl <at> freefriends.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Bruno Haible <bruno <at> clisp.org>
To: bug-gnulib <at> gnu.org
Cc: maiddaisuki <at> outlook.com, 75939 <at> debbugs.gnu.org, Karl Berry <karl <at> freefriends.org>
Subject: bug#75939: setting $MSYS2_ARG_CONV_EXCL in compile script?
Date: Sun, 02 Feb 2025 16:10:22 +0100
[Message part 1 (text/plain, inline)]
Karl Berry wrote:
> Kirill (cc'd) proposed setting the MSYS2_ARG_CONV_EXCL envvar in the
> compile script which comes from Automake, to avoid a double-conversion.
> See his report in the first msg here, and the final suggestion in the last:
> https://debbugs.gnu.org/cgi/bugreport.cgi?bug=75939
> 
> I don't know anything about this. I've never done any programming under
> Windows, or msys, cygwin, wine, or any other Unix emulator under Windows.
> 
> So I wanted to ask for advice before tinkering with something as basic
> as the compile script in this way. Especially since it currently does
> not set any environment variables.
> 
> So ... I'm hoping for feedback like "yeah sure", or "no, we should do
> xyz instead", or "the problem is actually abc", or something. Since no
> feedback was forthcoming on the automake list, I'm trying here.
> 
> And if we do apply it, then where? In this branch?
> 	cygwin/* | msys/*)
> 	  file=`cygpath -m "$file" || echo "$file"`
> 
> But I fear this will cause trouble on cygwin. But if we separate the
> branches, then it seems like other trouble could ensue. Setting it
> unconditionally in all cases seems unnecessarily global to me, though
> maybe that is the simplest.

Table of contents:
* Cygwin vs. MSYS2
* Nature of the MSYS2 problem
* General recommendation
* Specific proposal

* ========== Cygwin vs. MSYS2

MSYS2_ARG_CONV_EXCL is documented in
https://www.msys2.org/docs/filesystem-paths/#process-arguments
Quote:
  "When calling native executables from the context of [MSYS] then all the
   arguments that look like Unix paths will get auto converted to Windows."

Cygwin and MSYS2 both are development environments for native Windows
programs on Windows. Cygwin passes argv[] from the caller to the callee
unmodified; MSYS2 modifies it, at every program invocation, based on
heuristics.

On Cygwin, therefore, it is the programmer's responsibility to use
'cygpath -w' at the appropriate places. Fortunately, there is a Gnulib
macro, build-to-host.m4, that makes this easy.

* ========== Nature of the MSYS2 problem

The MSYS2 problem is that it's a horrible hack that is based on a
heuristic: all arguments that "look like Unix paths" are modified.

The user can set MSYS2_ARG_CONV_EXCL to avoid this from happening
in 1, 2, 3, or 10 places. But it will never be 100% correct.

* ========== General recommendation

My general advice is:
  1) Recommend Cygwin, not MSYS2. Like I do in
     <https://git.savannah.gnu.org/gitweb/?p=gettext.git;a=blob_plain;f=INSTALL.windows;hb=HEAD>
  2) Reduce the effort for GNU package upstream maintainers, by
     requesting a reasonably complete patch, not a piecemeal patch here
     and a piecemeal patch there.

* ========== Specific proposal

As for every bug report, the first action is to analyze the failure.
Here, the relevant lines of code in the 'compile' script are:

 	cygwin/* | msys/*)
 	  file=`cygpath -m "$file" || echo "$file"`

This is in function func_file_conv, which is used to produce arguments
for invocation of 'cl' (which is a native Windows program).

As documented in <https://cygwin.com/cygwin-ug-net/cygpath.html>,
"cygpath -m" produces file names like C:/Users/foobar/filename .
Some native Windows programs accept this syntax, some don't.
Therefore it is generally better to use "cygpath -w", which
produces file names like C:\Users\foobar\filename .
The *only* situation I've ever seen where "cygpath -m" is required
is when the callee is a shell script (with 'echo') that invokes
a Java program. (Example: IBM Application Server.)
Since the compiler called by 'compile' never is of this type, it is
better to use "cygpath -w".

Find attached a proposed patch. Tested on Cygwin with MSVC. Will work on
MSYS2 with MSVC as well.

Bruno
[0001-compile-Improve-support-for-C-compilations-on-MSYS2.patch (text/x-patch, attachment)]

This bug report was last modified 185 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.