Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 40 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -84,17 +122,14 @@ 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.
#
# The only option to test this project on GitHub Actions under Windows is to
# 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:
Expand Down Expand Up @@ -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
Expand Down
61 changes: 50 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:

Expand All @@ -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

Expand Down
14 changes: 10 additions & 4 deletions src/mgallocator.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,20 @@
#include "mgallocator.h"

#include <assert.h>
// 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 <stdalign.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#endif
// ONLY ON MSVC
#ifdef _MSC_VER
#define alignof __alignof
typedef double max_align_t;
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void *mg_system_realloc(struct mg_allocator *self, void *buf, size_t size) {
(void)self;
Expand Down
7 changes: 5 additions & 2 deletions src/mgsession.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@

#include <assert.h>
#include <errno.h>
#include <stdalign.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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 <stdalign.h>
#include <unistd.h>
#endif

Expand Down