Skip to content

Commit 0429b79

Browse files
committed
Update to Rust 2024, pin cxxbridge version, cleanup
1 parent b09409a commit 0429b79

File tree

8 files changed

+45
-28
lines changed

8 files changed

+45
-28
lines changed

.github/workflows/build_and_test.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ jobs:
1616
- uses: actions/checkout@v3
1717
- uses: ilammy/msvc-dev-cmd@v1
1818
- name: install cxxbridge
19-
run: cargo install cxxbridge-cmd
19+
# When changing this version, also change it in Cargo.toml
20+
run: cargo install cxxbridge-cmd@=1.0.190
2021
- name: install just
2122
run: cargo install just
2223
- name: Compile test
@@ -30,7 +31,8 @@ jobs:
3031
steps:
3132
- uses: actions/checkout@v3
3233
- name: install cxxbridge
33-
run: cargo install cxxbridge-cmd
34+
# When changing this version, also change it in Cargo.toml
35+
run: cargo install cxxbridge-cmd@=1.0.190
3436
- name: install just
3537
run: cargo install just
3638
- name: Compile test
@@ -44,7 +46,8 @@ jobs:
4446
steps:
4547
- uses: actions/checkout@v3
4648
- name: install cxxbridge
47-
run: cargo install cxxbridge-cmd
49+
# When changing this version, also change it in Cargo.toml
50+
run: cargo install cxxbridge-cmd@=1.0.190
4851
- name: install just
4952
run: cargo install just
5053
- name: Compile test

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ build/
44
*.exe
55
/TinyInst
66
*.obj
7-
test_file.txt
7+
test_file.txt
8+
.vscode

Cargo.toml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ repository = "https://github.com/AFLplusplus/tinyinst-rs/"
66
readme = "./README.md"
77
license = "MIT OR Apache-2.0"
88
keywords = ["bindings", "testing", "security"]
9-
version = "0.1.0"
10-
edition = "2021"
9+
version = "0.1.1"
10+
edition = "2024"
1111
categories = ["development-tools::testing", "os", "no-std"]
1212

1313
[dependencies]
14-
cxx = { version = "1.0", default-features = false, features = ["alloc"] }
14+
# When changing this, also change all versions in build_and_test.yml
15+
cxx = { version = "=1.0.190", default-features = false, features = ["alloc"] }
1516

1617
[build-dependencies]
1718
cmake = "0.1.54"
18-
git2 = "0.20.0"
19-
which = "7.0.2"
19+
git2 = "0.20.2"
20+
which = "8.0.0"

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ FFI to [TinyInst](https://github.com/googleprojectzero/TinyInst). Created for [L
55
## Dependencies
66

77
* Visual Studio 2022
8-
* cxxbridge
98
* cargo-make
109
* python3
1110
* git
11+
* cxxbridge@=1.0.190 (or latest version from Cargo.toml)
1212

1313
## Running the test
1414

@@ -17,7 +17,6 @@ FFI to [TinyInst](https://github.com/googleprojectzero/TinyInst). Created for [L
1717
3. Run `just build_test` to build the test binary
1818
4. Run `cargo test` to run the test
1919

20-
2120
## Optional ENV Variables
2221

2322
`CUSTOM_TINYINST_GENERATOR` = Generator used for cmake `-G` flag
@@ -26,7 +25,6 @@ FFI to [TinyInst](https://github.com/googleprojectzero/TinyInst). Created for [L
2625

2726
`CUSTOM_TINYINST_NO_BUILD` = if set, it won't build Tinyinst everytime. Useful when paired with `CUSTOM_TINYINST_DIR`
2827

29-
3028
#### License
3129

3230
<sup>

build.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ fn build_dep_check(tools: &[&str]) -> bool {
1919
true
2020
}
2121

22+
#[allow(clippy::too_many_lines)]
2223
fn main() {
2324
if !build_dep_check(&["git", "cxxbridge", "cmake"]) {
2425
return;
@@ -34,7 +35,9 @@ fn main() {
3435
let custom_tinyinst_generator =
3536
env::var_os("CUSTOM_TINYINST_GENERATOR").map(|x| x.to_string_lossy().to_string());
3637

37-
env::set_var("CXXFLAGS", "-std=c++17");
38+
// # Safety
39+
// the env is only accessed here, single threaded
40+
unsafe { env::set_var("CXXFLAGS", "-std=c++17") };
3841

3942
let tinyinst_generator = if let Some(generator) = custom_tinyinst_generator.as_ref() {
4043
generator

rustfmt.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
group_imports = "StdExternalCrate"
2+
imports_granularity = "Crate"
3+
newline_style = "Unix"
4+
format_code_in_doc_comments = true
5+
format_macro_bodies = true
6+
format_macro_matchers = true

src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*!
22
* Rust bindings for [`TinyInst`](https://github.com/googleprojectzero/TinyInst)
3-
*/
4-
5-
#![allow(incomplete_features)]
3+
*/
4+
#![doc = include_str!("../README.md")]
5+
/*! */
66
#![no_std]
77
#![warn(clippy::cargo)]
88
#![deny(clippy::cargo_common_metadata)]
@@ -45,7 +45,6 @@
4545
overflowing_literals,
4646
path_statements,
4747
patterns_in_fns_without_body,
48-
private_in_public,
4948
unconditional_recursion,
5049
unused,
5150
unused_allocation,

src/tinyinst.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,15 @@ impl TinyInst {
157157
.collect();
158158
tinyinst_args_ptr.push(core::ptr::null_mut());
159159

160-
// Init TinyInst with Tinyinst arguments.
161-
tinyinst_ptr.pin_mut().Init(
162-
i32::try_from(tinyinst_args.len()).unwrap(),
163-
tinyinst_args_ptr.as_mut_ptr(),
164-
);
160+
// Init TinyInst with TinyInst arguments.
161+
// # Safety
162+
// The arguments and pointers are valid at this point
163+
unsafe {
164+
tinyinst_ptr.pin_mut().Init(
165+
i32::try_from(tinyinst_args.len()).unwrap(),
166+
tinyinst_args_ptr.as_mut_ptr(),
167+
);
168+
}
165169

166170
let program_args_cstr: Vec<CString> = program_args
167171
.iter()
@@ -184,12 +188,14 @@ impl TinyInst {
184188
}
185189

186190
pub unsafe fn run(&mut self) -> litecov::RunResult {
187-
self.tinyinst_ptr.pin_mut().Run(
188-
i32::try_from(self.program_args_cstr.len()).unwrap(),
189-
self.program_args_ptr.as_mut_ptr(),
190-
self.timeout,
191-
self.timeout,
192-
)
191+
unsafe {
192+
self.tinyinst_ptr.pin_mut().Run(
193+
i32::try_from(self.program_args_cstr.len()).unwrap(),
194+
self.program_args_ptr.as_mut_ptr(),
195+
self.timeout,
196+
self.timeout,
197+
)
198+
}
193199
}
194200

195201
// pub unsafe fn bitmap_coverage(

0 commit comments

Comments
 (0)