binaryninja-api icon indicating copy to clipboard operation
binaryninja-api copied to clipboard

Rust: Allow running doctests and unit tests

Open mkrasnitski opened this issue 1 year ago • 1 comments

Adding the cargo::rustc-link-arg option to the build.rs file of the binaryninja crate allows doctests and unit tests to be linked against binaryninjacore.so.1 and ran when invoking cargo test.

Also, the single-colon cargo: syntax is deprecated as of Rust 1.77, and future features will all use the cargo:: syntax. Since the MSRV is already Rust 1.77, it's fine to switch for consistency's sake going forward.

mkrasnitski avatar May 18 '24 19:05 mkrasnitski

I guess CI is failing because binja isn't actually installed as part of the GH action? I wouldn't know how to set it up to allow for the linking to succeed - as far as I know the build.rs changes are correct (works on my machine lol)

mkrasnitski avatar May 20 '24 18:05 mkrasnitski

I guess CI is failing because binja isn't actually installed as part of the GH action?

You are correct we do not install binja on GH actions, we only use it for PR checks. I think it would be fine to just not run tests in CI.

emesare avatar Jul 10 '24 15:07 emesare

What's odd is that the doctests compile fine, whereas cargo test --no-run fails to even compile. What could be the difference here?

mkrasnitski avatar Jul 10 '24 17:07 mkrasnitski

What's odd is that the doctests compile fine, whereas cargo test --no-run fails to even compile. What could be the difference here?

The doctests are all annotated with no_run

emesare avatar Jul 10 '24 17:07 emesare

Exactly: they type check and compile just fine but don't run. For some reason though, the unit tests don't link correctly even though --no-run is passed, whereas the doctests do. I wonder if there's some subtle difference between how doctests and unit tests are treated here.

mkrasnitski avatar Jul 10 '24 20:07 mkrasnitski

This PR is superseded by rust_break_everything.

Specifically https://github.com/Vector35/binaryninja-api/commit/8a24a4394cf887728da1f260d7d3a86fb58157aa (Warning: this branch will rewrite history, these commits may not be accurate later)

emesare avatar Aug 24 '24 15:08 emesare