Skip to content

Commit 80933ab

Browse files
authored
Merge pull request #68 from memgraph/fix-ci-cd-action
This PR fixes so the CI is being run on the external contribution PRs. The windows fix uses vcpkg and statically linked OpenSSL
2 parents c14a02b + 204b951 commit 80933ab

4 files changed

Lines changed: 116 additions & 70 deletions

File tree

.github/CODEOWNERS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Global code owners
2+
# These users will be automatically assigned as reviewers for all PRs
3+
4+
* @antejavor @gitbuda

.github/workflows/ci.yml

Lines changed: 26 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,26 @@
11
name: CI
22

3-
on: [push]
3+
on:
4+
pull_request:
5+
branches: [ master ]
46

57
jobs:
68
build_and_test_ubuntu:
79
strategy:
810
matrix:
9-
platform: [ubuntu-20.04, ubuntu-22.04]
10-
mgversion: [2.19.0]
11+
platform: [ubuntu-24.04]
12+
mgversion: [latest]
1113
runs-on: ${{ matrix.platform }}
1214

1315
steps:
1416
- name: Install system dependencies
1517
run: sudo apt-get install -y git cmake make gcc g++ libssl-dev
16-
- uses: actions/checkout@v2
18+
- uses: actions/checkout@v4
1719
with:
1820
submodules: true
1921

20-
- name: Cache Memgraph Docker image
21-
id: cache-memgraph-community-docker
22-
uses: actions/cache@v1
23-
with:
24-
path: ~/memgraph
25-
key: cache-memgraph-v${{ matrix.mgversion }}-docker-image
26-
- name: Download Memgraph Docker image
27-
if: steps.cache-memgraph-community-docker.outputs.cache-hit != 'true'
28-
run: |
29-
mkdir ~/memgraph
30-
curl -L https://download.memgraph.com/memgraph/v${{ matrix.mgversion }}/docker/memgraph-${{ matrix.mgversion }}-docker.tar.gz > ~/memgraph/memgraph-docker.tar.gz
31-
- name: Load Memgraph Docker image
32-
run: docker load -i ~/memgraph/memgraph-docker.tar.gz
33-
34-
- uses: actions-rs/toolchain@v1
35-
with:
36-
toolchain: stable
22+
- name: Set up Rust toolchain
23+
uses: dtolnay/rust-toolchain@stable
3724
- name: Run rust linter
3825
run: cargo clippy
3926
- name: Run rust formatter
@@ -42,7 +29,7 @@ jobs:
4229
run: cargo build --verbose
4330
- name: Run Memgraph
4431
run: |
45-
docker run -d -p 7687:7687 memgraph/memgraph --telemetry-enabled=False
32+
docker run -d -p 7687:7687 memgraph/memgraph:${{ matrix.mgversion }} --telemetry-enabled=False
4633
- name: Run test
4734
run: cargo test
4835

@@ -64,7 +51,7 @@ jobs:
6451
run: |
6552
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
6653
67-
- uses: actions/checkout@v2
54+
- uses: actions/checkout@v4
6855
with:
6956
submodules: true
7057

@@ -87,47 +74,33 @@ jobs:
8774
sh rustup-init.sh -y --default-toolchain none
8875
rustup target add ${{ matrix.target }}
8976
90-
- uses: actions/checkout@v2
77+
- uses: actions/checkout@v4
9178
with:
9279
submodules: true
9380

9481
- name: Build the client
9582
run: cargo build --release
9683

9784
build_windows:
98-
strategy:
99-
matrix:
100-
platform: [windows-2019]
101-
target: [x86_64-pc-windows-gnu]
102-
arch:
103-
- { mingw: 64, msys: x86_64 }
104-
mgversion: [1.5]
105-
runs-on: ${{ matrix.platform }}
85+
runs-on: windows-latest
10686

10787
steps:
108-
- name: Install Rustup using win.rustup.rs
109-
run: |
110-
# Disable the download progress bar which can cause perf issues
111-
$ProgressPreference = "SilentlyContinue"
112-
Invoke-WebRequest https://win.rustup.rs/ -OutFile rustup-init.exe
113-
.\rustup-init.exe -y --default-host=x86_64-pc-windows-msvc --default-toolchain=none
114-
rustup target add ${{ matrix.target }}
115-
del rustup-init.exe
116-
117-
- uses: msys2/setup-msys2@v2
88+
- uses: actions/checkout@v4
11889
with:
119-
msystem: MINGW${{ matrix.arch.mingw }}
120-
update: true
121-
install: git mingw-w64-${{ matrix.arch.msys }}-toolchain mingw-w64-${{ matrix.arch.msys }}-cmake mingw-w64-${{ matrix.arch.msys }}-openssl
122-
123-
- name: Add mingw${{ matrix.arch.mingw }} to PATH
124-
run: |
125-
echo "C:/msys64/mingw${{ matrix.arch.mingw }}/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
90+
submodules: true
12691

127-
- uses: actions/checkout@v2
92+
- name: Set up Rust toolchain
93+
uses: dtolnay/rust-toolchain@stable
12894
with:
129-
submodules: true
95+
targets: x86_64-pc-windows-msvc
13096

131-
- name: Build the client
97+
- name: Install OpenSSL via vcpkg
13298
run: |
133-
cargo build --release --target=${{ matrix.target }}
99+
vcpkg install openssl:x64-windows-static
100+
101+
- name: Build the client
102+
run: cargo build --release --target=x86_64-pc-windows-msvc
103+
env:
104+
OPENSSL_LIB_DIR: "C:\\vcpkg\\installed\\x64-windows-static\\lib"
105+
OPENSSL_INCLUDE_DIR: "C:\\vcpkg\\installed\\x64-windows-static\\include"
106+
OPENSSL_STATIC: "1"

README.md

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,16 @@ your own Rust project, you can install it using `cargo`:
2828
cargo install rsmgclient
2929
```
3030

31-
NOTE: The default OpenSSL path on Windows is `C:\Program Files\OpenSSL-Win64\lib`,
32-
if you would like to change that please provide `OPENSSL_LIB_DIR` env variable.
31+
**Windows Users**: If you encounter OpenSSL-related build issues, you can install OpenSSL via vcpkg:
32+
```bash
33+
vcpkg install openssl:x64-windows-static
34+
```
35+
Then set the environment variables:
36+
```bash
37+
set OPENSSL_LIB_DIR=C:\vcpkg\installed\x64-windows-static\lib
38+
set OPENSSL_INCLUDE_DIR=C:\vcpkg\installed\x64-windows-static\include
39+
set OPENSSL_STATIC=1
40+
```
3341

3442
### Building from Source
3543

@@ -51,15 +59,14 @@ cargo build
5159
cargo test
5260
```
5361

54-
On MacOS, the build will try to detect OpenSSL by using MacPorts or Homebrew.
62+
On MacOS, the build will automatically detect OpenSSL using MacPorts or Homebrew.
63+
64+
On Windows, the build supports multiple OpenSSL configurations:
65+
- **Recommended**: The build will automatically use vcpkg to install OpenSSL if available
66+
- **Manual**: You can provide custom OpenSSL paths using `OPENSSL_LIB_DIR` and `OPENSSL_INCLUDE_DIR` environment variables
67+
- **Default**: Falls back to `C:\Program Files\OpenSSL-Win64\` if no custom paths are provided
5568

56-
On Windows, `bindgen` requires `libclang` which is a part of LLVM. If LLVM is
57-
not already installed just go to the [LLVM
58-
download](https://releases.llvm.org/download.html) page, download and install
59-
`LLVM.exe` file (select the option to put LLVM on the PATH). In addition,
60-
default OpenSSL path is `C:\Program Files\OpenSSL-Win64\lib`, if you would like
61-
to change that please provide `OPENSSL_LIB_DIR` env variable during the build
62-
phase.
69+
`bindgen` requires `libclang` which is part of LLVM. On Windows, if LLVM is not installed, download it from the [LLVM download page](https://releases.llvm.org/download.html) and install the `LLVM.exe` file (make sure to select the option to add LLVM to PATH).
6370

6471
## Documentation
6572

build.rs

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ fn build_mgclient_macos() -> Result<PathBuf, BuildError> {
152152
let openssl_root = openssl_dirs[0].clone();
153153
let path = Config::new("mgclient")
154154
.define("OPENSSL_ROOT_DIR", format!("{}", openssl_root.display()))
155+
.define(
156+
"OPENSSL_INCLUDE_DIR",
157+
format!("{}", openssl_root.join("include").display()),
158+
)
155159
.define(
156160
"OPENSSL_CRYPTO_LIBRARY",
157161
format!(
@@ -178,15 +182,59 @@ fn build_mgclient_linux() -> Result<PathBuf, BuildError> {
178182
}
179183

180184
fn build_mgclient_windows() -> Result<PathBuf, BuildError> {
181-
let openssl_dir = PathBuf::from(
185+
let openssl_lib_dir = PathBuf::from(
182186
std::env::var("OPENSSL_LIB_DIR")
183187
.unwrap_or_else(|_| "C:\\Program Files\\OpenSSL-Win64\\lib".to_string()),
184188
);
185-
println!("cargo:rustc-link-search=native={}", openssl_dir.display());
186-
let path = Config::new("mgclient")
187-
.define("OPENSSL_ROOT_DIR", format!("{}", openssl_dir.display()))
188-
.build();
189+
let openssl_include_dir = PathBuf::from(
190+
std::env::var("OPENSSL_INCLUDE_DIR")
191+
.unwrap_or_else(|_| "C:\\Program Files\\OpenSSL-Win64\\include".to_string()),
192+
);
193+
let openssl_root_dir = openssl_lib_dir.parent().unwrap_or(&openssl_lib_dir);
194+
195+
println!(
196+
"cargo:rustc-link-search=native={}",
197+
openssl_lib_dir.display()
198+
);
199+
200+
// Check if we're using vcpkg (static libraries)
201+
let is_vcpkg = openssl_lib_dir.to_string_lossy().contains("vcpkg");
202+
let (crypto_lib, ssl_lib) = if is_vcpkg {
203+
// vcpkg uses different library names for static builds
204+
(
205+
format!("{}\\libcrypto.lib", openssl_lib_dir.display()),
206+
format!("{}\\libssl.lib", openssl_lib_dir.display()),
207+
)
208+
} else {
209+
// Standard OpenSSL installation
210+
(
211+
format!("{}\\libcrypto.lib", openssl_lib_dir.display()),
212+
format!("{}\\libssl.lib", openssl_lib_dir.display()),
213+
)
214+
};
215+
216+
let mut config = Config::new("mgclient");
217+
config
218+
.define(
219+
"OPENSSL_ROOT_DIR",
220+
format!("{}", openssl_root_dir.display()),
221+
)
222+
.define(
223+
"OPENSSL_INCLUDE_DIR",
224+
format!("{}", openssl_include_dir.display()),
225+
)
226+
.define("OPENSSL_CRYPTO_LIBRARY", crypto_lib)
227+
.define("OPENSSL_SSL_LIBRARY", ssl_lib);
228+
229+
// If using static OpenSSL (vcpkg), configure for static linking
230+
if is_vcpkg {
231+
config.define("OPENSSL_USE_STATIC_LIBS", "TRUE");
232+
// Add system libraries that static OpenSSL depends on
233+
config.define("CMAKE_EXE_LINKER_FLAGS", "/DEFAULTLIB:crypt32.lib /DEFAULTLIB:ws2_32.lib /DEFAULTLIB:user32.lib /DEFAULTLIB:advapi32.lib");
234+
config.define("CMAKE_SHARED_LINKER_FLAGS", "/DEFAULTLIB:crypt32.lib /DEFAULTLIB:ws2_32.lib /DEFAULTLIB:user32.lib /DEFAULTLIB:advapi32.lib");
235+
}
189236

237+
let path = config.build();
190238
Ok(path)
191239
}
192240

@@ -246,8 +294,22 @@ fn main() -> Result<(), BuildError> {
246294
println!("cargo:rustc-link-lib=dylib=ssl");
247295
}
248296
HostType::Windows => {
249-
println!("cargo:rustc-link-lib=dylib=libcrypto");
250-
println!("cargo:rustc-link-lib=dylib=libssl");
297+
// Check if we're using static OpenSSL (vcpkg)
298+
let openssl_static = std::env::var("OPENSSL_STATIC").unwrap_or_default() == "1";
299+
if openssl_static {
300+
// Static linking - link with static libraries and system dependencies
301+
println!("cargo:rustc-link-lib=static=libcrypto");
302+
println!("cargo:rustc-link-lib=static=libssl");
303+
// Windows system libraries required by static OpenSSL
304+
println!("cargo:rustc-link-lib=crypt32");
305+
println!("cargo:rustc-link-lib=ws2_32");
306+
println!("cargo:rustc-link-lib=user32");
307+
println!("cargo:rustc-link-lib=advapi32");
308+
} else {
309+
// Dynamic linking
310+
println!("cargo:rustc-link-lib=dylib=libcrypto");
311+
println!("cargo:rustc-link-lib=dylib=libssl");
312+
}
251313
}
252314
HostType::MacOS => {
253315
println!("cargo:rustc-link-lib=dylib=crypto");

0 commit comments

Comments
 (0)