You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by sh...@apache.org on 2022/06/02 15:05:28 UTC

[bookkeeper] branch master updated: [build] Support windows build (#3303)

This is an automated email from the ASF dual-hosted git repository.

shoothzj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git


The following commit(s) were added to refs/heads/master by this push:
     new 1d93ff7083 [build] Support windows build (#3303)
1d93ff7083 is described below

commit 1d93ff708318cdcb1b477f416cbebed19e220d1b
Author: ZhangJian He <sh...@gmail.com>
AuthorDate: Thu Jun 2 23:05:22 2022 +0800

    [build] Support windows build (#3303)
    
    ### Motivation
    Support windows build to let more people easily contributed in this project. Test on my windows10 and windows11 PC.
    I think that Windows now can be used for development, but not for production.
    ### Changes
    - add some win32 compat code
    - add windows build check
    ### owasp ci failure
    both `google-http-client-gson` and `maven-settings` are not related to this PR
---
 .github/workflows/windows-build.yml                | 52 +++++++++++++++++++++
 native-io/pom.xml                                  | 37 +++++++++++++++
 .../src/main/native-io-jni/cpp/native_io_jni.c     | 54 ++++++++++++++++++++++
 3 files changed, 143 insertions(+)

diff --git a/.github/workflows/windows-build.yml b/.github/workflows/windows-build.yml
new file mode 100644
index 0000000000..5eb50950fd
--- /dev/null
+++ b/.github/workflows/windows-build.yml
@@ -0,0 +1,52 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF 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
+#
+#   http://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.
+#
+
+name: Build with windows on JDK 11
+
+on:
+  push:
+  pull_request:
+    branches:
+      - master
+      - branch-*
+    paths-ignore:
+      - 'site3/**'
+
+jobs:
+  test:
+    runs-on: windows-latest
+    timeout-minutes: 30
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v3
+
+      - name: Tune Runner VM
+        uses: ./.github/actions/tune-runner-vm
+
+      - name: Install mingw
+        run: choco install mingw
+
+      - name: Set up JDK 11
+        uses: actions/setup-java@v3
+        with:
+          distribution: 'temurin'
+          java-version: 11
+
+      - name: mvn package
+        run: mvn clean package -DskipTests
diff --git a/native-io/pom.xml b/native-io/pom.xml
index 693bfd9af8..48f3aefe48 100644
--- a/native-io/pom.xml
+++ b/native-io/pom.xml
@@ -211,6 +211,43 @@
         </plugins>
       </build>
     </profile>
+    <profile>
+      <id>Windows</id>
+      <activation>
+        <os>
+          <family>Windows</family>
+        </os>
+      </activation>
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>com.github.maven-nar</groupId>
+            <artifactId>nar-maven-plugin</artifactId>
+            <version>${nar-maven-plugin.version}</version>
+            <extensions>true</extensions>
+            <configuration>
+              <runtime>${nar.runtime}</runtime>
+              <output>circe-checksum</output>
+              <libraries>
+                <library>
+                  <type>jni</type>
+                  <narSystemPackage>com.scurrilous.circe.checksum</narSystemPackage>
+                </library>
+              </libraries>
+              <cpp>
+                <optionSet>${nar.cpp.optionSet}</optionSet>
+                <exceptions>false</exceptions>
+                <rtti>false</rtti>
+                <optimize>full</optimize>
+              </cpp>
+              <linker>
+                <name>g++</name>
+              </linker>
+            </configuration>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
   </profiles>
 
 </project>
diff --git a/native-io/src/main/native-io-jni/cpp/native_io_jni.c b/native-io/src/main/native-io-jni/cpp/native_io_jni.c
index 3e425a86bc..c8a966f38b 100644
--- a/native-io/src/main/native-io-jni/cpp/native_io_jni.c
+++ b/native-io/src/main/native-io-jni/cpp/native_io_jni.c
@@ -30,8 +30,60 @@
 
 #ifdef _WIN32
 
+#define fsync(fd) fflush(fd)
 #define strerror_r(errno,buf,len) strerror_s(buf,len,errno)
 
+static ssize_t pread (int fd, void *buf, size_t count, off_t offset)
+{
+  ssize_t res;
+  off_t ooffset;
+
+  ooffset = lseek (fd, 0, SEEK_CUR);
+  lseek (fd, offset, SEEK_SET);
+  res = read (fd, buf, count);
+  lseek (fd, ooffset, SEEK_SET);
+
+  return res;
+}
+
+static ssize_t pwrite (int fd, void *buf, size_t count, off_t offset)
+{
+  ssize_t res;
+  off_t ooffset;
+
+  ooffset = lseek (fd, 0, SEEK_CUR);
+  lseek (fd, offset, SEEK_SET);
+  res = write (fd, buf, count);
+  lseek (fd, ooffset, SEEK_SET);
+
+  return res;
+}
+
+static int check_align(size_t align)
+{
+    for (size_t i = sizeof(void *); i != 0; i *= 2)
+    if (align == i)
+        return 0;
+    return EINVAL;
+}
+
+int posix_memalign(void **ptr, size_t align, size_t size)
+{
+    if (check_align(align))
+        return EINVAL;
+
+    int saved_errno = errno;
+    void *p = _aligned_malloc(size, align);
+    if (p == NULL)
+    {
+        errno = saved_errno;
+        return ENOMEM;
+    }
+
+    *ptr = p;
+    return 0;
+}
+
 #endif
 
 static void throwExceptionWithErrno(JNIEnv* env, const char* message) {
@@ -87,9 +139,11 @@ Java_org_apache_bookkeeper_common_util_nativeio_NativeIOJni_open(
     }
 #endif
 
+#ifndef _WIN32
     if (javaFlags & 0x20) {
         flags |= O_DSYNC;
     }
+#endif
 
     int fd = open(cPath, flags, mode);