xmake-io / xmake

🔥 A cross-platform build utility based on Lua
https://xmake.io
Apache License 2.0
10.04k stars 785 forks source link

Windows MSVC: Platform switching to msys/x64 after errors #946

Closed paul-reilly closed 4 years ago

paul-reilly commented 4 years ago

Windows 10. MSVC, windows platform.

When some errors occur, I notice that the xmake platform has been switched to msys/x64 from windows when the next command is run.

There is a repro in #943, but it's not minimal. I'll update this issue if/when I can get a more direct example.

waruqi commented 4 years ago

msys/x64? It should be msys/x86_64

Please let me see the error output. Or you can add -vD arguments to get verbose output.

paul-reilly commented 4 years ago

The output from when I got it in #943 was:

➜  luasocket-test xmake
checking for the architecture ... x64
note: the following packages are unsupported for msys/x64!
  -> luasocket 3.0-rc1

This was after the error described in that report for the case issue with the checksum:

error: unmatched checksum!
waruqi commented 4 years ago

If you are running xmake under the msys2 environment, the default compilation platform is msys instead of windows. Many packages in xmake-repo do not support the msys platform for the time being.

You can manually switch to the windows platform and use msvc to compile it.

xmake f -p windows -c
xmake

Or you can run xmake on cmd/ps terminal. The default platform for these environments is windows/msvc.

paul-reilly commented 4 years ago

Thanks for getting back so soon. Just to confirm, I am running xmake from a Developer Command Prompt running Powershell in Windows Terminal and am exclusively using the windows target. I have an MSYS2 environment installed, but it is not in my PATH.

I noticed this bug when running Visual Studio Code as well, again using windows platform and being launched from a Dev Command Prompt. I don't know what error triggered it there.

waruqi commented 4 years ago

It will read $MSYSTEM to detect msys envirnoment.

https://github.com/xmake-io/xmake/blob/02433ff768af0842de49d3901df973c57bb43a5a/core/src/xmake/engine.c#L680-L688

echo $MSYSTEM
paul-reilly commented 4 years ago

I have a -Dv console log for you to see. I delete the .xmake dir and start fresh, then run xmake require which shows msys and x64 as the default options:

➜  luasocket-test ls

    Directory: C:\dev\xmake-packages\luasocket-test

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        11/09/2020     03:30                .vscode
d-----        11/09/2020     17:36                src
d-----        11/09/2020     00:53                testrepo
-a----        08/09/2020     15:34             56 .gitignore
-a----        11/09/2020     17:36            624 compile_commands.json
-a----        11/09/2020     20:41           2221 xmake.lua

➜  luasocket-test xmake require -Dv
checking for the architecture ... x64
checking for the gcc ... no
checking for the clang ... ok
configure
{
    arch = x64
    debugger = windbx  
    proxy_pac = pac.lua
    clean = true       
    ndk_stdcxx = true  
    plat = msys        
    mode = release     
    host = windows     
    kind = static      
    buildir = build    
    theme = default    
    ccache = true      
}
checking for the unzip ... ok
checking for the git ... ok
checking for the gzip ... no
checking for the 7z ... ok
checking for the ping ... ok
pinging for the host(gitlab.com) ... 13 ms
pinging for the host(github.com) ... 28 ms
pinging for the host(gitee.com) ... 276 ms
updating repositories .. 
cloning repository(custom-repo): https://github.com/paul-reilly/xmake-repo.git to C:\dev\xmake-packages\luasocket-test\.xmake\windows\x64\repositories\custom-repo ..
git clone https://github.com/paul-reilly/xmake-repo.git -b dev C:\dev\xmake-packages\luasocket-test\.xmake\windows\x64\repositories\custom-repo
Cloning into 'C:\dev\xmake-packages\luasocket-test\.xmake\windows\x64\repositories\custom-repo'...
remote: Enumerating objects: 26, done.
remote: Counting objects: 100% (26/26), done.
remote: Compressing objects: 100% (18/18), done.
Receiving objects:  99% (3733/3770)ed 21 (delta 5), pack-reused 3744
Receiving objects: 100% (3770/3770), 626.62 KiB | 2.29 MiB/s, done.
Resolving deltas: 100% (1955/1955), done.
pulling repository(xmake-repo): https://gitlab.com/tboox/xmake-repo.git to C:\Users\paul-\AppData\Local\.xmake\repositories\xmake-repo ..
git pull origin master
From https://gitlab.com/tboox/xmake-repo
 * branch            master     -> FETCH_HEAD
Already up to date.
ok
luasocket - in on_load
finding luajit-devpackage from xmake ..
checking for the xmake::luajit-devpackage ... no
finding luajit-devpackage from vcpkg ..
checking for the vcpkg directory ... C:\dev\tools\vcpkg
finding luajit-devpackage from conan ..
finding luajit-devpackage from pkg_config ..
checking for the pkg-config ... no
finding luajit-devpackage from system ..
checking for the luajit-devpackage ... no
finding luajit from xmake ..
checking for the xmake::luajit ... no
finding luajit from vcpkg ..
finding luajit from conan ..
finding luajit from pkg_config ..
finding luajit from system ..
checking for the luajit ... no
finding luasocket from xmake ..
checking for the xmake::luasocket ... no
finding luasocket from vcpkg ..
finding luasocket from conan ..
finding luasocket from pkg_config ..
finding luasocket from system ..
checking for the luasocket ... no
note: the following packages are unsupported for msys/x64!
  -> luajit-devpackage 2.1.0-beta3
  -> luajit 2.1.0-beta3
  -> luasocket 3.0-rc1
error: @programdir\core\main.lua:284: stack traceback:
    [C]: in function 'error'
    [@programdir\core\base\os.lua:803]: in function 'raise'
    [@programdir\actions\require\impl\package.lua:788]: in function 'install_packages'
    [@programdir\actions\require\install.lua:162]: in function 'install'
    [@programdir\actions\require\main.lua:111]:
    [C]: in function 'load'
    [@programdir\core\base\task.lua:520]: in function 'run'
    [@programdir\core\main.lua:282]: in function 'cotask'
    [@programdir\core\base\scheduler.lua:317]:

stack traceback:
        [C]: in function 'error'
        @programdir\core\base\os.lua:792: in function 'raise'
        @programdir\core\main.lua:284: in function 'cotask'
        @programdir\core\base\scheduler.lua:317: in function <@programdir\core\base\scheduler.lua:315>
➜  luasocket-test 
waruqi commented 4 years ago

please run echo $MSYSTEM and let me see the output result.

paul-reilly commented 4 years ago

In Dev Command Prompt I am using, the result is nothing and MSYS2/mingw64 is not in the path (g++ not run):

➜  dev echo $MSYSTEM
➜  dev echo $env:MSYSTEM
➜  dev g++
g++ : The term 'g++' is not recognized.....

In MSYS2/mingw64:

mingw64>:~$ echo $MSYSTEM
MINGW64
paul-reilly commented 4 years ago

I do have clang available on the command line and that is what xmake is finding and using as a compiler when this happens.

waruqi commented 4 years ago

I noticed this bug when running Visual Studio Code as well, again using windows platform and being launched from a Dev Command Prompt. I don't know what error triggered it there.

note: the following packages are unsupported for msys/x64!

Here xmake detects the msys environment by mistake, only the $MSYSTEM environment variable is set, can it be detected as msys2

https://github.com/xmake-io/xmake/blob/02433ff768af0842de49d3901df973c57bb43a5a/core/src/xmake/engine.c#L674-L689

you can run xmake l os.subhost and let me see the result.

If it is not in the msys operating environment, the result should be windows.

paul-reilly commented 4 years ago

This is strange, running xmake l os.subhost and checking $MSYSTEM in...

Dev Command Prompt, Powershell

➜  iPlug2 git:(master) ✗ xmake l os.subhost
"windows"
➜  iPlug2 git:(master) ✗ $env:MSYSTEM
➜  iPlug2 git:(master) ✗

Visual Studio Code Terminal (launched from Dev Command Prompt)

➜  iPlug2 git:(master) ✗ xmake l os.subhost
"msys"
➜  iPlug2 git:(master) ✗ $env:MSYSTEM      
MINGW64

It seems that the issue is somewhere in Visual Studio Code or the xmake extension. I switch between command line and VS Code, which explains the different behaviour.

waruqi commented 4 years ago

It seems that the issue is somewhere in Visual Studio Code or the xmake extension. I switch between command line and VS Code, which explains the different behaviour.

the xmake extension will not set any environment variables

Visual Studio Code Terminal (launched from Dev Command Prompt)

Why did it set $MSYSTEM, because the msys2 shell was loaded?

paul-reilly commented 4 years ago

Why did it set $MSYSTEM, because the msys2 shell was loaded?

No, it's very strange. I don't have a MSYS2 shell set up at all in VS Code, it's running a Windows terminal and Powershell. Here's a screenshot. I created a new project xmake create -l c++ -t console testtest and opened it in VS Code...

vscode-snippet

The xmake extension has no settings fields changed.

paul-reilly commented 4 years ago

Oh crap. I found this in the VS Code Terminal settings:

"terminal.integrated.env.windows":
    {
        "MSYSTEM": "MINGW64",
        //"MSYS2_PATH_TYPE": "inherit",
        "MSVSCODE": "1"
    }

Which I assume must have been me at some point in the past, but I have no memory of it.

Sorry for the hassle and thanks very much for the help!