diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9d4d720..0b55eb6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,6 +36,45 @@ jobs: ctest -E "example|integration" sudo make install + build_windows_compiler: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - os: windows-latest + env: + VCPKG_ROOT: "${{ github.workspace }}\\vcpkg" + deps: "openssl:x64-windows" + steps: + - name: Set-up repository + uses: actions/checkout@v2 + - name: Restore vcpkg and its artifacts + uses: actions/cache@v3 + id: vcpkg-cache + with: + path: ${{ env.VCPKG_ROOT }} + key: ${{ matrix.os }}-${{ env.deps }} + - name: Get vcpkg + if: ${{ steps.vcpkg-cache.outputs.cache-hit != 'true' }} + run: | + cd ${{ github.workspace }} + git clone https://github.com/Microsoft/vcpkg.git + cd vcpkg + .\bootstrap-vcpkg.bat + - name: Remove system vcpkg + run: rm -rf "$VCPKG_INSTALLATION_ROOT" + shell: bash + - name: Install vcpkg packages + run: | + ${{ env.VCPKG_ROOT }}\vcpkg.exe install ${{ env.deps }} + - name: Build and test mgclient + run: | + mkdir build + cd build + cmake -DOPENSSL_ROOT_DIR="${{ env.VCPKG_ROOT }}\installed\x64-windows" .. + cmake --build . + build_and_test_linux: strategy: matrix: @@ -68,7 +107,6 @@ jobs: run: | docker load -i ~/memgraph/memgraph-docker.tar.gz docker run -d -p 7687:7687 memgraph --telemetry-enabled=false - - name: Build with gcc, test and install mgclient run: | mkdir build-gcc && cd build-gcc @@ -84,9 +122,6 @@ jobs: ctest --output-on-failure sudo make install - # This project needs MinGW environment ON_WINDOWS to compile. CMake, make, - # gcc are all required. - # # GitHub actions can't run Linux Docker container on Windows machine # https://github.com/actions/virtual-environments/issues/1143. # @@ -94,7 +129,7 @@ jobs: # run Memgraph under [WSL](https://docs.microsoft.com/en-us/windows/wsl/). # Memgraph has to be started manually because systemd is not available on # WSL (init process does not exist). - build_and_test_windows: + build_and_test_windows_mingw: runs-on: windows-latest strategy: matrix: @@ -123,7 +158,6 @@ jobs: dpkg -i ~/memgraph/memgraph-community.deb nohup /usr/lib/memgraph/memgraph --bolt-port 7687 --bolt-cert-file="" --bolt-key-file="" --data-directory="~/memgraph/data" --storage-properties-on-edges=true --storage-snapshot-interval-sec=0 --storage-wal-enabled=false --storage-recover-on-startup=false --storage-snapshot-on-exit=false --telemetry-enabled=false --log-file='' & sleep 1 # Wait for Memgraph a bit. - - name: Build and test mgclient run: | mkdir build diff --git a/README.md b/README.md index 3a637e6..726df32 100644 --- a/README.md +++ b/README.md @@ -30,11 +30,14 @@ brew install openssl@1.1 ``` If `cmake` can't locate OpenSSL, please set `OPENSSL_ROOT_DIR` to a valid path. -An examples follows: +Examples follow: ``` -cmake -DOPENSSL_ROOT_DIR="$(ls -rd -- /usr/local/Cellar/openssl@1.1/* | head -n 1)" .. +# M1 with brew installed cmake -DOPENSSL_ROOT_DIR="$(brew --prefix openssl)" .. + +# Using only ls command +cmake -DOPENSSL_ROOT_DIR="$(ls -rd -- /usr/local/Cellar/openssl@1.1/* | head -n 1)" .. ``` After running CMake, you should see a Makefile in the build directory. Then you @@ -112,12 +115,43 @@ ctest ## Building and installing on Windows -To build `mgclient` on Windows, MINGW environment should be used. - - Install MSYS2 from https://www.msys2.org/. - - Install MinGW toolchain with the following command: - ``` - pacman -S --needed git base-devel mingw-w64-i686-toolchain mingw-w64-x86_64-toolchain mingw-w64-i686-cmake mingw-w64-x86_64-cmake mingw-w64-i686-openssl mingw-w64-x86_64-openssl - ``` +To build and install mgclient from source on Windows you will need: + - CMake version >= 3.8 + - OpenSSL version >= 1.0.2 + - MinGW: gcc >= 8 or Windows Compiler (take a look + [here](https://blog.knatten.org/2022/08/26/microsoft-c-versions-explained/) + to understand versioning in a bit more details): + VS >= 17 2022, MSVC >= 14.34, C >= 19.34 + +### Windows Compiler + +``` +mkdir build +cd build +cmake .. +cmake --build . +``` + +Depending on where OpenSSL is installed you might need to define +`OPENSSL_ROOT_DIR`, example follows: +``` +cmake -DOPENSSL_ROOT_DIR="$VCPKG_ROOT\installed\x64-windows" .. +``` + +To install OpenSSL [vcpkg](https://vcpkg.io/en/index.html) can be used: +``` +vcpkg install openssl:x64-windows +``` +or you can download and install OpenSSL from +[here](https://slproweb.com/products/Win32OpenSSL.html). + +### MinGW + +- Install MSYS2 from https://www.msys2.org/. +- Install MinGW toolchain with the following command: + ``` + pacman -S --needed git base-devel mingw-w64-i686-toolchain mingw-w64-x86_64-toolchain mingw-w64-i686-cmake mingw-w64-x86_64-cmake mingw-w64-i686-openssl mingw-w64-x86_64-openssl + ``` Once the environment is ready, please run: @@ -127,12 +161,17 @@ cd build cmake .. -G "MinGW Makefiles" cmake --build . --target install ``` -## Building WASM (linux only) -Compiling `mgclient` for wasm requires the Emscripten sdk. This is automated in the following steps: + +## Building WASM (Linux only) + +Compiling `mgclient` for wasm requires the Emscripten sdk. This is automated in +the following steps: 1. mkdir build && cd build 2. cmake .. -DWASM=ON 3. make -Now there should be an `mgclient.js` and an `mgclient.wasm` found in `mgclient/build/` + +Now there should be an `mgclient.js` and an `mgclient.wasm` found in +`mgclient/build/` ## Using the library diff --git a/src/mgallocator.c b/src/mgallocator.c index 069e1e0..b12aeb4 100644 --- a/src/mgallocator.c +++ b/src/mgallocator.c @@ -15,14 +15,20 @@ #include "mgallocator.h" #include +// Somehow stdalign.h is not there (VS Build Tools 2019, Windows 11) +// https://docs.microsoft.com/en-us/cpp/cpp/alignment-cpp-declarations?view=msvc-170 +// EVERYWHERE EXCEPT MSVC +#if !defined(_WIN32) || !defined(_MSC_VER) #include -#include -#include -#include - +#endif +// ONLY ON MSVC #ifdef _MSC_VER +#define alignof __alignof typedef double max_align_t; #endif +#include +#include +#include void *mg_system_realloc(struct mg_allocator *self, void *buf, size_t size) { (void)self; diff --git a/src/mgsession.c b/src/mgsession.c index 69b0d88..7ce4a42 100644 --- a/src/mgsession.c +++ b/src/mgsession.c @@ -16,13 +16,16 @@ #include #include -#include #include #include #include #include #include -#ifndef _MSC_VER +// Somehow stdalign.h is not there (VS Build Tools 2019, Windows 11) +// https://docs.microsoft.com/en-us/cpp/cpp/alignment-cpp-declarations?view=msvc-170 +// EVERYWHERE EXCEPT MSVC +#if !defined(_WIN32) || !defined(_MSC_VER) +#include #include #endif