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

jiangtian pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/tsfile.git


The following commit(s) were added to refs/heads/develop by this push:
     new c6af3c36 Fix/fix the cpp build on windows (#109)
c6af3c36 is described below

commit c6af3c36bb67b892edd34fed39bb3720af74d3d6
Author: Christofer Dutz <[email protected]>
AuthorDate: Tue Jun 18 05:19:46 2024 +0200

    Fix/fix the cpp build on windows (#109)
    
    * FIX: Get the windows build working again
    
    * FIX: Updated the cmake-generator to match that of IoTDB.
    
    * FIX: Reverted to MinGW as there were errors with VisualStudio 17
    
    * fix: Adjusted the code to compile on linux, mac and windows.
    
    * feat: Enabled the cpp build on windows in github actions
    
    * fix: Tried to fix a compiler error (which however doesn't make much sense)
    
    * Removed the comments of license uncertainty.
    
    * feat: Removed the unneeded download
---
 .github/workflows/unit-test.yml       |  6 +--
 cpp/pom.xml                           | 93 ++++++++++++++++++++---------------
 cpp/src/common/allocator/mem_alloc.cc |  4 ++
 cpp/src/common/global.cc              |  4 ++
 cpp/src/cwrapper/TsFile-cwrapper.h    |  3 ++
 cpp/src/encoding/encoder_factory.h    |  1 +
 cpp/src/file/read_file.cc             | 35 ++++++++++++-
 cpp/src/file/write_file.cc            | 13 ++++-
 pom.xml                               |  6 +++
 9 files changed, 119 insertions(+), 46 deletions(-)

diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml
index 1d3e9ff8..f8d79fed 100644
--- a/.github/workflows/unit-test.yml
+++ b/.github/workflows/unit-test.yml
@@ -91,8 +91,4 @@ jobs:
       - name: Build and test with Maven (All others)
         shell: bash
         run: |
-          if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
-            ./mvnw${{ steps.platform_suffix.outputs.platform_suffix }} -P 
with-java clean verify
-          else
-            ./mvnw${{ steps.platform_suffix.outputs.platform_suffix }} -P 
with-java,with-cpp clean verify
-          fi
\ No newline at end of file
+          ./mvnw${{ steps.platform_suffix.outputs.platform_suffix }} -P 
with-java,with-cpp clean verify
diff --git a/cpp/pom.xml b/cpp/pom.xml
index d815e87c..cf457b63 100644
--- a/cpp/pom.xml
+++ b/cpp/pom.xml
@@ -28,7 +28,6 @@
     <packaging>pom</packaging>
     <name>TsFile: C++</name>
     <properties>
-        <unity.version>2.6.0</unity.version>
         <groovy.version>4.0.21</groovy.version>
         <!-- Tell Sonar where to find the sources -->
         <sonar.sources>common,examples,tsfile</sonar.sources>
@@ -37,64 +36,80 @@
     <build>
         <sourceDirectory>${project.basedir}</sourceDirectory>
         <plugins>
+            <!--
+                Do the actual build.
+            -->
             <plugin>
-                <groupId>com.googlecode.maven-download-plugin</groupId>
-                <artifactId>download-maven-plugin</artifactId>
+                <groupId>com.googlecode.cmake-maven-project</groupId>
+                <artifactId>cmake-maven-plugin</artifactId>
                 <executions>
-                    <!--
-                        Get additional stuff we need for the build.
-                    -->
+                    <!-- Generate the configuration for the main compilation 
-->
+                    <!--execution>
+                      <id>cmake-generate-compile</id>
+                      <phase>compile</phase>
+                      <goals>
+                        <goal>generate</goal>
+                      </goals>
+                    </execution>
+                    <!- Compile the main code ->
                     <execution>
-                        <id>get-unity</id>
-                        <phase>generate-sources</phase>
+                      <id>cmake-execute-compile</id>
+                      <phase>compile</phase>
+                      <goals>
+                        <goal>compile</goal>
+                      </goals>
+                    </execution-->
+                    <!-- Generate the configuration for the test compilation 
-->
+                    <execution>
+                        <id>cmake-generate-test-compile</id>
+                        <phase>generate-test-sources</phase>
                         <goals>
-                            <goal>wget</goal>
+                            <goal>generate</goal>
                         </goals>
                         <configuration>
-                            
<url>https://github.com/ThrowTheSwitch/Unity/archive/v${unity.version}.zip</url>
-                            <unpack>true</unpack>
-                            
<outputDirectory>${project.build.directory}/dependency</outputDirectory>
+                            <options>
+                                <option>-DBUILD_PHASE=test-compile</option>
+                            </options>
                         </configuration>
                     </execution>
-                </executions>
-            </plugin>
-            <!--
-                Do the actual build.
-            -->
-            <plugin>
-                <groupId>org.codehaus.mojo</groupId>
-                <artifactId>exec-maven-plugin</artifactId>
-                <version>1.6.0</version>
-                <executions>
-                    <!-- run build script -->
+                    <!-- Compile the test code -->
                     <execution>
-                        <id>execute-compile-shell-script</id>
-                        <phase>compile</phase>
+                        <id>cmake-execute-test-compile</id>
+                        <phase>test-compile</phase>
                         <goals>
-                            <goal>exec</goal>
+                            <goal>compile</goal>
                         </goals>
-                        <configuration>
-                            <executable>bash</executable>
-                            <arguments>
-                                <argument>build.sh</argument>
-                            </arguments>
-                        </configuration>
                     </execution>
-                    <!-- run test_all.sh script -->
+                    <!-- Execute the tests -->
                     <execution>
-                        <id>execute-test-shell-script</id>
+                        <id>cmake-run-tests</id>
                         <phase>test</phase>
                         <goals>
-                            <goal>exec</goal>
+                            <goal>test</goal>
                         </goals>
                         <configuration>
-                            <executable>bash</executable>
-                            <arguments>
-                                <argument>test_all.sh</argument>
-                            </arguments>
+                            
<buildDirectory>${project.build.directory}/build</buildDirectory>
                         </configuration>
                     </execution>
                 </executions>
+                <configuration>
+                    <!--
+                        Actually the path to the CMakeList.txt file which then 
again
+                        tells to tool where to find the sources.
+                    -->
+                    <sourcePath>${project.basedir}</sourcePath>
+                    <!--
+                        Path to where the build configuration is generated
+                        (This directory is then used in the compile step to 
actually perform the build)
+                    -->
+                    <targetPath>${project.build.directory}/build</targetPath>
+                    <!--
+                        Name of the generator the compile step will be 
executing.
+                    -->
+                    <generator>${cmake.generator}</generator>
+                    <!-- The directory where the "generate" step generated the 
build configuration -->
+                    
<projectDirectory>${project.build.directory}/build</projectDirectory>
+                </configuration>
             </plugin>
             <!-- Overwrite test config-->
             <plugin>
diff --git a/cpp/src/common/allocator/mem_alloc.cc 
b/cpp/src/common/allocator/mem_alloc.cc
index 983b52aa..a1e16d9b 100644
--- a/cpp/src/common/allocator/mem_alloc.cc
+++ b/cpp/src/common/allocator/mem_alloc.cc
@@ -17,7 +17,9 @@
  * under the License.
  */
 
+#ifndef _WIN32
 #include <execinfo.h>
+#endif
 #include <string.h>
 
 #include <iostream>
@@ -102,6 +104,7 @@ void *mem_alloc(uint32_t size, AllocModID mid) {
     }
 }
 
+#ifndef _WIN32
 void printCallers() {
     int layers = 0, i = 0;
     char **symbols = NULL;
@@ -126,6 +129,7 @@ void printCallers() {
         printf("Failed to parse function names\n");
     }
 }
+#endif
 
 void mem_free(void *ptr) {
     // try as 4Byte header
diff --git a/cpp/src/common/global.cc b/cpp/src/common/global.cc
index fc63677c..b54d4499 100644
--- a/cpp/src/common/global.cc
+++ b/cpp/src/common/global.cc
@@ -19,7 +19,9 @@
 
 #include "global.h"
 
+#ifndef _WIN32
 #include <execinfo.h>
+#endif
 #include <stdlib.h>
 
 #include "utils/injection.h"
@@ -166,6 +168,7 @@ void cols_to_json(ByteStream* byte_stream,
     // DEBUG_print_byte_stream(*byte_stream);  // for debug
 }
 
+#ifndef _WIN32
 void print_backtrace() {
     const int MAX_FRAMES = 32;
     int layers = 0;
@@ -182,6 +185,7 @@ void print_backtrace() {
         free(symbols);
     }
 }
+#endif
 
 Mutex g_all_inject_points_mutex;
 std::map<std::string, InjectPoint> g_all_inject_points;
diff --git a/cpp/src/cwrapper/TsFile-cwrapper.h 
b/cpp/src/cwrapper/TsFile-cwrapper.h
index 08b664d5..97ffedd0 100644
--- a/cpp/src/cwrapper/TsFile-cwrapper.h
+++ b/cpp/src/cwrapper/TsFile-cwrapper.h
@@ -24,6 +24,9 @@
 #include <stdbool.h>
 #include <stddef.h>
 #include <stdint.h>
+#ifdef _WIN32
+#include <sys/stat.h>
+#endif
 
 typedef long long SchemaInfo;
 typedef long long timestamp;
diff --git a/cpp/src/encoding/encoder_factory.h 
b/cpp/src/encoding/encoder_factory.h
index b533efbb..e9e02e4b 100644
--- a/cpp/src/encoding/encoder_factory.h
+++ b/cpp/src/encoding/encoder_factory.h
@@ -104,6 +104,7 @@ class EncoderFactory {
             ASSERT(false);
             return nullptr;
         }
+        return nullptr;
     }
 
     static void free(Encoder *encoder) { common::mem_free(encoder); }
diff --git a/cpp/src/file/read_file.cc b/cpp/src/file/read_file.cc
index 185c24d3..97385835 100644
--- a/cpp/src/file/read_file.cc
+++ b/cpp/src/file/read_file.cc
@@ -26,6 +26,13 @@
 #include "common/logger/elog.h"
 #include "common/tsfile_common.h"
 
+#ifdef _WIN32
+#include <windows.h>
+#include <io.h>
+
+ssize_t pread(int fd, void *buf, size_t count, uint64_t offset);
+#endif
+
 using namespace common;
 namespace storage {
 
@@ -123,4 +130,30 @@ int ReadFile::read(int32_t offset, char *buf, int32_t 
buf_size,
     return ret;
 }
 
-}  // end namespace storage
\ No newline at end of file
+}  // end namespace storage
+
+#ifdef _WIN32
+ssize_t pread(int fd, void *buf, size_t count, uint64_t offset)
+{
+    long unsigned int read_bytes = 0;
+
+    OVERLAPPED overlapped;
+    memset(&overlapped, 0, sizeof(OVERLAPPED));
+
+    overlapped.OffsetHigh = (uint32_t)((offset & 0xFFFFFFFF00000000LL) >> 32);
+    overlapped.Offset = (uint32_t)(offset & 0xFFFFFFFFLL);
+
+    HANDLE file = (HANDLE)_get_osfhandle(fd);
+    SetLastError(0);
+    bool RF = ReadFile(file, buf, count, &read_bytes, &overlapped);
+
+    // For some reason it errors when it hits end of file so we don't want to 
check that
+    if ((RF == 0) && GetLastError() != ERROR_HANDLE_EOF) {
+        errno = GetLastError();
+        // printf ("Error reading file : %d\n", GetLastError());
+        return -1;
+    }
+
+    return read_bytes;
+}
+#endif
diff --git a/cpp/src/file/write_file.cc b/cpp/src/file/write_file.cc
index 071a226b..2fb08c26 100644
--- a/cpp/src/file/write_file.cc
+++ b/cpp/src/file/write_file.cc
@@ -31,6 +31,10 @@
 #include "common/logger/elog.h"
 #include "utils/errno_define.h"
 
+#ifdef _WIN32
+int     fsync(int);
+#endif
+
 using namespace common;
 
 namespace storage {
@@ -125,4 +129,11 @@ int WriteFile::close() {
     return E_OK;
 }
 
-}  // end namespace storage
\ No newline at end of file
+}  // end namespace storage
+
+#ifdef _WIN32
+int fsync(int fd)
+{
+    return _commit(fd);
+}
+#endif
diff --git a/pom.xml b/pom.xml
index 07a98e94..6b81c462 100644
--- a/pom.xml
+++ b/pom.xml
@@ -725,6 +725,8 @@
                 <os.suffix>win</os.suffix>
                 <os.classifier>windows-x86_64</os.classifier>
                 <cmake.generator>MinGW Makefiles</cmake.generator>
+                <!-- The generated code relied on Boost and that relies on VS 
and can't be built with MinGW -->
+                <!--cmake.generator>Visual Studio 17 2022</cmake.generator-->
             </properties>
         </profile>
         <!-- profile for windows amd64 (mainly AMD Processors) (Self-Enabling) 
-->
@@ -740,6 +742,8 @@
                 <os.suffix>win</os.suffix>
                 <os.classifier>windows-amd64</os.classifier>
                 <cmake.generator>MinGW Makefiles</cmake.generator>
+                <!-- The generated code relied on Boost and that relies on VS 
and can't be built with MinGW -->
+                <!--cmake.generator>Visual Studio 17 2022</cmake.generator-->
             </properties>
         </profile>
         <!-- profile for windows aarch64 (mainly newer Mac or Raspberry PI 
Processors) (Self-Enabling) -->
@@ -755,6 +759,8 @@
                 <os.suffix>win</os.suffix>
                 <os.classifier>windows-aarch64</os.classifier>
                 <cmake.generator>MinGW Makefiles</cmake.generator>
+                <!-- The generated code relied on Boost and that relies on VS 
and can't be built with MinGW -->
+                <!--cmake.generator>Visual Studio 17 2022</cmake.generator-->
             </properties>
         </profile>
         <!-- Little helper profile that will disable running the cmake tests 
when the maven tests are being skipped -->

Reply via email to