maven-nar / nar-maven-plugin

Native ARchive plugin for Maven
https://maven-nar.github.io/
Apache License 2.0
231 stars 160 forks source link

MSVC: VS2019 is not recognized #367

Open zosrothko opened 3 years ago

zosrothko commented 3 years ago

Hi

The latest VS2019 version of MSVC is not recognized by maven-nar-plugin because the Register Key is not updated anymore by MSVC installation starting from VS2019. See there. Thus nar-maven-plugin should use now the vswhere.exe to locate MSVC tools as linker & compiler.

vindiagram commented 3 years ago

To add more to @zosrothko statement of the issue. VS 2019 does not set and "SOFTWARE\Microsoft\VisualStudio\SxS\VS7" registry keys nor does it set any "VS###COMNTOOLS" environment variables. The recommended approach from Microsoft is to use the vswhere.exe utility. This utility was added in VS 2017 and will always be installed to "C:\Program Files (x86)\Microsoft Visual Studio\Installer" no matter the configuration of VS 2017 or VS 2019 during installation.

Thus it should be simple to add a check for the tools existence and then perform its execution to locate the installations.

Example: "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -all -products Microsoft.VisualStudio.Product.BuildTools -format json -utf8

Produces [ { "instanceId": "7ac59f05", "installDate": "2021-01-13T14:09:11Z", "installationName": "VisualStudio/16.8.4+30907.101", "installationPath": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools", "installationVersion": "16.8.30907.101", "productId": "Microsoft.VisualStudio.Product.BuildTools", "productPath": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\Common7\\Tools\\LaunchDevCmd.bat", "state": 4294967295, "isComplete": true, "isLaunchable": true, "isPrerelease": false, "isRebootRequired": false, "displayName": "Visual Studio Build Tools 2019", "description": "The Visual Studio Build Tools allows you to build native and managed MSBuild-based applications without requiring the Visual Studio IDE. There are options to install the Visual C++ compilers and libraries, MFC, ATL, and C++/CLI support.", "channelId": "VisualStudio.16.Release", "channelUri": "https://aka.ms/vs/16/release/channel", "enginePath": "C:\\Program Files (x86)\\Microsoft Visual Studio\\Installer\\resources\\app\\ServiceHub\\Services\\Microsoft.VisualStudio.Setup.Service", "releaseNotes": "https://go.microsoft.com/fwlink/?LinkId=660893#16.8.4", "thirdPartyNotices": "https://go.microsoft.com/fwlink/?LinkId=660909", "updateDate": "2021-01-13T14:09:11.9659288Z", "catalog": { "buildBranch": "d16.8", "buildVersion": "16.8.30907.101", "id": "VisualStudio/16.8.4+30907.101", "localBuild": "build-lab", "manifestName": "VisualStudio", "manifestType": "installer", "productDisplayVersion": "16.8.4", "productLine": "Dev16", "productLineVersion": "2019", "productMilestone": "RTW", "productMilestoneIsPreRelease": "False", "productName": "Visual Studio", "productPatchVersion": "4", "productPreReleaseMilestoneSuffix": "1.0", "productSemanticVersion": "16.8.4+30907.101", "requiredEngineVersion": "2.8.3267.30329" }, "properties": { "campaignId": "", "channelManifestId": "VisualStudio.16.Release/16.8.4+30907.101", "nickname": "", "setupEngineFilePath": "C:\\Program Files (x86)\\Microsoft Visual Studio\\Installer\\vs_installershell.exe" } } ]

This json could be parsed for the list of installed VS version since 2010.

see properties: InstallationPath, InstallationVersion

mondain commented 3 years ago

I just tried this with 3.10.1 and locally built 3.10.2-SNAPSHOT, neither work with or without a passed in proper path to the tools ie. mvn clean package -P win -Dmsvc.toolpath="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29333/bin/Hostx64/x64"

Always failing on validate

[ERROR] Failed to execute goal com.github.maven-nar:nar-maven-plugin:3.10.2-SNAPSHOT:nar-validate (default-nar-validate) on project foo: Execution default-nar-validate of goal com.github.maven-nar:nar-maven-plugin:3.10.2-SNAPSHOT:nar-validate failed: The system cannot find the file specified.
mondain commented 3 years ago

I've got a working fix for this in my fork; I fixed it by using the environmental variables since VS no longer makes the previously used registry entries. https://github.com/mondain/nar-maven-plugin

nmwael commented 3 years ago

@mondain could you get your fix to working with the latest released nar in maven?

IE the "mvn clean package -P win -Dmsvc.toolpath="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29333/bin/Hostx64/x64" ?

nmwael commented 3 years ago

UPDATE: seems this changes something however it gives me a nullpointer.. `

com.github.maven-nar
        <artifactId>nar-maven-plugin</artifactId>
        <version>3.10.1</version>
        <extensions>true</extensions>
    <configuration>
     <linker>
     <name>mscv</name>
     <toolPath>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30037\bin\Hostx64\x64</toolPath>
     </linker>`

Caused by: java.lang.NullPointerException at com.github.maven_nar.Linker.getVersion (Linker.java:617)

Im probably missing some property

nmwael commented 3 years ago

Okay made a spelling mistake, linker name should be msvc.. this gives:

DEBUG] -- end configuration -- [DEBUG] linker original name: msvc [DEBUG] aol_linker: msvc [INFO] Using AOL: amd64-Windows-msvc [DEBUG] -- Searching for usable VisualStudio [DEBUG] Requested Linker version is "" [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 9.501 s [INFO] Finished at: 2021-08-05T12:54:25+02:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal com.github.maven-nar:nar-maven-plugin:3.10.1:nar-validate (default-nar-validate) on project it0015-cpp-executable: Execution default-nar-validate of goal com.github.maven-nar:nar-maven-plugin:3.10.1:nar-validate failed: The system cannot find the file specified. -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.github.maven-nar:nar-maven-plugin:3.10.1:nar-validate (default-nar-validate) on project it0015-cpp-executable: Execution default-nar-validate of goal com.github.maven-nar:nar-maven-plugin:3.10.1:nar-validate failed: The system cannot find the file specified. at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192) at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105) at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956) at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288) at org.apache.maven.cli.MavenCli.main (MavenCli.java:192) at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62) at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke (Method.java:566) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282) at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406) at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347) Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-nar-validate of goal com.github.maven-nar:nar-maven-plugin:3.10.1:nar-validate failed: The system cannot find the file specified. at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:148) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192) at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105) at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956) at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288) at org.apache.maven.cli.MavenCli.main (MavenCli.java:192) at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62) at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke (Method.java:566) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282) at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406) at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347) Caused by: com.sun.jna.platform.win32.Win32Exception: The system cannot find the file specified. at com.github.maven_nar.Msvc.visualStudioVS7SxS (Msvc.java:528) at com.github.maven_nar.Msvc.initVisualStudio (Msvc.java:577) at com.github.maven_nar.Msvc.init (Msvc.java:140) at com.github.maven_nar.AbstractNarMojo.getMsvc (AbstractNarMojo.java:331)

Which obviously are wrong, since version should be 16.. Looks like something are different in the current master branch of the nar plugin, maybe it has been fixed there?

nmwael commented 3 years ago

Okay so I just tried to use version 3.10.2-SNAPSHOT built from master and it seems to be working (I get an error but it looks to be from the actually cpp code)

I wonder when are 3.10.2-SNAPSHOT scheduled to be released

GregDomjan commented 3 years ago

@ctrueden do you have time to push the snapshot?

mondain commented 2 years ago

@nmwael @GregDomjan I've also had issues on newer Windows 10 systems if I've installed the VS 2019 build tools on top of VS 2019 itself; the paths get messed up etc, I've been able to resolve that by removing the build tools; not sure why MS even supports having both when one or the other isnt needed.

GregDomjan commented 2 years ago

@mondain haven't really had time to look into such a configuration of the system with the IDE and Build tools, think there is a similar assumption that you can only have either enterprise or professional and not both.

mondain commented 2 years ago

@GregDomjan @ctrueden did the plugin updates get pushed somewhere? Switching my pom when I have to build on windows systems still requires me to build the plugin itself to proceed; which is of course a PITA going on ~4 months now...

GregDomjan commented 2 years ago

@mondain Sorry no progress from my side, will look into it some more soon I hope