Skip to content

Commit

Permalink
Also build on windows (java-native-access#166)
Browse files Browse the repository at this point in the history
Motivation:

We should also build on windows our native bits.

Modifications:

- Add jobs to build on windows
- Adjust build config to support windows

Result:

Verify we can build on windows
  • Loading branch information
normanmaurer authored Feb 2, 2021
1 parent 940c2b2 commit e79636e
Show file tree
Hide file tree
Showing 6 changed files with 233 additions and 22 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ on:
jobs:
build-linux-x86_64:
runs-on: ubuntu-latest
name: linux-x86_64
steps:
- uses: actions/checkout@v2

Expand All @@ -38,3 +39,44 @@ jobs:
with:
name: target
path: "**/target/"

build-windows:
runs-on: windows-2016
name: windows-x86_64
steps:
- uses: actions/checkout@v2

- name: Set up JDK 8
uses: actions/setup-java@v1
with:
java-version: 8

- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: x86_64-pc-windows-msvc
override: true

- name: Add msbuild to PATH
uses: microsoft/[email protected]

- name: Configuring Developer Command Prompt
uses: ilammy/msvc-dev-cmd@v1
with:
arch: x86_amd64

- name: Install tools
uses: crazy-max/ghaction-chocolatey@v1
with:
args: install ninja nasm

- name: Build project
run: mvn --file pom.xml clean package

- uses: actions/upload-artifact@v2
if: ${{ failure() }}
with:
name: build-windows-target
path: "**/target/"
42 changes: 42 additions & 0 deletions .github/workflows/ci-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
jobs:
build-linux-x86_64:
runs-on: ubuntu-latest
name: linux-x86_64
steps:
- uses: actions/checkout@v2

Expand Down Expand Up @@ -38,3 +39,44 @@ jobs:
with:
name: target
path: "**/target/"

build-pr-windows:
runs-on: windows-2016
name: windows-x86_64
steps:
- uses: actions/checkout@v2

- name: Set up JDK 8
uses: actions/setup-java@v1
with:
java-version: 8

- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: x86_64-pc-windows-msvc
override: true

- name: Add msbuild to PATH
uses: microsoft/[email protected]

- name: Configuring Developer Command Prompt
uses: ilammy/msvc-dev-cmd@v1
with:
arch: x86_amd64

- name: Install tools
uses: crazy-max/ghaction-chocolatey@v1
with:
args: install ninja nasm

- name: Build project
run: mvn --file pom.xml clean package

- uses: actions/upload-artifact@v2
if: ${{ failure() }}
with:
name: build-pr-windows-target
path: "**/target/"
139 changes: 120 additions & 19 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<properties>
<javaModuleName>io.netty.incubator.codec.quic</javaModuleName>
<nativeSourceDirectory>${project.basedir}/src/main/c</nativeSourceDirectory>
<nativeLibOnlyDir>${project.build.directory}/native-lib-only</nativeLibOnlyDir>
<skipTests>false</skipTests>
<netty.version>4.1.59.Final-SNAPSHOT</netty.version>
<netty.build.version>28</netty.build.version>
Expand All @@ -93,6 +94,7 @@
<quicheBranch>master</quicheBranch>
<quicheCommitSha>5092e4d1e8ae2773a56eddda6a8205f5e65b4b37</quicheCommitSha>
<generatedSourcesDir>${project.build.directory}/generated-sources</generatedSourcesDir>
<templateDir>${project.build.directory}/template</templateDir>
<cargoTarget/>
<cflags>-std=c99 -Werror -fno-omit-frame-pointer -fvisibility=hidden -Wunused -Wno-unused-value -O3 -I${quicheHomeIncludeDir} -I${boringsslHomeIncludeDir}</cflags>
<ldflags>-L${quicheHomeBuildDir} -lquiche -L${boringsslHomeBuildDir} -lssl -lcrypto</ldflags>
Expand All @@ -109,6 +111,29 @@
<bundleNativeCode />
</properties>
<profiles>
<profile>
<id>windows</id>
<activation>
<os>
<family>windows</family>
</os>
</activation>
<properties>
<boringsslHomeBuildDir>${boringsslHomeDir}/build/RelWithDebInfo</boringsslHomeBuildDir>
<quicheTarget>x86_64-pc-windows-msvc</quicheTarget>
<cargoTarget>--target=${quicheTarget}</cargoTarget>
<quicheBuildDir>${quicheSourceDir}/target/${quicheTarget}/release</quicheBuildDir>
<cmakeAsmFlags/>
<!-- On Windows, build with /MT for static linking -->
<cmakeCFlags>/MT</cmakeCFlags>
<!-- Disable one warning to be able to build on windows -->
<cmakeCxxFlags>/MT /wd4091</cmakeCxxFlags>
<libssl>ssl.lib</libssl>
<libcrypto>crypto.lib</libcrypto>
<libquiche>quiche.lib</libquiche>
<bundleNativeCode>META-INF/native/${jniLibName}.dll;osname=win32;processor=${os.detected.arch}</bundleNativeCode>
</properties>
</profile>
<profile>
<id>mac</id>
<activation>
Expand Down Expand Up @@ -368,17 +393,33 @@
</else>
</if>
<echo message="Building Quiche" />

<exec executable="cargo" failonerror="true" dir="${quicheSourceDir}" resolveexecutable="true">
<arg value="build" />
<arg value="--features" />
<arg value="ffi" />
<arg value="--release" />
<env key="CFLAGS" value="${extraCflags}" />
<env key="CXXFLAGS" value="${extraCxxflags}" />
<env key="QUICHE_BSSL_PATH" value="${boringsslHomeDir}/"/>
</exec>

<if>
<equals arg1="${os.detected.name}" arg2="windows" />
<then>
<exec executable="cargo" failonerror="true" dir="${quicheSourceDir}" resolveexecutable="true">
<arg value="build" />
<arg value="--features" />
<arg value="ffi" />
<arg value="--release" />
<arg value="${cargoTarget}" />
<!-- See https://github.com/cloudflare/quiche/blob/0.7.0/src/build.rs#L73 -->
<env key="DEBUG" value="true" />
<env key="OPT_LEVEL" value="3" />
<env key="QUICHE_BSSL_PATH" value="${boringsslHomeDir}/"/>
</exec>
</then>
<else>
<exec executable="cargo" failonerror="true" dir="${quicheSourceDir}" resolveexecutable="true">
<arg value="build" />
<arg value="--features" />
<arg value="ffi" />
<arg value="--release" />
<env key="CFLAGS" value="${extraCflags}" />
<env key="CXXFLAGS" value="${extraCxxflags}" />
<env key="QUICHE_BSSL_PATH" value="${boringsslHomeDir}/"/>
</exec>
</else>
</if>
<!-- Only copy the libs and header files we need -->
<mkdir dir="${quicheHomeDir}" />
<copy file="${quicheBuildDir}/${libquiche}" todir="${quicheHomeBuildDir}/" />
Expand Down Expand Up @@ -410,6 +451,66 @@
</target>
</configuration>
</execution>

<execution>
<!-- Adjust our template and copy it over so it can be used when compiling on windows -->
<id>setup-template</id>
<phase>generate-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<!-- Add the ant tasks from ant-contrib -->
<taskdef resource="net/sf/antcontrib/antcontrib.properties" />
<property environment="env" />
<!-- Convert the paths to windows format -->
<pathconvert property="boringsslHomeIncludeWindowsDir" targetos="windows">
<path location="${boringsslHomeIncludeDir}" />
</pathconvert>
<pathconvert property="quicheHomeIncludeWindowsDir" targetos="windows">
<path location="${quicheHomeIncludeDir}" />
</pathconvert>
<pathconvert property="boringsslHomeBuildWindowsDir" targetos="windows">
<path location="${boringsslHomeBuildDir}" />
</pathconvert>
<pathconvert property="quicheHomeBuildWindowsDir" targetos="windows">
<path location="${quicheHomeBuildDir}" />
</pathconvert>

<!-- Copy and filter the template MSVC project -->
<filter token="BORINGSSL_INCLUDE_DIR" value="${boringsslHomeIncludeWindowsDir}" />
<filter token="QUICHE_INCLUDE_DIR" value="${quicheHomeIncludeWindowsDir}" />
<filter token="BORINGSSL_LIB_DIR" value="${boringsslHomeBuildWindowsDir}" />
<filter token="QUICHE_LIB_DIR" value="${quicheHomeBuildWindowsDir}" />
<filter token="QUICHE_LIB" value="${libquiche}" />
<filter token="CRYPTO_LIB" value="${libcrypto}" />
<filter token="SSL_LIB" value="${libssl}" />

<copy file="src/main/native-package/vs2010.custom.props.template" tofile="${templateDir}/vs2010.custom.props" filtering="true" overwrite="true" verbose="true" />
</target>
</configuration>
</execution>

<!-- Copy the native lib that was generated. -->
<execution>
<id>copy-native-lib</id>
<phase>process-test-resources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<!-- Add the ant tasks from ant-contrib -->
<taskdef resource="net/sf/antcontrib/antcontrib.properties" />

<copy todir="${project.build.outputDirectory}" includeEmptyDirs="false">
<zipfileset dir="${nativeLibOnlyDir}/META-INF/native" />
<regexpmapper handledirsep="yes" from="^(?:[^/]+/)*([^/]+)$" to="META-INF/native/\1" />
</copy>
</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
Expand Down Expand Up @@ -612,20 +713,19 @@
</plugin>
<plugin>
<groupId>org.fusesource.hawtjni</groupId>
<artifactId>maven-hawtjni-plugin</artifactId>
<version>1.14</version>
<artifactId>hawtjni-maven-plugin</artifactId>
<version>1.18</version>
<executions>
<execution>
<id>build-native-lib</id>
<configuration>
<name>${jniLibName}</name>
<nativeSourceDirectory>${generatedSourcesDir}</nativeSourceDirectory>
<libDirectory>${project.build.outputDirectory}</libDirectory>
<!-- We use Maven's artifact classifier instead.
This hack will make the hawtjni plugin to put the native library
under 'META-INF/native' rather than 'META-INF/native/${platform}'. -->
<platform>.</platform>
<verbose>true</verbose>
<customPackageDirectory>${templateDir}</customPackageDirectory>
<windowsBuildTool>msbuild</windowsBuildTool>
<windowsCustomProps>true</windowsCustomProps>
<windowsPlatformToolset>v140</windowsPlatformToolset>
<libDirectory>${nativeLibOnlyDir}</libDirectory>
<configureArgs>
<configureArg>${extraConfigureArg}</configureArg>
<configureArg>CFLAGS=${cflags}</configureArg>
Expand All @@ -647,6 +747,7 @@
<execution>
<id>default-jar</id>
<configuration>
<!-- Exclude native lib -->
<excludes>
<exclude>META-INF/native/**</exclude>
</excludes>
Expand Down
2 changes: 1 addition & 1 deletion src/main/c/netty_quic_boringssl.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@

// JNI initialization hooks. Users of this file are responsible for calling these in the JNI_OnLoad and JNI_OnUnload methods.
jint netty_boringssl_JNI_OnLoad(JNIEnv* env, const char* packagePrefix);
void netty_boringssl_JNI_OnUnLoad(JNIEnv* env, const char* packagePrefix);
void netty_boringssl_JNI_OnUnload(JNIEnv* env, const char* packagePrefix);

#endif /* NETTY_BORINGSSL_H_ */
4 changes: 2 additions & 2 deletions src/main/c/netty_quic_quiche.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ static jint netty_quiche_JNI_OnLoad(JNIEnv* env, const char* packagePrefix) {
netty_jni_util_unregister_natives(env, packagePrefix, QUICHE_CLASSNAME);
}
if (boringsslLoaded == 1) {
netty_boringssl_JNI_OnUnLoad(env, packagePrefix);
netty_boringssl_JNI_OnUnload(env, packagePrefix);
}

NETTY_JNI_UTIL_UNLOAD_CLASS(env, quiche_logger_class);
Expand All @@ -591,7 +591,7 @@ static jint netty_quiche_JNI_OnLoad(JNIEnv* env, const char* packagePrefix) {
}

static void netty_quiche_JNI_OnUnload(JNIEnv* env, const char* packagePrefix) {
netty_boringssl_JNI_OnUnLoad(env, packagePrefix);
netty_boringssl_JNI_OnUnload(env, packagePrefix);

NETTY_JNI_UTIL_UNLOAD_CLASS(env, quiche_logger_class);

Expand Down
26 changes: 26 additions & 0 deletions src/main/native-package/vs2010.custom.props.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2021 The Netty Project
~
~ The Netty Project licenses this file to you under the Apache License,
~ version 2.0 (the "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at:
~
~ https://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
~ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
~ License for the specific language governing permissions and limitations
~ under the License.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>$(JAVA_HOME)\include;$(JAVA_HOME)\include\win32;@BORINGSSL_INCLUDE_DIR@;@QUICHE_INCLUDE_DIR@;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<AdditionalDependencies>ws2_32.lib;crypt32.lib;userenv.lib;@BORINGSSL_LIB_DIR@\@SSL_LIB@;@BORINGSSL_LIB_DIR@\@CRYPTO_LIB@;@QUICHE_LIB_DIR@\@QUICHE_LIB@;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
</Project>

0 comments on commit e79636e

Please sign in to comment.