Skip to content

Commit c7db486

Browse files
authored
feat: modernize to Rust edition 2024 (#74)
* feat: modernize to Rust edition 2024 Ignoring the CentOS build, we will deprecate it.
1 parent 4c46a89 commit c7db486

File tree

10 files changed

+714
-338
lines changed

10 files changed

+714
-338
lines changed

.github/workflows/ci.yml

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

3-
on:
3+
on:
44
pull_request:
55
branches: [ master ]
66

@@ -13,14 +13,17 @@ jobs:
1313
runs-on: ${{ matrix.platform }}
1414

1515
steps:
16-
- name: Install system dependencies
17-
run: sudo apt-get install -y git cmake make gcc g++ libssl-dev
18-
- uses: actions/checkout@v4
16+
- uses: actions/checkout@v5
1917
with:
2018
submodules: true
2119

20+
- name: Install system dependencies
21+
run: sudo apt-get install -y git cmake make gcc g++ libssl-dev
22+
2223
- name: Set up Rust toolchain
2324
uses: dtolnay/rust-toolchain@stable
25+
with:
26+
components: clippy, rustfmt
2427
- name: Run rust linter
2528
run: cargo clippy
2629
- name: Run rust formatter
@@ -35,9 +38,13 @@ jobs:
3538

3639
build_centos:
3740
runs-on: ubuntu-latest
38-
container:
41+
container:
3942
image: centos:8
4043
steps:
44+
- uses: actions/checkout@v5
45+
with:
46+
submodules: true
47+
4148
- name: Modify repo files of centos image
4249
run: |
4350
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
@@ -47,18 +54,13 @@ jobs:
4754
run: |
4855
yum install -y git cmake make gcc gcc-c++ openssl-devel epel-release clang
4956
50-
- name: Install rustup
51-
run: |
52-
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
53-
54-
- uses: actions/checkout@v4
57+
- name: Set up Rust toolchain
58+
uses: dtolnay/rust-toolchain@stable
5559
with:
56-
submodules: true
60+
components: clippy, rustfmt
5761

5862
- name: Build the project
59-
run: |
60-
. "$HOME/.cargo/env"
61-
cargo build --release
63+
run: cargo build --release
6264

6365
build_macos:
6466
strategy:
@@ -68,15 +70,15 @@ jobs:
6870
runs-on: ${{ matrix.platform }}
6971

7072
steps:
71-
- name: Install Rustup
72-
run: |
73-
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup-init.sh
74-
sh rustup-init.sh -y --default-toolchain none
75-
rustup target add ${{ matrix.target }}
73+
- uses: actions/checkout@v5
74+
with:
75+
submodules: true
7676

77-
- uses: actions/checkout@v4
77+
- name: Set up Rust toolchain
78+
uses: dtolnay/rust-toolchain@stable
7879
with:
79-
submodules: true
80+
targets: ${{ matrix.target }}
81+
components: clippy, rustfmt
8082

8183
- name: Build the client
8284
run: cargo build --release
@@ -85,19 +87,20 @@ jobs:
8587
runs-on: windows-latest
8688

8789
steps:
88-
- uses: actions/checkout@v4
90+
- uses: actions/checkout@v5
8991
with:
9092
submodules: true
9193

9294
- name: Set up Rust toolchain
9395
uses: dtolnay/rust-toolchain@stable
9496
with:
9597
targets: x86_64-pc-windows-msvc
98+
components: clippy, rustfmt
9699

97100
- name: Install OpenSSL via vcpkg
98101
run: |
99102
vcpkg install openssl:x64-windows-static
100-
103+
101104
- name: Build the client
102105
run: cargo build --release --target=x86_64-pc-windows-msvc
103106
env:

Cargo.toml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
11
[package]
22
name = "rsmgclient"
3-
version = "2.0.3"
3+
version = "3.0.0"
44
description = "Memgraph database adapter for Rust programming language."
55
authors = ["Memgraph Contributors <[email protected]>"]
66
license = "Apache-2.0"
77
homepage = "https://memgraph.com"
88
repository = "https://github.com/memgraph/rsmgclient"
99
readme = "README.md"
1010
documentation = "https://docs.rs/rsmgclient"
11-
edition = "2018"
11+
edition = "2024"
1212
keywords = ["memgraph", "client", "driver", "database-adapter"]
1313
categories = ["database", "api-bindings"]
1414
exclude = [
1515
".github/*"
1616
]
1717

1818
[dependencies]
19-
maplit = "1.0.2"
20-
chrono = "0.4.19"
19+
maplit = "1.0"
20+
chrono = "0.4"
21+
chrono-tz = "0.10"
22+
thiserror = "2.0"
2123

2224
[dev-dependencies]
2325
libc = "0.2"
24-
serial_test = "0.4.0"
25-
serde_json = "1.0.57"
26+
serial_test = "3.2"
27+
serde_json = "1.0"
2628

2729
[build-dependencies]
28-
bindgen = "0.68.1"
29-
cmake = "0.1.51"
30+
bindgen = "0.72"
31+
cmake = "0.1"
3032

3133
[dev-dependencies.cargo-husky]
3234
version = "1"

benches/connection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::{thread, time};
77

88
use serde_json::json;
99
use std::collections::HashMap;
10-
use std::fs::{create_dir_all, OpenOptions};
10+
use std::fs::{OpenOptions, create_dir_all};
1111
use std::io::prelude::*;
1212
use std::path::Path;
1313

build.rs

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,17 @@ impl Error for BuildError {}
5252
// NOTE: We have to build mgclient and link the rust binary with the same SSL and Crypto libs.
5353

5454
fn build_mgclient_macos() -> Result<PathBuf, BuildError> {
55-
println!("MacOS detected. We will check if you have either the MacPorts or Homebrew package managers.");
55+
println!(
56+
"MacOS detected. We will check if you have either the MacPorts or Homebrew package managers."
57+
);
5658
println!("Checking for MacPorts...");
5759
let output = Command::new("/usr/bin/command")
5860
.args(["-v", "port"])
5961
.output()
6062
.map_err(|err| BuildError::IoError(format!("'/usr/bin/command -v port': {}", err)))?
6163
.stdout;
62-
let port_path = String::from_utf8(output).unwrap();
64+
let port_path = String::from_utf8(output)
65+
.map_err(|err| BuildError::Unknown(format!("Invalid UTF-8 in port path: {}", err)))?;
6366
if !port_path.is_empty() {
6467
let port_path = &port_path[..port_path.len() - 1];
6568
println!(
@@ -72,17 +75,19 @@ fn build_mgclient_macos() -> Result<PathBuf, BuildError> {
7275
Command::new(port_path)
7376
.args(["installed", "openssl"])
7477
.output()
75-
.expect("Failed to execute shell command 'port installed openssl'")
78+
.map_err(|err| BuildError::IoError(format!("'port installed openssl': {}", err)))?
7679
.stdout,
7780
)
78-
.unwrap();
81+
.map_err(|err| BuildError::Unknown(format!("Invalid UTF-8 in port output: {}", err)))?;
7982
if output == "None of the specified ports are installed.\n" {
80-
panic!("The openssl port does not seem to be installed! Please install it using 'port install openssl'.");
83+
panic!(
84+
"The openssl port does not seem to be installed! Please install it using 'port install openssl'."
85+
);
8186
}
8287
let openssl_lib_dir = port_binary_path
8388
.ancestors()
8489
.nth(2)
85-
.unwrap()
90+
.ok_or_else(|| BuildError::Unknown("Unable to find port parent directory".to_string()))?
8691
.join("libexec")
8792
.join("openssl3")
8893
.join("lib");
@@ -104,13 +109,14 @@ fn build_mgclient_macos() -> Result<PathBuf, BuildError> {
104109
.output()
105110
.map_err(|err| BuildError::IoError(format!("'/usr/bin/command -v brew': {}", err)))?
106111
.stdout;
107-
let brew_path = String::from_utf8(output).unwrap();
112+
let brew_path = String::from_utf8(output)
113+
.map_err(|err| BuildError::Unknown(format!("Invalid UTF-8 in brew path: {}", err)))?;
108114
if brew_path.is_empty() {
109115
println!("Homebrew not found.");
110-
BuildError::Unknown(
116+
return Err(BuildError::Unknown(
111117
"We did not detect either MacPorts or Homebrew on your machine. We cannot proceed."
112118
.to_string(),
113-
);
119+
));
114120
} else {
115121
println!("'brew' executable detected at {:?}", &brew_path);
116122
println!("Proceeding with installation assuming Homebrew is your package manager");
@@ -140,9 +146,15 @@ fn build_mgclient_macos() -> Result<PathBuf, BuildError> {
140146
})
141147
.collect::<Vec<PathBuf>>();
142148
openssl_dirs.sort_by(|a, b| {
143-
let a_time = a.metadata().unwrap().modified().unwrap();
144-
let b_time = b.metadata().unwrap().modified().unwrap();
145-
b_time.cmp(&a_time)
149+
// If we can't get metadata, treat as older file (sort to end)
150+
let a_time = a.metadata().ok().and_then(|m| m.modified().ok());
151+
let b_time = b.metadata().ok().and_then(|m| m.modified().ok());
152+
match (b_time, a_time) {
153+
(Some(b), Some(a)) => b.cmp(&a),
154+
(Some(_), None) => std::cmp::Ordering::Less,
155+
(None, Some(_)) => std::cmp::Ordering::Greater,
156+
(None, None) => std::cmp::Ordering::Equal,
157+
}
146158
});
147159
let openssl_root_path = openssl_dirs[0].clone();
148160
println!(
@@ -268,10 +280,14 @@ fn main() -> Result<(), BuildError> {
268280
.header(format!("{}", mgclient_export_h.display()))
269281
.header(format!("{}", mgclient_mgvalue_h.display()))
270282
.clang_arg(format!("-I{}", mgclient_out.join("include").display()))
271-
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
283+
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
284+
.generate_cstr(true)
272285
.generate()
273286
.expect("Unable to generate bindings");
274-
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
287+
let out_path =
288+
PathBuf::from(env::var("OUT_DIR").map_err(|_| {
289+
BuildError::Unknown("OUT_DIR environment variable not set".to_string())
290+
})?);
275291
bindings
276292
.write_to_file(out_path.join("bindings.rs"))
277293
.expect("Couldn't write bindings!");

src/bindings/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
// limitations under the License.
1414

1515
#![allow(
16-
dead_code,
1716
non_upper_case_globals,
1817
non_camel_case_types,
1918
non_snake_case,

0 commit comments

Comments
 (0)