From b500ab0692524b546564c6ad87589e7ab482530e Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Sat, 17 Aug 2024 13:33:26 +0200 Subject: [PATCH 01/37] Add spatial data types --- mgclient | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mgclient b/mgclient index d57df8a..1999893 160000 --- a/mgclient +++ b/mgclient @@ -1 +1 @@ -Subproject commit d57df8aba5d62074c56aced591147e2b2616c4dc +Subproject commit 19998932beb0f54dee0347b515cd9c9da60a83b4 From d58bab98a2f987681e24b1e1a9627357a5cabf35 Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Sun, 18 Aug 2024 20:15:31 +0200 Subject: [PATCH 02/37] Add Point2D and Point3D + tests --- mgclient | 2 +- src/connection/mod.rs | 2 +- src/main.rs | 20 ++++++++- src/value/mod.rs | 96 +++++++++++++++++++++++++++++++++++++++++++ src/value/tests.rs | 78 +++++++++++++++++++++++++++++++++++ 5 files changed, 195 insertions(+), 3 deletions(-) diff --git a/mgclient b/mgclient index 1999893..df0aeb3 160000 --- a/mgclient +++ b/mgclient @@ -1 +1 @@ -Subproject commit 19998932beb0f54dee0347b515cd9c9da60a83b4 +Subproject commit df0aeb3439813eb08d541c3855b312a90f54cb25 diff --git a/src/connection/mod.rs b/src/connection/mod.rs index 89e69e0..7ffea70 100644 --- a/src/connection/mod.rs +++ b/src/connection/mod.rs @@ -372,7 +372,7 @@ impl Connection { unsafe { bindings::mg_session_params_destroy(mg_session_params); if !trust_callback_ptr.is_null() { - Box::from_raw(trust_callback_ptr); + let _ = Box::from_raw(trust_callback_ptr); } }; diff --git a/src/main.rs b/src/main.rs index 85c5199..2afd9c8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,6 @@ -use rsmgclient::{ConnectParams, Connection, MgError, Value}; +use std::collections::HashMap; + +use rsmgclient::{ConnectParams, Connection, MgError, Point2D, QueryParam, Value}; fn execute_query() -> Result<(), MgError> { // Connect to Memgraph. @@ -29,6 +31,22 @@ fn execute_query() -> Result<(), MgError> { } connection.commit()?; + let mut query_params: HashMap = HashMap::new(); + query_params.insert( + "point2d".to_string(), + QueryParam::Point2D(Point2D { + srid: 7203, + x_longitude: 0.0, + y_latitude: 1.0, + }), + ); + connection.execute("RETURN $point2d;", Some(&query_params))?; + for record in connection.fetchall()? { + for value in record.values { + println!("{}", value); + } + } + Ok(()) } diff --git a/src/value/mod.rs b/src/value/mod.rs index 4a4a974..8690f1e 100644 --- a/src/value/mod.rs +++ b/src/value/mod.rs @@ -23,6 +23,43 @@ use std::num::TryFromIntError; use std::os::raw::c_char; use std::slice; +/// Representation of Point2D spatial data type. +#[derive(Debug, PartialEq, Clone)] +pub struct Point2D { + pub srid: u16, + pub x_longitude: f64, + pub y_latitude: f64, +} + +impl fmt::Display for Point2D { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!( + f, + "Point2D({{ srid:{}, x:{}, y:{} }})", + self.srid, self.x_longitude, self.y_latitude + ) + } +} + +/// Representation of Point3D spatial data type. +#[derive(Debug, PartialEq, Clone)] +pub struct Point3D { + pub srid: u16, + pub x_longitude: f64, + pub y_latitude: f64, + pub z_height: f64, +} + +impl fmt::Display for Point3D { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!( + f, + "Point2D({{ srid:{}, x:{}, y:{}, z:{} }})", + self.srid, self.x_longitude, self.y_latitude, self.z_height + ) + } +} + /// Representation of parameter value used in query. pub enum QueryParam { Null, @@ -34,6 +71,8 @@ pub enum QueryParam { LocalTime(NaiveTime), LocalDateTime(NaiveDateTime), Duration(Duration), + Point2D(Point2D), + Point3D(Point3D), List(Vec), Map(HashMap), } @@ -60,6 +99,12 @@ impl QueryParam { QueryParam::Duration(x) => { bindings::mg_value_make_duration(duration_to_mg_duration(x)) } + QueryParam::Point2D(x) => { + bindings::mg_value_make_point_2d(point2d_to_mg_point_2d(x)) + } + QueryParam::Point3D(x) => { + bindings::mg_value_make_point_3d(point3d_to_mg_point_3d(x)) + } QueryParam::List(x) => bindings::mg_value_make_list(vector_to_mg_list(x)), QueryParam::Map(x) => bindings::mg_value_make_map(hash_map_to_mg_map(x)), } @@ -135,6 +180,8 @@ pub enum Value { LocalTime(NaiveTime), LocalDateTime(NaiveDateTime), Duration(Duration), + Point2D(Point2D), + Point3D(Point3D), Map(HashMap), Node(Node), Relationship(Relationship), @@ -241,6 +288,32 @@ pub(crate) fn mg_value_duration(mg_value: *const bindings::mg_value) -> Duration Duration::days(days) + Duration::seconds(seconds) + Duration::nanoseconds(nanoseconds) } +pub(crate) fn mg_value_point2d(mg_value: *const bindings::mg_value) -> Point2D { + let c_point2d = unsafe { bindings::mg_value_point_2d(mg_value) }; + let srid = unsafe { bindings::mg_point_2d_srid(c_point2d) } as u16; + let x_longitude = unsafe { bindings::mg_point_2d_x(c_point2d) }; + let y_latitude = unsafe { bindings::mg_point_2d_y(c_point2d) }; + Point2D { + srid, + x_longitude, + y_latitude, + } +} + +pub(crate) fn mg_value_point3d(mg_value: *const bindings::mg_value) -> Point3D { + let c_point3d = unsafe { bindings::mg_value_point_3d(mg_value) }; + let srid = unsafe { bindings::mg_point_3d_srid(c_point3d) } as u16; + let x_longitude = unsafe { bindings::mg_point_3d_x(c_point3d) }; + let y_latitude = unsafe { bindings::mg_point_3d_y(c_point3d) }; + let z_height = unsafe { bindings::mg_point_3d_z(c_point3d) }; + Point3D { + srid, + x_longitude, + y_latitude, + z_height, + } +} + pub(crate) fn mg_map_to_hash_map(mg_map: *const bindings::mg_map) -> HashMap { unsafe { let size = bindings::mg_map_size(mg_map); @@ -433,6 +506,21 @@ pub(crate) fn duration_to_mg_duration(input: &Duration) -> *mut bindings::mg_dur unsafe { bindings::mg_duration_make(0, days, seconds, nanoseconds) } } +pub(crate) fn point2d_to_mg_point_2d(input: &Point2D) -> *mut bindings::mg_point_2d { + unsafe { bindings::mg_point_2d_make(input.srid, input.x_longitude, input.y_latitude) } +} + +pub(crate) fn point3d_to_mg_point_3d(input: &Point3D) -> *mut bindings::mg_point_3d { + unsafe { + bindings::mg_point_3d_make( + input.srid, + input.x_longitude, + input.y_latitude, + input.z_height, + ) + } +} + pub(crate) fn vector_to_mg_list(vector: &[QueryParam]) -> *mut bindings::mg_list { let size = vector.len() as u32; let mg_list = unsafe { bindings::mg_list_make_empty(size) }; @@ -466,6 +554,12 @@ impl Value { bindings::mg_value_type_MG_VALUE_TYPE_DURATION => { Value::Duration(mg_value_duration(c_mg_value)) } + bindings::mg_value_type_MG_VALUE_TYPE_POINT_2D => { + Value::Point2D(mg_value_point2d(c_mg_value)) + } + bindings::mg_value_type_MG_VALUE_TYPE_POINT_3D => { + Value::Point3D(mg_value_point3d(c_mg_value)) + } bindings::mg_value_type_MG_VALUE_TYPE_LIST => { Value::List(mg_value_list_to_vec(c_mg_value)) } @@ -496,6 +590,8 @@ impl fmt::Display for Value { Value::LocalTime(x) => write!(f, "'{}'", x), Value::LocalDateTime(x) => write!(f, "'{}'", x), Value::Duration(x) => write!(f, "'{}'", x), + Value::Point2D(x) => write!(f, "'{}'", x), + Value::Point3D(x) => write!(f, "'{}'", x), Value::List(x) => write!( f, "{}", diff --git a/src/value/tests.rs b/src/value/tests.rs index 5d2b079..80052d6 100644 --- a/src/value/tests.rs +++ b/src/value/tests.rs @@ -69,6 +69,8 @@ fn mg_value_to_c_mg_value(mg_value: &Value) -> *mut bindings::mg_value { naive_local_date_time_to_mg_local_date_time(x), ), Value::Duration(x) => bindings::mg_value_make_duration(duration_to_mg_duration(x)), + Value::Point2D(x) => bindings::mg_value_make_point_2d(point2d_to_mg_point_2d(x)), + Value::Point3D(x) => bindings::mg_value_make_point_3d(point3d_to_mg_point_3d(x)), Value::List(x) => { bindings::mg_value_make_list(bindings::mg_list_copy(vector_to_mg_list(x))) } @@ -359,6 +361,53 @@ fn from_c_mg_value_duration() { assert_eq!(format!("{}", mg_value), "'PT864100.000001S'"); } +#[test] +fn from_c_mg_value_point_2d() { + let c_point2d = bindings::mg_point_2d { + srid: 0, + x: 1.0, + y: 2.0, + }; + let c_mg_value = + unsafe { bindings::mg_value_make_point_2d(bindings::mg_point_2d_copy(&c_point2d)) }; + let mg_value = unsafe { Value::from_mg_value(c_mg_value) }; + assert_eq!( + Value::Point2D(Point2D { + srid: 0, + x_longitude: 1.0, + y_latitude: 2.0 + }), + mg_value + ); + assert_eq!(format!("{}", mg_value), "'Point2D({ srid:0, x:1, y:2 })'"); +} + +#[test] +fn from_c_mg_value_point_3d() { + let c_point3d = bindings::mg_point_3d { + srid: 0, + x: 1.0, + y: 2.0, + z: 3.0, + }; + let c_mg_value = + unsafe { bindings::mg_value_make_point_3d(bindings::mg_point_3d_copy(&c_point3d)) }; + let mg_value = unsafe { Value::from_mg_value(c_mg_value) }; + assert_eq!( + Value::Point3D(Point3D { + srid: 0, + x_longitude: 1.0, + y_latitude: 2.0, + z_height: 3.0 + }), + mg_value + ); + assert_eq!( + format!("{}", mg_value), + "'Point2D({ srid:0, x:1, y:2, z:3 })'" + ); +} + #[test] fn from_c_mg_value_list() { let mg_values = vec![ @@ -861,6 +910,35 @@ fn from_duration_to_mg_value_2() { } } +#[test] +fn from_point2d_to_mg_point_2d() { + let query_param = QueryParam::Point2D(Point2D { + srid: 0, + x_longitude: 1.0, + y_latitude: 2.0, + }); + let c_mg_value = unsafe { *(query_param.to_c_mg_value()) }; + assert_eq!( + c_mg_value.type_, + bindings::mg_value_type_MG_VALUE_TYPE_POINT_2D + ); +} + +#[test] +fn from_point3d_to_mg_point_3d() { + let query_param = QueryParam::Point3D(Point3D { + srid: 0, + x_longitude: 1.0, + y_latitude: 2.0, + z_height: 3.0, + }); + let c_mg_value = unsafe { *(query_param.to_c_mg_value()) }; + assert_eq!( + c_mg_value.type_, + bindings::mg_value_type_MG_VALUE_TYPE_POINT_3D + ); +} + #[test] fn from_to_c_mg_value_list() { let vec: Vec = vec![ From 65ff82809b18069aa1f343b8dd05bbddb09f043a Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Sat, 24 Aug 2024 16:16:05 +0200 Subject: [PATCH 03/37] Move to the latest mgclient --- .github/workflows/ci.yml | 5 ++--- mgclient | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cdb4168..2b96331 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ jobs: strategy: matrix: platform: [ubuntu-20.04, ubuntu-22.04] - mgversion: [2.16.1] + mgversion: [2.19.0] runs-on: ${{ matrix.platform }} steps: @@ -97,11 +97,10 @@ jobs: build_windows: strategy: matrix: - platform: [windows-2019] + platform: [windows-2022] target: [x86_64-pc-windows-gnu] arch: - { mingw: 64, msys: x86_64 } - mgversion: [1.5] runs-on: ${{ matrix.platform }} steps: diff --git a/mgclient b/mgclient index df0aeb3..316e0cc 160000 --- a/mgclient +++ b/mgclient @@ -1 +1 @@ -Subproject commit df0aeb3439813eb08d541c3855b312a90f54cb25 +Subproject commit 316e0cc195537fa103ae2ae53e0303a311bc5255 From dcb84ac9677b1748aaabe03623ab61dd99088286 Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Sat, 24 Aug 2024 16:20:19 +0200 Subject: [PATCH 04/37] Fix linux build --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2b96331..00afe43 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,7 +42,7 @@ jobs: run: cargo build --verbose - name: Run Memgraph run: | - docker run -d -p 7687:7687 memgraph --telemetry-enabled=False + docker run -d -p 7687:7687 memgraph/memgraph --telemetry-enabled=False - name: Run test run: cargo test From eed064fb384a94f985b09918f777cc93289163a4 Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Sat, 24 Aug 2024 16:29:40 +0200 Subject: [PATCH 05/37] Try 1 ssl, print dir --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 00afe43..081ec0c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -122,6 +122,7 @@ jobs: - name: Add mingw${{ matrix.arch.mingw }} to PATH run: | echo "C:/msys64/mingw${{ matrix.arch.mingw }}/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8 + ls -alh "C:/msys64/mingw${{ matrix.arch.mingw }}/lib" - uses: actions/checkout@v2 with: From f15e007e4820af858bcefeae864c809b9f716f04 Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Sat, 24 Aug 2024 16:32:15 +0200 Subject: [PATCH 06/37] Try 2 ssl, ls fix --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 081ec0c..5f42f0a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -122,7 +122,7 @@ jobs: - name: Add mingw${{ matrix.arch.mingw }} to PATH run: | echo "C:/msys64/mingw${{ matrix.arch.mingw }}/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8 - ls -alh "C:/msys64/mingw${{ matrix.arch.mingw }}/lib" + ls "C:/msys64/mingw${{ matrix.arch.mingw }}/lib" - uses: actions/checkout@v2 with: From c8119e91788c6f04967ae8152e22a77f37f39e5a Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Sat, 24 Aug 2024 16:40:16 +0200 Subject: [PATCH 07/37] Try 3 ssl, ls fix --- .github/workflows/ci.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5f42f0a..d1d995d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -119,10 +119,14 @@ jobs: update: true install: git mingw-w64-${{ matrix.arch.msys }}-toolchain mingw-w64-${{ matrix.arch.msys }}-cmake mingw-w64-${{ matrix.arch.msys }}-openssl + - name: Debug + run: | + ls "C:/" + ls "C:/msys64" + - name: Add mingw${{ matrix.arch.mingw }} to PATH run: | echo "C:/msys64/mingw${{ matrix.arch.mingw }}/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8 - ls "C:/msys64/mingw${{ matrix.arch.mingw }}/lib" - uses: actions/checkout@v2 with: From 7ac4a375054087bb623df7f60ce075576bb69942 Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Sat, 24 Aug 2024 16:43:12 +0200 Subject: [PATCH 08/37] Try 4 ssl, ls fix --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d1d995d..bb5dc10 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -123,6 +123,7 @@ jobs: run: | ls "C:/" ls "C:/msys64" + ls "C:/msys64/mingw${{ matrix.arch.mingw }}" - name: Add mingw${{ matrix.arch.mingw }} to PATH run: | From b39c332fda105969ca39d9158f2f2d9a906c18e1 Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Sat, 24 Aug 2024 16:45:50 +0200 Subject: [PATCH 09/37] Try 5 ssl, ls fix --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bb5dc10..c88d46a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -124,6 +124,7 @@ jobs: ls "C:/" ls "C:/msys64" ls "C:/msys64/mingw${{ matrix.arch.mingw }}" + ls "C:/msys64/mingw${{ matrix.arch.mingw }}/lib/ - name: Add mingw${{ matrix.arch.mingw }} to PATH run: | From 46461e3b5361b5fc336d302704eeb6726fdd4f59 Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Sat, 24 Aug 2024 16:50:03 +0200 Subject: [PATCH 10/37] Try 6 ssl, ls fix --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c88d46a..ce3b521 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -124,11 +124,12 @@ jobs: ls "C:/" ls "C:/msys64" ls "C:/msys64/mingw${{ matrix.arch.mingw }}" - ls "C:/msys64/mingw${{ matrix.arch.mingw }}/lib/ + ls "C:/msys64/mingw${{ matrix.arch.mingw }}/lib/" - name: Add mingw${{ matrix.arch.mingw }} to PATH run: | echo "C:/msys64/mingw${{ matrix.arch.mingw }}/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8 + echo "C:/msys64/mingw${{ matrix.arch.mingw }}/lib" | Out-File -Append -FilePath $env:OPENSSL_LIB_DIR -Encoding utf8 - uses: actions/checkout@v2 with: From 9a10e81fa830ea35d398a553e2049dbc4ee00ffb Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Sat, 24 Aug 2024 17:10:00 +0200 Subject: [PATCH 11/37] Try 7 ssl, ls fix --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ce3b521..7f3f705 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -124,12 +124,12 @@ jobs: ls "C:/" ls "C:/msys64" ls "C:/msys64/mingw${{ matrix.arch.mingw }}" - ls "C:/msys64/mingw${{ matrix.arch.mingw }}/lib/" + ls "C:/msys64/mingw${{ matrix.arch.mingw }}/lib" - name: Add mingw${{ matrix.arch.mingw }} to PATH run: | echo "C:/msys64/mingw${{ matrix.arch.mingw }}/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8 - echo "C:/msys64/mingw${{ matrix.arch.mingw }}/lib" | Out-File -Append -FilePath $env:OPENSSL_LIB_DIR -Encoding utf8 + echo "OPENSSL_LIB_DIR=C:/msys64/mingw${{ matrix.arch.mingw }}/lib" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 - uses: actions/checkout@v2 with: From bb1425faee333acf6b99cda4c56b7e47402dfd2e Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Sat, 24 Aug 2024 17:20:16 +0200 Subject: [PATCH 12/37] Try 8 ssl --- .github/workflows/ci.yml | 3 ++- Cargo.toml | 2 +- build.rs | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7f3f705..93e9820 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -129,7 +129,8 @@ jobs: - name: Add mingw${{ matrix.arch.mingw }} to PATH run: | echo "C:/msys64/mingw${{ matrix.arch.mingw }}/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8 - echo "OPENSSL_LIB_DIR=C:/msys64/mingw${{ matrix.arch.mingw }}/lib" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 + # NOTE: How to set the environment variable? + # echo "OPENSSL_LIB_DIR=C:/msys64/mingw${{ matrix.arch.mingw }}/lib" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 - uses: actions/checkout@v2 with: diff --git a/Cargo.toml b/Cargo.toml index 8d6634b..cf4a946 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ serde_json = "1.0.57" [build-dependencies] bindgen = "0.68.1" -cmake = "0.1.45" +cmake = "0.1.51" [dev-dependencies.cargo-husky] version = "1" diff --git a/build.rs b/build.rs index 32167fd..78fc5cc 100644 --- a/build.rs +++ b/build.rs @@ -143,6 +143,7 @@ fn build_mgclient_windows() -> PathBuf { ); println!("cargo:rustc-link-search=native={}", openssl_dir.display()); Config::new("mgclient") + .generator("MinGW Makefiles") .define("OPENSSL_ROOT_DIR", format!("{}", openssl_dir.display())) .build() } From 0dc11ed2b0ceb8e6c731fbc18df0f4d43a00129a Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Sat, 24 Aug 2024 17:24:40 +0200 Subject: [PATCH 13/37] Try 9 ssl --- .github/workflows/ci.yml | 3 +-- build.rs | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 93e9820..bab8953 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -129,8 +129,7 @@ jobs: - name: Add mingw${{ matrix.arch.mingw }} to PATH run: | echo "C:/msys64/mingw${{ matrix.arch.mingw }}/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8 - # NOTE: How to set the environment variable? - # echo "OPENSSL_LIB_DIR=C:/msys64/mingw${{ matrix.arch.mingw }}/lib" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 + # echo "CMAKE_GENERATOR='MinGW Makefiles'" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 - uses: actions/checkout@v2 with: diff --git a/build.rs b/build.rs index 78fc5cc..846e003 100644 --- a/build.rs +++ b/build.rs @@ -143,8 +143,7 @@ fn build_mgclient_windows() -> PathBuf { ); println!("cargo:rustc-link-search=native={}", openssl_dir.display()); Config::new("mgclient") - .generator("MinGW Makefiles") - .define("OPENSSL_ROOT_DIR", format!("{}", openssl_dir.display())) + // .define("OPENSSL_ROOT_DIR", format!("{}", openssl_dir.display())) .build() } From 525222b32f1decd06788040573883942e4f1357d Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Sat, 24 Aug 2024 17:30:34 +0200 Subject: [PATCH 14/37] Try 10 ssl --- .github/workflows/ci.yml | 2 +- build.rs | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bab8953..869197e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -129,7 +129,7 @@ jobs: - name: Add mingw${{ matrix.arch.mingw }} to PATH run: | echo "C:/msys64/mingw${{ matrix.arch.mingw }}/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8 - # echo "CMAKE_GENERATOR='MinGW Makefiles'" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 + echo "CMAKE_GENERATOR='MinGW Makefiles'" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 - uses: actions/checkout@v2 with: diff --git a/build.rs b/build.rs index 846e003..3877e1b 100644 --- a/build.rs +++ b/build.rs @@ -141,10 +141,14 @@ fn build_mgclient_windows() -> PathBuf { std::env::var("OPENSSL_LIB_DIR") .unwrap_or_else(|_| "C:\\Program Files\\OpenSSL-Win64\\lib".to_string()), ); - println!("cargo:rustc-link-search=native={}", openssl_dir.display()); - Config::new("mgclient") - // .define("OPENSSL_ROOT_DIR", format!("{}", openssl_dir.display())) - .build() + if openssl_dir.exists() { + println!("cargo:rustc-link-search=native={}", openssl_dir.display()); + Config::new("mgclient") + .define("OPENSSL_ROOT_DIR", format!("{}", openssl_dir.display())) + .build() + } else { + Config::new("mgclient").build() + } } fn main() { From 373ebe2445c1e6894e1dad673f7b1c6e5240a8f1 Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Sat, 24 Aug 2024 17:33:59 +0200 Subject: [PATCH 15/37] Try 11 ssl --- .github/workflows/ci.yml | 2 +- build.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 869197e..46250ee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -129,7 +129,7 @@ jobs: - name: Add mingw${{ matrix.arch.mingw }} to PATH run: | echo "C:/msys64/mingw${{ matrix.arch.mingw }}/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8 - echo "CMAKE_GENERATOR='MinGW Makefiles'" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 + echo "CMAKE_GENERATOR=MinGW Makefiles" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 - uses: actions/checkout@v2 with: diff --git a/build.rs b/build.rs index 3877e1b..15ec336 100644 --- a/build.rs +++ b/build.rs @@ -137,6 +137,7 @@ fn build_mgclient_linux() -> PathBuf { } fn build_mgclient_windows() -> PathBuf { + // NOTE: The intention with the default here is to help desktop Windows users let openssl_dir = PathBuf::from( std::env::var("OPENSSL_LIB_DIR") .unwrap_or_else(|_| "C:\\Program Files\\OpenSSL-Win64\\lib".to_string()), From bb2ae9b1da41429652670aa40ebb8e729875df9d Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Sat, 24 Aug 2024 17:37:19 +0200 Subject: [PATCH 16/37] Try 12 ssl --- .github/workflows/ci.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 46250ee..64df634 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -119,18 +119,22 @@ jobs: update: true install: git mingw-w64-${{ matrix.arch.msys }}-toolchain mingw-w64-${{ matrix.arch.msys }}-cmake mingw-w64-${{ matrix.arch.msys }}-openssl - - name: Debug + - name: Debug 1 run: | ls "C:/" ls "C:/msys64" ls "C:/msys64/mingw${{ matrix.arch.mingw }}" - ls "C:/msys64/mingw${{ matrix.arch.mingw }}/lib" + ls "C:/msys64/mingw${{ matrix.arch.mingw }}/lib" # -> empty - name: Add mingw${{ matrix.arch.mingw }} to PATH run: | echo "C:/msys64/mingw${{ matrix.arch.mingw }}/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8 echo "CMAKE_GENERATOR=MinGW Makefiles" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 + - name: Debug 2 + run: | + openssl version -a + - uses: actions/checkout@v2 with: submodules: true From fb7c9f6d674907e489991797f085e71b359b5aa1 Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Sat, 24 Aug 2024 17:41:15 +0200 Subject: [PATCH 17/37] Try 13 ssl --- .github/workflows/ci.yml | 14 ++++---------- build.rs | 3 ++- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 64df634..29c9814 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -119,21 +119,15 @@ jobs: update: true install: git mingw-w64-${{ matrix.arch.msys }}-toolchain mingw-w64-${{ matrix.arch.msys }}-cmake mingw-w64-${{ matrix.arch.msys }}-openssl - - name: Debug 1 + - name: Figure out where is openssl run: | - ls "C:/" - ls "C:/msys64" - ls "C:/msys64/mingw${{ matrix.arch.mingw }}" - ls "C:/msys64/mingw${{ matrix.arch.mingw }}/lib" # -> empty + openssl version -a - name: Add mingw${{ matrix.arch.mingw }} to PATH run: | echo "C:/msys64/mingw${{ matrix.arch.mingw }}/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8 - echo "CMAKE_GENERATOR=MinGW Makefiles" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 - - - name: Debug 2 - run: | - openssl version -a + # echo "CMAKE_GENERATOR=MinGW Makefiles" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 + echo "OPENSSL_LIB_DIR=C:/Program Files/OpenSSL/lib/engines-1_1" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 - uses: actions/checkout@v2 with: diff --git a/build.rs b/build.rs index 15ec336..148918c 100644 --- a/build.rs +++ b/build.rs @@ -137,7 +137,8 @@ fn build_mgclient_linux() -> PathBuf { } fn build_mgclient_windows() -> PathBuf { - // NOTE: The intention with the default here is to help desktop Windows users + // NOTE: The intention with the default here is to help desktop Windows users link OpenSSL + // default folder created when OpenSSL is manually installed. let openssl_dir = PathBuf::from( std::env::var("OPENSSL_LIB_DIR") .unwrap_or_else(|_| "C:\\Program Files\\OpenSSL-Win64\\lib".to_string()), From 8f6a78bc8d64aea3fa4caf66883c830d2aa06bb1 Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Sat, 24 Aug 2024 17:45:52 +0200 Subject: [PATCH 18/37] Try 14 ssl --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 29c9814..ff9de3f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -123,11 +123,11 @@ jobs: run: | openssl version -a - - name: Add mingw${{ matrix.arch.mingw }} to PATH + - name: Add mingw${{ matrix.arch.mingw }} to PATH and define OPENSSL_LIB_DIR run: | echo "C:/msys64/mingw${{ matrix.arch.mingw }}/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8 # echo "CMAKE_GENERATOR=MinGW Makefiles" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 - echo "OPENSSL_LIB_DIR=C:/Program Files/OpenSSL/lib/engines-1_1" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 + echo "OPENSSL_LIB_DIR=C:\\Program Files\\OpenSSL\\lib\\engines-1_1" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 - uses: actions/checkout@v2 with: From 451036872d3d7e782b69c95f381da7ce99c6c6f1 Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Sat, 24 Aug 2024 17:51:21 +0200 Subject: [PATCH 19/37] Try 15 ssl --- .github/workflows/ci.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ff9de3f..4ede92e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -133,6 +133,11 @@ jobs: with: submodules: true + - name: Debug + run: | + echo "$OPENSSL_LIB_DIR" + ls "$OPENSSL_LIB_DIR" + - name: Build the client run: | cargo build --release --target=${{ matrix.target }} From a99c4ed8efe911422341fd5c74fe45e21f88f959 Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Sat, 24 Aug 2024 18:00:05 +0200 Subject: [PATCH 20/37] Try 16 ssl --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4ede92e..e44fd02 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -127,7 +127,7 @@ jobs: run: | echo "C:/msys64/mingw${{ matrix.arch.mingw }}/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8 # echo "CMAKE_GENERATOR=MinGW Makefiles" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 - echo "OPENSSL_LIB_DIR=C:\\Program Files\\OpenSSL\\lib\\engines-1_1" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 + echo "OPENSSL_LIB_DIR=C:\\Program Files\\OpenSSL" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 - uses: actions/checkout@v2 with: From db452404d3f24f2f73344b834e8a7e0dfefcc05e Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Sat, 24 Aug 2024 18:07:20 +0200 Subject: [PATCH 21/37] Try 17 ssl --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e44fd02..26f91f4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -135,8 +135,7 @@ jobs: - name: Debug run: | - echo "$OPENSSL_LIB_DIR" - ls "$OPENSSL_LIB_DIR" + ls "C:\\Program Files\\OpenSSL\\lib" - name: Build the client run: | From adbad91f95387238abb70545f1451c7f869c3458 Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Sat, 24 Aug 2024 18:13:40 +0200 Subject: [PATCH 22/37] Try 18 ssl --- .github/workflows/ci.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 26f91f4..afa13a5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -123,20 +123,20 @@ jobs: run: | openssl version -a + - name: Figure out where is openssl + run: | + Get-ChildItem -Recurse -Name "libssl.a" + - name: Add mingw${{ matrix.arch.mingw }} to PATH and define OPENSSL_LIB_DIR run: | echo "C:/msys64/mingw${{ matrix.arch.mingw }}/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8 - # echo "CMAKE_GENERATOR=MinGW Makefiles" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 + echo "CMAKE_GENERATOR=MinGW Makefiles" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 echo "OPENSSL_LIB_DIR=C:\\Program Files\\OpenSSL" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 - uses: actions/checkout@v2 with: submodules: true - - name: Debug - run: | - ls "C:\\Program Files\\OpenSSL\\lib" - - name: Build the client run: | cargo build --release --target=${{ matrix.target }} From c341d5786ba8499f0894c5367a8b22b43ae5e5a7 Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Sat, 24 Aug 2024 18:17:07 +0200 Subject: [PATCH 23/37] Try 19 ssl --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index afa13a5..6b1dfe2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -125,12 +125,12 @@ jobs: - name: Figure out where is openssl run: | - Get-ChildItem -Recurse -Name "libssl.a" + Get-ChildItem -Recurse -Name "libssl.a" C: - name: Add mingw${{ matrix.arch.mingw }} to PATH and define OPENSSL_LIB_DIR run: | echo "C:/msys64/mingw${{ matrix.arch.mingw }}/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8 - echo "CMAKE_GENERATOR=MinGW Makefiles" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 + # echo "CMAKE_GENERATOR=MinGW Makefiles" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 echo "OPENSSL_LIB_DIR=C:\\Program Files\\OpenSSL" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 - uses: actions/checkout@v2 From 8380c25943bb7378fda79f51cc2c29a42771420a Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Sat, 24 Aug 2024 18:19:45 +0200 Subject: [PATCH 24/37] Try 20 ssl --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6b1dfe2..3644537 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -125,7 +125,7 @@ jobs: - name: Figure out where is openssl run: | - Get-ChildItem -Recurse -Name "libssl.a" C: + Get-ChildItem C: -Recurse -Name "libssl.a" - name: Add mingw${{ matrix.arch.mingw }} to PATH and define OPENSSL_LIB_DIR run: | From f844919e4b519c17673972ea72555ef02f1a1fb4 Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Sat, 24 Aug 2024 18:25:32 +0200 Subject: [PATCH 25/37] Try 21 ssl --- .github/workflows/ci.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3644537..b46acfc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -123,15 +123,16 @@ jobs: run: | openssl version -a - - name: Figure out where is openssl - run: | - Get-ChildItem C: -Recurse -Name "libssl.a" + # - name: Figure out where is openssl + # run: | + # Get-ChildItem C: -Recurse -Name "libssl.a" - name: Add mingw${{ matrix.arch.mingw }} to PATH and define OPENSSL_LIB_DIR run: | echo "C:/msys64/mingw${{ matrix.arch.mingw }}/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8 # echo "CMAKE_GENERATOR=MinGW Makefiles" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 - echo "OPENSSL_LIB_DIR=C:\\Program Files\\OpenSSL" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 + # echo "OPENSSL_LIB_DIR=C:\\Program Files\\OpenSSL" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 + echo "OPENSSL_LIB_DIR=C:/msys64/mingw${{ matrix.arch.mingw }}" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 - uses: actions/checkout@v2 with: From f515f8ceca127629dcea4a352f920051fdc9074b Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Sat, 24 Aug 2024 18:29:21 +0200 Subject: [PATCH 26/37] Try 22 ssl --- .github/workflows/ci.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b46acfc..cc3c6ea 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -121,17 +121,16 @@ jobs: - name: Figure out where is openssl run: | - openssl version -a + openssl version -a # NOTE: This gives non-MinGW SSL - # - name: Figure out where is openssl - # run: | - # Get-ChildItem C: -Recurse -Name "libssl.a" + - name: Figure out where is openssl + run: | + Get-ChildItem C: -Recurse -Name "libssl.dll.a" - name: Add mingw${{ matrix.arch.mingw }} to PATH and define OPENSSL_LIB_DIR run: | echo "C:/msys64/mingw${{ matrix.arch.mingw }}/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8 - # echo "CMAKE_GENERATOR=MinGW Makefiles" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 - # echo "OPENSSL_LIB_DIR=C:\\Program Files\\OpenSSL" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 + echo "CMAKE_GENERATOR=MinGW Makefiles" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 echo "OPENSSL_LIB_DIR=C:/msys64/mingw${{ matrix.arch.mingw }}" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 - uses: actions/checkout@v2 From 1faba59db16d8d2a2ea0e1113f2aeb3335c199d1 Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Sat, 24 Aug 2024 18:34:01 +0200 Subject: [PATCH 27/37] Try 23 ssl --- .github/workflows/ci.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cc3c6ea..7aec1d1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -119,19 +119,19 @@ jobs: update: true install: git mingw-w64-${{ matrix.arch.msys }}-toolchain mingw-w64-${{ matrix.arch.msys }}-cmake mingw-w64-${{ matrix.arch.msys }}-openssl - - name: Figure out where is openssl - run: | - openssl version -a # NOTE: This gives non-MinGW SSL + # - name: Figure out where is openssl + # run: | + # openssl version -a # NOTE: This gives non-MinGW SSL - - name: Figure out where is openssl - run: | - Get-ChildItem C: -Recurse -Name "libssl.dll.a" + # - name: Figure out where is openssl + # run: | + # Get-ChildItem C: -Recurse -Name "libssl.dll.a" - name: Add mingw${{ matrix.arch.mingw }} to PATH and define OPENSSL_LIB_DIR run: | - echo "C:/msys64/mingw${{ matrix.arch.mingw }}/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8 + # echo "C:/msys64/mingw${{ matrix.arch.mingw }}/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8 echo "CMAKE_GENERATOR=MinGW Makefiles" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 - echo "OPENSSL_LIB_DIR=C:/msys64/mingw${{ matrix.arch.mingw }}" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 + # echo "OPENSSL_LIB_DIR=C:/msys64/mingw${{ matrix.arch.mingw }}" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 - uses: actions/checkout@v2 with: From 18be18af0f5297c1374af16acb6ff9b4e80e792e Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Sat, 24 Aug 2024 18:39:49 +0200 Subject: [PATCH 28/37] Try 24 ssl --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7aec1d1..9cb253d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -127,11 +127,11 @@ jobs: # run: | # Get-ChildItem C: -Recurse -Name "libssl.dll.a" - - name: Add mingw${{ matrix.arch.mingw }} to PATH and define OPENSSL_LIB_DIR + - name: Define required environment variables run: | # echo "C:/msys64/mingw${{ matrix.arch.mingw }}/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8 echo "CMAKE_GENERATOR=MinGW Makefiles" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 - # echo "OPENSSL_LIB_DIR=C:/msys64/mingw${{ matrix.arch.mingw }}" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 + echo "OPENSSL_LIB_DIR=D:/a/_temp/msys64/mingw${{ matrix.arch.mingw }}" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 - uses: actions/checkout@v2 with: From b52a1b12930545834f7c4f580ca96af05d53647e Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Sat, 24 Aug 2024 18:46:12 +0200 Subject: [PATCH 29/37] Try 25 ssl --- .github/workflows/ci.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9cb253d..0e34b99 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -114,6 +114,7 @@ jobs: del rustup-init.exe - uses: msys2/setup-msys2@v2 + id: msys2 with: msystem: MINGW${{ matrix.arch.mingw }} update: true @@ -122,16 +123,19 @@ jobs: # - name: Figure out where is openssl # run: | # openssl version -a # NOTE: This gives non-MinGW SSL - # - name: Figure out where is openssl # run: | # Get-ChildItem C: -Recurse -Name "libssl.dll.a" + # echo "C:/msys64/mingw${{ matrix.arch.mingw }}/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8 + - name: Debug + run: | + ls "${{ steps.msys2.outputs.msys2-location }}/mingw64/lib" - name: Define required environment variables run: | - # echo "C:/msys64/mingw${{ matrix.arch.mingw }}/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8 echo "CMAKE_GENERATOR=MinGW Makefiles" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 - echo "OPENSSL_LIB_DIR=D:/a/_temp/msys64/mingw${{ matrix.arch.mingw }}" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 + # NOTE: https://github.com/msys2/setup-msys2?tab=readme-ov-file#msys2-location + echo "OPENSSL_LIB_DIR=${{ steps.msys2.outputs.msys2-location }}/mingw${{ matrix.arch.mingw }}" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 - uses: actions/checkout@v2 with: From a212ad5eef90d5df1fa5fa6a740ecb636db408a0 Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Sat, 24 Aug 2024 18:58:22 +0200 Subject: [PATCH 30/37] Try 26 ssl --- .github/workflows/ci.yml | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0e34b99..f830550 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -102,9 +102,14 @@ jobs: arch: - { mingw: 64, msys: x86_64 } runs-on: ${{ matrix.platform }} + # TODO(gitbuda): Maybe shell is a problem, under https://github.com/memgraph/mgclient/blob/master/.github/workflows/ci.yml + defaults: + run: + shell: msys2 {0} steps: - name: Install Rustup using win.rustup.rs + shell: pwsh run: | # Disable the download progress bar which can cause perf issues $ProgressPreference = "SilentlyContinue" @@ -114,19 +119,13 @@ jobs: del rustup-init.exe - uses: msys2/setup-msys2@v2 + # From https://github.com/msys2/setup-msys2?tab=readme-ov-file#msys2-location id: msys2 with: msystem: MINGW${{ matrix.arch.mingw }} update: true install: git mingw-w64-${{ matrix.arch.msys }}-toolchain mingw-w64-${{ matrix.arch.msys }}-cmake mingw-w64-${{ matrix.arch.msys }}-openssl - # - name: Figure out where is openssl - # run: | - # openssl version -a # NOTE: This gives non-MinGW SSL - # - name: Figure out where is openssl - # run: | - # Get-ChildItem C: -Recurse -Name "libssl.dll.a" - # echo "C:/msys64/mingw${{ matrix.arch.mingw }}/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8 - name: Debug run: | ls "${{ steps.msys2.outputs.msys2-location }}/mingw64/lib" @@ -134,7 +133,6 @@ jobs: - name: Define required environment variables run: | echo "CMAKE_GENERATOR=MinGW Makefiles" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 - # NOTE: https://github.com/msys2/setup-msys2?tab=readme-ov-file#msys2-location echo "OPENSSL_LIB_DIR=${{ steps.msys2.outputs.msys2-location }}/mingw${{ matrix.arch.mingw }}" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 - uses: actions/checkout@v2 From 48eb993941a3c87b4807d64e8e8a4e4bd8f7d5f8 Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Sat, 24 Aug 2024 19:00:44 +0200 Subject: [PATCH 31/37] Try 27 ssl --- .github/workflows/ci.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f830550..2c89831 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -126,11 +126,8 @@ jobs: update: true install: git mingw-w64-${{ matrix.arch.msys }}-toolchain mingw-w64-${{ matrix.arch.msys }}-cmake mingw-w64-${{ matrix.arch.msys }}-openssl - - name: Debug - run: | - ls "${{ steps.msys2.outputs.msys2-location }}/mingw64/lib" - - name: Define required environment variables + shell: pwsh run: | echo "CMAKE_GENERATOR=MinGW Makefiles" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 echo "OPENSSL_LIB_DIR=${{ steps.msys2.outputs.msys2-location }}/mingw${{ matrix.arch.mingw }}" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 From 41f3a24375ff4a1bc114fcd81d73674925204061 Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Sun, 25 Aug 2024 09:22:30 +0200 Subject: [PATCH 32/37] Try 28 ssl --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2c89831..6211ee7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -114,7 +114,7 @@ jobs: # Disable the download progress bar which can cause perf issues $ProgressPreference = "SilentlyContinue" Invoke-WebRequest https://win.rustup.rs/ -OutFile rustup-init.exe - .\rustup-init.exe -y --default-host=x86_64-pc-windows-msvc --default-toolchain=none + .\rustup-init.exe -y --default-host=x86_64-pc-windows-gnu --default-toolchain=none rustup target add ${{ matrix.target }} del rustup-init.exe From ca123ca35279d17811fde8552822fae17326d1a6 Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Sun, 25 Aug 2024 09:25:27 +0200 Subject: [PATCH 33/37] Try 29 ssl --- .github/workflows/ci.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6211ee7..34cd06e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -103,13 +103,13 @@ jobs: - { mingw: 64, msys: x86_64 } runs-on: ${{ matrix.platform }} # TODO(gitbuda): Maybe shell is a problem, under https://github.com/memgraph/mgclient/blob/master/.github/workflows/ci.yml - defaults: - run: - shell: msys2 {0} + # defaults: + # run: + # shell: msys2 {0} + # shell: pwsh steps: - name: Install Rustup using win.rustup.rs - shell: pwsh run: | # Disable the download progress bar which can cause perf issues $ProgressPreference = "SilentlyContinue" @@ -127,7 +127,6 @@ jobs: install: git mingw-w64-${{ matrix.arch.msys }}-toolchain mingw-w64-${{ matrix.arch.msys }}-cmake mingw-w64-${{ matrix.arch.msys }}-openssl - name: Define required environment variables - shell: pwsh run: | echo "CMAKE_GENERATOR=MinGW Makefiles" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 echo "OPENSSL_LIB_DIR=${{ steps.msys2.outputs.msys2-location }}/mingw${{ matrix.arch.mingw }}" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 From 4c9dbfa478f8d8fc178b508acc9349744c66262f Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Sun, 25 Aug 2024 09:33:00 +0200 Subject: [PATCH 34/37] Try 30 ssl --- .github/workflows/ci.yml | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 34cd06e..80c82f0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,5 +1,4 @@ name: CI - on: [push] jobs: @@ -9,11 +8,10 @@ jobs: platform: [ubuntu-20.04, ubuntu-22.04] mgversion: [2.19.0] runs-on: ${{ matrix.platform }} - steps: - name: Install system dependencies run: sudo apt-get install -y git cmake make gcc g++ libssl-dev - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: submodules: true @@ -55,19 +53,15 @@ jobs: run: | sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-* sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-* - - name: Install dependencies run: | yum install -y git cmake make gcc gcc-c++ openssl-devel epel-release clang - - name: Install rustup run: | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y - - uses: actions/checkout@v2 with: submodules: true - - name: Build the project run: | . "$HOME/.cargo/env" @@ -79,7 +73,6 @@ jobs: platform: [macos-latest] target: [x86_64-apple-darwin] runs-on: ${{ matrix.platform }} - steps: - name: Install Rustup run: | @@ -87,10 +80,9 @@ jobs: sh rustup-init.sh -y --default-toolchain none rustup target add ${{ matrix.target }} - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: submodules: true - - name: Build the client run: cargo build --release @@ -102,11 +94,11 @@ jobs: arch: - { mingw: 64, msys: x86_64 } runs-on: ${{ matrix.platform }} - # TODO(gitbuda): Maybe shell is a problem, under https://github.com/memgraph/mgclient/blob/master/.github/workflows/ci.yml + # TODO(gitbuda): Maybe shell is a problem, https://github.com/memgraph/mgclient/blob/master/.github/workflows/ci.yml # defaults: # run: # shell: msys2 {0} - # shell: pwsh + # shell: pwsh steps: - name: Install Rustup using win.rustup.rs @@ -128,13 +120,13 @@ jobs: - name: Define required environment variables run: | + echo "C:/msys64/mingw${{ matrix.arch.mingw }}/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8 echo "CMAKE_GENERATOR=MinGW Makefiles" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 echo "OPENSSL_LIB_DIR=${{ steps.msys2.outputs.msys2-location }}/mingw${{ matrix.arch.mingw }}" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: submodules: true - - name: Build the client run: | cargo build --release --target=${{ matrix.target }} From 0fafc9bf482c4c3455ec68b2521f20f83ce0e57e Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Sun, 25 Aug 2024 09:46:20 +0200 Subject: [PATCH 35/37] Try 31 ssl --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 80c82f0..3cf060b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -92,7 +92,7 @@ jobs: platform: [windows-2022] target: [x86_64-pc-windows-gnu] arch: - - { mingw: 64, msys: x86_64 } + - { mingw: 32, msys: x86_64 } runs-on: ${{ matrix.platform }} # TODO(gitbuda): Maybe shell is a problem, https://github.com/memgraph/mgclient/blob/master/.github/workflows/ci.yml # defaults: From 0d2bcb5c1f64c28119051ff205a38087959b1e4a Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Sun, 25 Aug 2024 09:54:00 +0200 Subject: [PATCH 36/37] Try 32 ssl --- .github/workflows/ci.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3cf060b..86afe4e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -94,11 +94,6 @@ jobs: arch: - { mingw: 32, msys: x86_64 } runs-on: ${{ matrix.platform }} - # TODO(gitbuda): Maybe shell is a problem, https://github.com/memgraph/mgclient/blob/master/.github/workflows/ci.yml - # defaults: - # run: - # shell: msys2 {0} - # shell: pwsh steps: - name: Install Rustup using win.rustup.rs @@ -116,7 +111,11 @@ jobs: with: msystem: MINGW${{ matrix.arch.mingw }} update: true - install: git mingw-w64-${{ matrix.arch.msys }}-toolchain mingw-w64-${{ matrix.arch.msys }}-cmake mingw-w64-${{ matrix.arch.msys }}-openssl + install: >- + git + mingw-w${{ matrix.arch.mingw }}-${{ matrix.arch.msys }}-toolchain + mingw-w${{ matrix.arch.mingw }}-${{ matrix.arch.msys }}-cmake + mingw-w${{ matrix.arch.mingw }}-${{ matrix.arch.msys }}-openssl - name: Define required environment variables run: | From c3e0581b184fdc03c22a566b53ba6249e4c05e25 Mon Sep 17 00:00:00 2001 From: antejavor Date: Mon, 10 Nov 2025 10:55:28 +0100 Subject: [PATCH 37/37] Update build.rs and ci.yaml from master. --- .github/workflows/ci.yml | 91 ++++++++--------------- build.rs | 157 ++++++++++++++++++++++++++++++++------- 2 files changed, 162 insertions(+), 86 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 86afe4e..05c3e54 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,13 +1,17 @@ name: CI -on: [push] + +on: + pull_request: + branches: [ master ] jobs: build_and_test_ubuntu: strategy: matrix: - platform: [ubuntu-20.04, ubuntu-22.04] - mgversion: [2.19.0] + platform: [ubuntu-24.04] + mgversion: [latest] runs-on: ${{ matrix.platform }} + steps: - name: Install system dependencies run: sudo apt-get install -y git cmake make gcc g++ libssl-dev @@ -15,23 +19,8 @@ jobs: with: submodules: true - - name: Cache Memgraph Docker image - id: cache-memgraph-community-docker - uses: actions/cache@v1 - with: - path: ~/memgraph - key: cache-memgraph-v${{ matrix.mgversion }}-docker-image - - name: Download Memgraph Docker image - if: steps.cache-memgraph-community-docker.outputs.cache-hit != 'true' - run: | - mkdir ~/memgraph - curl -L https://download.memgraph.com/memgraph/v${{ matrix.mgversion }}/docker/memgraph-${{ matrix.mgversion }}-docker.tar.gz > ~/memgraph/memgraph-docker.tar.gz - - name: Load Memgraph Docker image - run: docker load -i ~/memgraph/memgraph-docker.tar.gz - - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable + - name: Set up Rust toolchain + uses: dtolnay/rust-toolchain@stable - name: Run rust linter run: cargo clippy - name: Run rust formatter @@ -40,7 +29,7 @@ jobs: run: cargo build --verbose - name: Run Memgraph run: | - docker run -d -p 7687:7687 memgraph/memgraph --telemetry-enabled=False + docker run -d -p 7687:7687 memgraph/memgraph:${{ matrix.mgversion }} --telemetry-enabled=False - name: Run test run: cargo test @@ -53,15 +42,19 @@ jobs: run: | sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-* sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-* + - name: Install dependencies run: | yum install -y git cmake make gcc gcc-c++ openssl-devel epel-release clang + - name: Install rustup run: | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y - - uses: actions/checkout@v2 + + - uses: actions/checkout@v4 with: submodules: true + - name: Build the project run: | . "$HOME/.cargo/env" @@ -73,6 +66,7 @@ jobs: platform: [macos-latest] target: [x86_64-apple-darwin] runs-on: ${{ matrix.platform }} + steps: - name: Install Rustup run: | @@ -83,49 +77,30 @@ jobs: - uses: actions/checkout@v4 with: submodules: true + - name: Build the client run: cargo build --release build_windows: - strategy: - matrix: - platform: [windows-2022] - target: [x86_64-pc-windows-gnu] - arch: - - { mingw: 32, msys: x86_64 } - runs-on: ${{ matrix.platform }} + runs-on: windows-latest steps: - - name: Install Rustup using win.rustup.rs - run: | - # Disable the download progress bar which can cause perf issues - $ProgressPreference = "SilentlyContinue" - Invoke-WebRequest https://win.rustup.rs/ -OutFile rustup-init.exe - .\rustup-init.exe -y --default-host=x86_64-pc-windows-gnu --default-toolchain=none - rustup target add ${{ matrix.target }} - del rustup-init.exe - - - uses: msys2/setup-msys2@v2 - # From https://github.com/msys2/setup-msys2?tab=readme-ov-file#msys2-location - id: msys2 + - uses: actions/checkout@v4 with: - msystem: MINGW${{ matrix.arch.mingw }} - update: true - install: >- - git - mingw-w${{ matrix.arch.mingw }}-${{ matrix.arch.msys }}-toolchain - mingw-w${{ matrix.arch.mingw }}-${{ matrix.arch.msys }}-cmake - mingw-w${{ matrix.arch.mingw }}-${{ matrix.arch.msys }}-openssl - - - name: Define required environment variables - run: | - echo "C:/msys64/mingw${{ matrix.arch.mingw }}/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8 - echo "CMAKE_GENERATOR=MinGW Makefiles" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 - echo "OPENSSL_LIB_DIR=${{ steps.msys2.outputs.msys2-location }}/mingw${{ matrix.arch.mingw }}" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 + submodules: true - - uses: actions/checkout@v4 + - name: Set up Rust toolchain + uses: dtolnay/rust-toolchain@stable with: - submodules: true - - name: Build the client + targets: x86_64-pc-windows-msvc + + - name: Install OpenSSL via vcpkg run: | - cargo build --release --target=${{ matrix.target }} + vcpkg install openssl:x64-windows-static + + - name: Build the client + run: cargo build --release --target=x86_64-pc-windows-msvc + env: + OPENSSL_LIB_DIR: "C:\\vcpkg\\installed\\x64-windows-static\\lib" + OPENSSL_INCLUDE_DIR: "C:\\vcpkg\\installed\\x64-windows-static\\include" + OPENSSL_STATIC: "1" diff --git a/build.rs b/build.rs index 148918c..329d663 100644 --- a/build.rs +++ b/build.rs @@ -16,6 +16,8 @@ extern crate bindgen; use cmake::Config; use std::env; +use std::error::Error; +use std::fmt::Display; use std::path::{Path, PathBuf}; use std::process::Command; @@ -27,16 +29,35 @@ enum HostType { Unknown, } +#[derive(Debug)] +enum BuildError { + IoError(String), + OpenSSL(String), + Unknown(String), +} + +impl Display for BuildError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + BuildError::IoError(msg) => write!(f, "Failed to execute shell command: {}", msg), + BuildError::OpenSSL(msg) => write!(f, "OpenSSL Error: {}", msg), + BuildError::Unknown(msg) => write!(f, "Error: {}", msg), + } + } +} + +impl Error for BuildError {} + // NOTE: The code here is equivalent to [rust-openssl](https://github.com/sfackler/rust-openssl). // NOTE: We have to build mgclient and link the rust binary with the same SSL and Crypto libs. -fn build_mgclient_macos() -> PathBuf { +fn build_mgclient_macos() -> Result { println!("MacOS detected. We will check if you have either the MacPorts or Homebrew package managers."); println!("Checking for MacPorts..."); let output = Command::new("/usr/bin/command") .args(["-v", "port"]) .output() - .expect("Failed to execute shell command: '/usr/bin/command -v port'") + .map_err(|err| BuildError::IoError(format!("'/usr/bin/command -v port': {}", err)))? .stdout; let port_path = String::from_utf8(output).unwrap(); if !port_path.is_empty() { @@ -73,33 +94,50 @@ fn build_mgclient_macos() -> PathBuf { // With MacPorts, you don't need to pass in the OPENSSL_ROOT_DIR, // OPENSSL_CRYPTO_LIBRARY, and OPENSSL_SSL_LIBRARY options to CMake, PkgConfig // should take care of setting those variables. - Config::new("mgclient").build() + let path = Config::new("mgclient").build(); + Ok(path) } else { println!("Macports not found."); println!("Checking for Homebrew..."); let output = Command::new("/usr/bin/command") .args(["-v", "brew"]) .output() - .expect("Failed to execute shell command: '/usr/bin/command -v brew'") + .map_err(|err| BuildError::IoError(format!("'/usr/bin/command -v brew': {}", err)))? .stdout; let brew_path = String::from_utf8(output).unwrap(); if brew_path.is_empty() { println!("Homebrew not found."); - panic!( + BuildError::Unknown( "We did not detect either MacPorts or Homebrew on your machine. We cannot proceed." + .to_string(), ); } else { println!("'brew' executable detected at {:?}", &brew_path); println!("Proceeding with installation assuming Homebrew is your package manager"); } + let path_openssl = if cfg!(target_arch = "aarch64") { - "/opt/homebrew/Cellar/openssl@1.1" + "/opt/homebrew/Cellar/openssl@3" } else { - "/usr/local/Cellar/openssl@1.1" + "/usr/local/Cellar/openssl@3" }; + println!("Found OpenSSL at path: {}", path_openssl); + let mut openssl_dirs = std::fs::read_dir(PathBuf::new().join(path_openssl)) - .unwrap() - .map(|r| r.unwrap().path()) + .map_err(|err| { + BuildError::OpenSSL(format!("Failed to read OpenSSL directory: '{}'", err)) + })? + .filter_map(|r| match r { + Ok(entry) => Some(entry.path()), + Err(err) => { + // Return the error as a BuildError + Err(BuildError::OpenSSL(format!( + "Failed to read directory entry: '{}'", + err + ))) + .ok() + } + }) .collect::>(); openssl_dirs.sort_by(|a, b| { let a_time = a.metadata().unwrap().modified().unwrap(); @@ -112,8 +150,12 @@ fn build_mgclient_macos() -> PathBuf { openssl_root_path.join("lib").display() ); let openssl_root = openssl_dirs[0].clone(); - Config::new("mgclient") + let path = Config::new("mgclient") .define("OPENSSL_ROOT_DIR", format!("{}", openssl_root.display())) + .define( + "OPENSSL_INCLUDE_DIR", + format!("{}", openssl_root.join("include").display()), + ) .define( "OPENSSL_CRYPTO_LIBRARY", format!( @@ -128,32 +170,75 @@ fn build_mgclient_macos() -> PathBuf { openssl_root.join("lib").join("libssl.dylib").display() ), ) - .build() + .build(); + + Ok(path) } } -fn build_mgclient_linux() -> PathBuf { - Config::new("mgclient").build() +fn build_mgclient_linux() -> Result { + let path = Config::new("mgclient").build(); + Ok(path) } -fn build_mgclient_windows() -> PathBuf { - // NOTE: The intention with the default here is to help desktop Windows users link OpenSSL - // default folder created when OpenSSL is manually installed. - let openssl_dir = PathBuf::from( +fn build_mgclient_windows() -> Result { + let openssl_lib_dir = PathBuf::from( std::env::var("OPENSSL_LIB_DIR") .unwrap_or_else(|_| "C:\\Program Files\\OpenSSL-Win64\\lib".to_string()), ); - if openssl_dir.exists() { - println!("cargo:rustc-link-search=native={}", openssl_dir.display()); - Config::new("mgclient") - .define("OPENSSL_ROOT_DIR", format!("{}", openssl_dir.display())) - .build() + let openssl_include_dir = PathBuf::from( + std::env::var("OPENSSL_INCLUDE_DIR") + .unwrap_or_else(|_| "C:\\Program Files\\OpenSSL-Win64\\include".to_string()), + ); + let openssl_root_dir = openssl_lib_dir.parent().unwrap_or(&openssl_lib_dir); + + println!( + "cargo:rustc-link-search=native={}", + openssl_lib_dir.display() + ); + + // Check if we're using vcpkg (static libraries) + let is_vcpkg = openssl_lib_dir.to_string_lossy().contains("vcpkg"); + let (crypto_lib, ssl_lib) = if is_vcpkg { + // vcpkg uses different library names for static builds + ( + format!("{}\\libcrypto.lib", openssl_lib_dir.display()), + format!("{}\\libssl.lib", openssl_lib_dir.display()), + ) } else { - Config::new("mgclient").build() + // Standard OpenSSL installation + ( + format!("{}\\libcrypto.lib", openssl_lib_dir.display()), + format!("{}\\libssl.lib", openssl_lib_dir.display()), + ) + }; + + let mut config = Config::new("mgclient"); + config + .define( + "OPENSSL_ROOT_DIR", + format!("{}", openssl_root_dir.display()), + ) + .define( + "OPENSSL_INCLUDE_DIR", + format!("{}", openssl_include_dir.display()), + ) + .define("OPENSSL_CRYPTO_LIBRARY", crypto_lib) + .define("OPENSSL_SSL_LIBRARY", ssl_lib); + + // If using static OpenSSL (vcpkg), configure for static linking + if is_vcpkg { + config.define("OPENSSL_USE_STATIC_LIBS", "TRUE"); + // Add system libraries that static OpenSSL depends on + config.define("CMAKE_EXE_LINKER_FLAGS", "/DEFAULTLIB:crypt32.lib /DEFAULTLIB:ws2_32.lib /DEFAULTLIB:user32.lib /DEFAULTLIB:advapi32.lib"); + config.define("CMAKE_SHARED_LINKER_FLAGS", "/DEFAULTLIB:crypt32.lib /DEFAULTLIB:ws2_32.lib /DEFAULTLIB:user32.lib /DEFAULTLIB:advapi32.lib"); } + + let path = config.build(); + Ok(path) } -fn main() { +fn main() -> Result<(), BuildError> { let host_type = if cfg!(target_os = "linux") { HostType::Linux } else if cfg!(target_os = "windows") { @@ -169,8 +254,8 @@ fn main() { HostType::Windows => build_mgclient_windows(), HostType::MacOS => build_mgclient_macos(), HostType::Linux => build_mgclient_linux(), - HostType::Unknown => panic!("Unknown operating system"), - }; + HostType::Unknown => Err(BuildError::Unknown("Unknown operating system".to_string())), + }?; let mgclient_h = mgclient_out.join("include").join("mgclient.h"); let mgclient_export_h = mgclient_out.join("include").join("mgclient-export.h"); @@ -209,8 +294,22 @@ fn main() { println!("cargo:rustc-link-lib=dylib=ssl"); } HostType::Windows => { - println!("cargo:rustc-link-lib=dylib=libcrypto"); - println!("cargo:rustc-link-lib=dylib=libssl"); + // Check if we're using static OpenSSL (vcpkg) + let openssl_static = std::env::var("OPENSSL_STATIC").unwrap_or_default() == "1"; + if openssl_static { + // Static linking - link with static libraries and system dependencies + println!("cargo:rustc-link-lib=static=libcrypto"); + println!("cargo:rustc-link-lib=static=libssl"); + // Windows system libraries required by static OpenSSL + println!("cargo:rustc-link-lib=crypt32"); + println!("cargo:rustc-link-lib=ws2_32"); + println!("cargo:rustc-link-lib=user32"); + println!("cargo:rustc-link-lib=advapi32"); + } else { + // Dynamic linking + println!("cargo:rustc-link-lib=dylib=libcrypto"); + println!("cargo:rustc-link-lib=dylib=libssl"); + } } HostType::MacOS => { println!("cargo:rustc-link-lib=dylib=crypto"); @@ -218,4 +317,6 @@ fn main() { } HostType::Unknown => panic!("Unknown operating system"), } + + Ok(()) }