Skip to content

Commit 5b5e2b4

Browse files
authored
ref(relay): Migrate to Rust Edition 2024 (#4705)
Mostly done by hand: - `#[no_mangle]` -> `#[unsafe(no_mangle)]` - `unsafe fn foo { ... some_unsafe_code() }` -> `unsafe fn foo { ... unsafe { some_unsafe_code() } }` (mostly in FFI) - `env::*` is unsafe now, just put them into an unsafe block for now, this was already in 2021 unsafe, just not marked as such - `Foo(ref mut bar)` -> `Foo(bar)` (a lot of those) - Updated `cbindgen` (old version produced edition incompatible code)
1 parent 4dde4af commit 5b5e2b4

File tree

233 files changed

+1047
-909
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

233 files changed

+1047
-909
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
**Internal**:
1818

1919
- Remove threads with 1 non-idle sample in profiling chunks. ([#4694](https://github.com/getsentry/relay/pull/4694))
20+
- Migrate all Rust workspace crates to edition 2024. ([#4705](https://github.com/getsentry/relay/pull/4705))
2021

2122
## 25.4.0
2223

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ axum-server = "0.7.1"
8080
arc-swap = "1.7.1"
8181
async-trait = "0.1.83"
8282
backoff = "0.4.0"
83-
bindgen = "0.70.1"
83+
bindgen = "0.71.1"
8484
brotli = "6.0.0"
8585
bytecount = "0.6.8"
8686
bytes = "1.10.1"

relay-auth/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description = "Authentication and crypto for Relay"
55
homepage = "https://getsentry.github.io/relay/"
66
repository = "https://github.com/getsentry/relay"
77
version = "25.4.0"
8-
edition = "2021"
8+
edition = "2024"
99
license-file = "../LICENSE.md"
1010
publish = false
1111
build = "build.rs"

relay-auth/src/lib.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use data_encoding::BASE64URL_NOPAD;
3030
use ed25519_dalek::{Signer, Verifier};
3131
use hmac::{Hmac, Mac};
3232
use rand::rngs::OsRng;
33-
use rand::{thread_rng, RngCore};
33+
use rand::{RngCore, thread_rng};
3434
use relay_common::time::UnixTimestamp;
3535
use serde::de::DeserializeOwned;
3636
use serde::{Deserialize, Serialize};
@@ -706,9 +706,9 @@ mod tests {
706706
"OvXFVm1tIUi8xDTuyHX1SSqdMc8nCt2qU9IUaH5p7oU"
707707
);
708708
assert_eq!(
709-
format!("{sk:#}"),
710-
"OvXFVm1tIUi8xDTuyHX1SSqdMc8nCt2qU9IUaH5p7oUk5pHZsdnfXNiMWiMLtSE86J3N9Peo5CBP1YQHDUkApQ"
711-
);
709+
format!("{sk:#}"),
710+
"OvXFVm1tIUi8xDTuyHX1SSqdMc8nCt2qU9IUaH5p7oUk5pHZsdnfXNiMWiMLtSE86J3N9Peo5CBP1YQHDUkApQ"
711+
);
712712
assert_eq!(
713713
pk.to_string(),
714714
"JOaR2bHZ31zYjFojC7UhPOidzfT3qOQgT9WEBw1JAKU"
@@ -755,8 +755,7 @@ mod tests {
755755
let sig = sk.sign(data);
756756
assert!(pk.verify(data, &sig));
757757

758-
let bad_sig =
759-
"jgubwSf2wb2wuiRpgt2H9_bdDSMr88hXLp5zVuhbr65EGkSxOfT5ILIWr623twLgLd0bDgHg6xzOaUCX7XvUCw";
758+
let bad_sig = "jgubwSf2wb2wuiRpgt2H9_bdDSMr88hXLp5zVuhbr65EGkSxOfT5ILIWr623twLgLd0bDgHg6xzOaUCX7XvUCw";
760759
assert!(!pk.verify(data, bad_sig));
761760
}
762761

relay-base-schema/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description = "Basic types for Relay's API schema used across multiple services"
55
homepage = "https://getsentry.github.io/relay/"
66
repository = "https://github.com/getsentry/relay"
77
version = "25.4.0"
8-
edition = "2021"
8+
edition = "2024"
99
license-file = "../LICENSE.md"
1010
publish = false
1111

relay-base-schema/src/metrics/mri.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,7 @@ mod tests {
463463
fn test_normalize_name_length() {
464464
let long_mri = "c:custom/ThisIsACharacterLongStringForTestingPurposesToEnsureThatWeHaveEnoughCharactersToWorkWithAndToCheckIfOurFunctionProperlyHandlesSlicingAndNormalizationWithoutErrors";
465465
assert_eq!(
466-
MetricResourceIdentifier::parse(long_mri)
467-
.unwrap()
468-
.name,
466+
MetricResourceIdentifier::parse(long_mri).unwrap().name,
469467
"ThisIsACharacterLongStringForTestingPurposesToEnsureThatWeHaveEnoughCharactersToWorkWithAndToCheckIfOurFunctionProperlyHandlesSlicingAndNormalizationW"
470468
);
471469

relay-cabi/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ authors = ["Sentry <[email protected]>"]
55
homepage = "https://getsentry.github.io/relay/"
66
repository = "https://github.com/getsentry/relay"
77
description = "Exposes some internals of the relay to C."
8-
edition = "2021"
8+
edition = "2024"
99
license-file = "../LICENSE.md"
1010
publish = false
1111

relay-cabi/src/auth.rs

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use chrono::Duration;
22
use relay_auth::{
3-
generate_key_pair, generate_relay_id, PublicKey, RegisterRequest, RegisterResponse, RelayId,
4-
RelayVersion, SecretKey,
3+
PublicKey, RegisterRequest, RegisterResponse, RelayId, RelayVersion, SecretKey,
4+
generate_key_pair, generate_relay_id,
55
};
66
use serde::Serialize;
77

@@ -26,45 +26,45 @@ pub struct RelayKeyPair {
2626
pub struct RelayRegisterRequest;
2727

2828
/// Parses a public key from a string.
29-
#[no_mangle]
29+
#[unsafe(no_mangle)]
3030
#[relay_ffi::catch_unwind]
3131
pub unsafe extern "C" fn relay_publickey_parse(s: *const RelayStr) -> *mut RelayPublicKey {
32-
let public_key: PublicKey = (*s).as_str().parse()?;
32+
let public_key: PublicKey = unsafe { (*s).as_str() }.parse()?;
3333
Box::into_raw(Box::new(public_key)) as *mut RelayPublicKey
3434
}
3535

3636
/// Frees a public key.
37-
#[no_mangle]
37+
#[unsafe(no_mangle)]
3838
#[relay_ffi::catch_unwind]
3939
pub unsafe extern "C" fn relay_publickey_free(spk: *mut RelayPublicKey) {
4040
if !spk.is_null() {
4141
let pk = spk as *mut PublicKey;
42-
let _dropped = Box::from_raw(pk);
42+
let _dropped = unsafe { Box::from_raw(pk) };
4343
}
4444
}
4545

4646
/// Converts a public key into a string.
47-
#[no_mangle]
47+
#[unsafe(no_mangle)]
4848
#[relay_ffi::catch_unwind]
4949
pub unsafe extern "C" fn relay_publickey_to_string(spk: *const RelayPublicKey) -> RelayStr {
5050
let pk = spk as *const PublicKey;
51-
RelayStr::from_string((*pk).to_string())
51+
unsafe { RelayStr::from_string((*pk).to_string()) }
5252
}
5353

5454
/// Verifies a signature
55-
#[no_mangle]
55+
#[unsafe(no_mangle)]
5656
#[relay_ffi::catch_unwind]
5757
pub unsafe extern "C" fn relay_publickey_verify(
5858
spk: *const RelayPublicKey,
5959
data: *const RelayBuf,
6060
sig: *const RelayStr,
6161
) -> bool {
6262
let pk = spk as *const PublicKey;
63-
(*pk).verify((*data).as_bytes(), (*sig).as_str())
63+
unsafe { (*pk).verify((*data).as_bytes(), (*sig).as_str()) }
6464
}
6565

6666
/// Verifies a signature
67-
#[no_mangle]
67+
#[unsafe(no_mangle)]
6868
#[relay_ffi::catch_unwind]
6969
pub unsafe extern "C" fn relay_publickey_verify_timestamp(
7070
spk: *const RelayPublicKey,
@@ -74,48 +74,48 @@ pub unsafe extern "C" fn relay_publickey_verify_timestamp(
7474
) -> bool {
7575
let pk = spk as *const PublicKey;
7676
let max_age = Some(Duration::seconds(i64::from(max_age)));
77-
(*pk).verify_timestamp((*data).as_bytes(), (*sig).as_str(), max_age)
77+
unsafe { (*pk).verify_timestamp((*data).as_bytes(), (*sig).as_str(), max_age) }
7878
}
7979

8080
/// Parses a secret key from a string.
81-
#[no_mangle]
81+
#[unsafe(no_mangle)]
8282
#[relay_ffi::catch_unwind]
8383
pub unsafe extern "C" fn relay_secretkey_parse(s: &RelayStr) -> *mut RelaySecretKey {
84-
let secret_key: SecretKey = s.as_str().parse()?;
84+
let secret_key: SecretKey = unsafe { s.as_str() }.parse()?;
8585
Box::into_raw(Box::new(secret_key)) as *mut RelaySecretKey
8686
}
8787

8888
/// Frees a secret key.
89-
#[no_mangle]
89+
#[unsafe(no_mangle)]
9090
#[relay_ffi::catch_unwind]
9191
pub unsafe extern "C" fn relay_secretkey_free(spk: *mut RelaySecretKey) {
9292
if !spk.is_null() {
9393
let pk = spk as *mut SecretKey;
94-
let _dropped = Box::from_raw(pk);
94+
let _dropped = unsafe { Box::from_raw(pk) };
9595
}
9696
}
9797

9898
/// Converts a secret key into a string.
99-
#[no_mangle]
99+
#[unsafe(no_mangle)]
100100
#[relay_ffi::catch_unwind]
101101
pub unsafe extern "C" fn relay_secretkey_to_string(spk: *const RelaySecretKey) -> RelayStr {
102102
let pk = spk as *const SecretKey;
103-
RelayStr::from_string((*pk).to_string())
103+
unsafe { RelayStr::from_string((*pk).to_string()) }
104104
}
105105

106106
/// Verifies a signature
107-
#[no_mangle]
107+
#[unsafe(no_mangle)]
108108
#[relay_ffi::catch_unwind]
109109
pub unsafe extern "C" fn relay_secretkey_sign(
110110
spk: *const RelaySecretKey,
111111
data: *const RelayBuf,
112112
) -> RelayStr {
113113
let pk = spk as *const SecretKey;
114-
RelayStr::from_string((*pk).sign((*data).as_bytes()))
114+
unsafe { RelayStr::from_string((*pk).sign((*data).as_bytes())) }
115115
}
116116

117117
/// Generates a secret, public key pair.
118-
#[no_mangle]
118+
#[unsafe(no_mangle)]
119119
#[relay_ffi::catch_unwind]
120120
pub unsafe extern "C" fn relay_generate_key_pair() -> RelayKeyPair {
121121
let (sk, pk) = generate_key_pair();
@@ -126,15 +126,15 @@ pub unsafe extern "C" fn relay_generate_key_pair() -> RelayKeyPair {
126126
}
127127

128128
/// Randomly generates an relay id
129-
#[no_mangle]
129+
#[unsafe(no_mangle)]
130130
#[relay_ffi::catch_unwind]
131131
pub unsafe extern "C" fn relay_generate_relay_id() -> RelayUuid {
132132
let relay_id = generate_relay_id();
133133
RelayUuid::new(relay_id)
134134
}
135135

136136
/// Creates a challenge from a register request and returns JSON.
137-
#[no_mangle]
137+
#[unsafe(no_mangle)]
138138
#[relay_ffi::catch_unwind]
139139
pub unsafe extern "C" fn relay_create_register_challenge(
140140
data: *const RelayBuf,
@@ -147,10 +147,13 @@ pub unsafe extern "C" fn relay_create_register_challenge(
147147
m => Some(Duration::seconds(i64::from(m))),
148148
};
149149

150-
let req =
151-
RegisterRequest::bootstrap_unpack((*data).as_bytes(), (*signature).as_str(), max_age)?;
150+
let challenge = unsafe {
151+
let req =
152+
RegisterRequest::bootstrap_unpack((*data).as_bytes(), (*signature).as_str(), max_age)?;
153+
154+
req.into_challenge((*secret).as_str().as_bytes())
155+
};
152156

153-
let challenge = req.into_challenge((*secret).as_str().as_bytes());
154157
RelayStr::from_string(serde_json::to_string(&challenge)?)
155158
}
156159

@@ -163,7 +166,7 @@ struct RelayRegisterResponse<'a> {
163166
}
164167

165168
/// Validates a register response.
166-
#[no_mangle]
169+
#[unsafe(no_mangle)]
167170
#[relay_ffi::catch_unwind]
168171
pub unsafe extern "C" fn relay_validate_register_response(
169172
data: *const RelayBuf,
@@ -177,9 +180,9 @@ pub unsafe extern "C" fn relay_validate_register_response(
177180
};
178181

179182
let (response, state) = RegisterResponse::unpack(
180-
(*data).as_bytes(),
181-
(*signature).as_str(),
182-
(*secret).as_str().as_bytes(),
183+
unsafe { (*data).as_bytes() },
184+
unsafe { (*signature).as_str() },
185+
unsafe { (*secret).as_str().as_bytes() },
183186
max_age,
184187
)?;
185188

@@ -195,10 +198,10 @@ pub unsafe extern "C" fn relay_validate_register_response(
195198
}
196199

197200
/// Returns true if the given version is supported by this library.
198-
#[no_mangle]
201+
#[unsafe(no_mangle)]
199202
#[relay_ffi::catch_unwind]
200203
pub unsafe extern "C" fn relay_version_supported(version: &RelayStr) -> bool {
201-
let relay_version = match version.as_str() {
204+
let relay_version = match unsafe { version.as_str() } {
202205
"" => RelayVersion::default(),
203206
s => s.parse::<RelayVersion>()?,
204207
};

relay-cabi/src/codeowners.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,14 @@ fn translate_codeowners_pattern(pattern: &str) -> Option<Regex> {
9595
}
9696

9797
/// Returns `true` if the codeowners path matches the value, `false` otherwise.
98-
#[no_mangle]
98+
#[unsafe(no_mangle)]
9999
#[relay_ffi::catch_unwind]
100100
pub unsafe extern "C" fn relay_is_codeowners_path_match(
101101
value: *const RelayBuf,
102102
pattern: *const RelayStr,
103103
) -> bool {
104-
let value = (*value).as_bytes();
105-
let pat = (*pattern).as_str();
104+
let value = unsafe { (*value).as_bytes() };
105+
let pat = unsafe { (*pattern).as_str() };
106106

107107
let mut cache = CODEOWNERS_CACHE.lock().unwrap();
108108

0 commit comments

Comments
 (0)