Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toolPathWindowsSDK wrongly forced when SDK is 8.1 and UCRT is 10.* (proposal) #343

Open
AlainCo opened this issue Jun 6, 2019 · 0 comments

Comments

@AlainCo
Copy link

AlainCo commented Jun 6, 2019

Hi,
I'm new to NAR plugin, just wanting to compile a JNI dll for jMTPe with maven...
I finally could compile 32 and 64 bits without using all variable of vcvars34/64...
I work with VC14.0 x86 community, installed standard-way on Win10 amd64
latest problem was that
toolPathWindowsSDK property in msvc was replaced by a wrong guess using windowsSdkHome in com.github.maven_nar.Msvc.addWindowsSDKPaths()
the result was that "mt.exe" was called but not found in the path.

I patched locally this method, just to do the toolPathWindowsSDK=new File(windowsSdkHome,...) only if toolPathWindowsSDK is null or empty

The plugin in the pom is configured through few of the usual VC14.0 variables, and I had only to set the cited environment variables in windows, no path, no lib, no include... It uses the x86 tool chain to cross generate amd64 and x86 binaries, and runs OK on my 64bit windows (should work on 32bits).

I'm new, so maybe I did mistake, so feel free to explain me.

Here is the POM extract

<plugin>
    <groupId>com.github.maven-nar</groupId>
    <artifactId>nar-maven-plugin</artifactId>
    <version>3.8.1-SNAPSHOT</version>
    <extensions>true</extensions>
    <configuration>
        <ignore>false</ignore>
        <os>Windows</os>
        <cpp>
            <name>msvc</name>
            <includes>
                <include>**/*.cpp</include>
            </includes>
            <exceptions>true</exceptions>
            <debug>false</debug>
            <sourceDirectory>${basedir}/src/main/c++</sourceDirectory>
            <systemIncludePaths>
                <systemIncludePath>${JAVA_HOME}/include</systemIncludePath>
                <systemIncludePath>${JAVA_HOME}/include/win32</systemIncludePath>
            </systemIncludePaths>
            <includePaths>
                <includePath>${basedir}/src/main/include</includePath>
            </includePaths>
            <defines>
                <define>UNICODE</define>
                <define>_UNICODE</define>
            </defines>
        </cpp>
        <linker>
            <name>msvc</name>
            <sysLibs>
                <sysLib>
                    <name>PortableDeviceGuids</name>
                </sysLib>
            </sysLibs>
        </linker>
        <libraries>
            <library>
                <type>jni</type>
                <narSystemPackage>jmtp</narSystemPackage>
                <linkCPP>false</linkCPP>
            </library>
        </libraries>
        <msvc>
           <home>${VSINSTALLDIR}</home>
            <msvctoolhome>${VCINSTALLDIR}</msvctoolhome>
            <version>${VISUALSTUDIOVERSION}</version>
            <toolPathLinker>${VCINSTALLDIR}\bin</toolPathLinker>
            <windowsSdkVersion>8.1</windowsSdkVersion>
            <windowsSdkHome>${UNIVERSALCRTSDKDIR}</windowsSdkHome>
            <toolPathWindowsSDK>${WINDOWSSDKDIR}bin\x86</toolPathWindowsSDK>
            <sdkIncludes>
                <sdkInclude>${UNIVERSALCRTSDKDIR}include\${UCRTVERSION}\ucrt</sdkInclude>
            </sdkIncludes>
            <sdkLibs>
                <sdkLib>${UNIVERSALCRTSDKDIR}lib\${UCRTVERSION}\ucrt</sdkLib>
            </sdkLibs>
        </msvc>
    </configuration>
    <executions>
        <execution>
            <id>compile-DLL32</id>
            <phase>compile</phase>
            <goals>
                <goal>nar-compile</goal>
            </goals>
            <configuration>
                <architecture>x86</architecture>
                <cpp>
                    <toolPath>${VCINSTALLDIR}\bin</toolPath>
                </cpp>
                <linker>
                    <toolPath>${VCINSTALLDIR}\bin</toolPath>
                </linker>
            </configuration>
        </execution>
        <execution>
            <id>compile-DLL64</id>
            <phase>compile</phase>
            <goals>
                <goal>nar-compile</goal>
            </goals>
            <configuration>
                <architecture>amd64</architecture>
                <cpp>
                    <toolPath>${VCINSTALLDIR}\bin\x86_amd64</toolPath>
                </cpp>
                <linker>
                    <toolPath>${VCINSTALLDIR}\bin\x86_amd64</toolPath>
                </linker>
            </configuration>
        </execution>
    </executions>
</plugin>

The code I edited is in method com.github.maven_nar.Msvc.addWindowsSDKPaths(), only an if() is added :

if(toolPathWindowsSDK==null||toolPathWindowsSDK.trim().isEmpty()) {
        if ("amd64".equals(mojoArchitecture)) {
            toolPathWindowsSDK = new File(windowsSdkHome, "bin/"+versionPart+"x64").getAbsolutePath();
        } else if (compareVersion(windowsSdkVersion, "7.1A") <= 0) {
            toolPathWindowsSDK = new File(windowsSdkHome, "bin").getAbsolutePath();
        } else {
            toolPathWindowsSDK = new File(windowsSdkHome, "bin/"+versionPart+"x86").getAbsolutePath();
        }
    }

for the variables I have set:

JAVA_HOME=C:\Developpement\JDK1.8_x64
UCRTVERSION=10.0.10240.0
UNIVERSALCRTSDKDIR=C:\Program Files (x86)\Windows Kits\10\
VCINSTALLDIR=C:\Developpement\vstudio\vs2015\VC\
VISUALSSTUDIOVERSION=14.0
VSINSTALLDIR=C:\Developpement\vstudio\vs2015\
WINDOWSSDKDIR=C:\Program Files (x86)\Windows Kits\8.1\

maybe there is a problem between 8.1 SDK and 10.0 UCRT, but I did not install Windows 10 SDK as it is said not compatible with VC14.0.

I hope this helps...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant