-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Windows compilation #14
Comments
Hi Hugal31. Thanks for picking this up. We were kind of hoping this was us doing sth wrong... At our end yara-rust is part of a larger project we're trying to compile for Windows. Cross-compiling from Linux is so far the option we've had the most success with but we got stuck at the above point. Can you recommend an alternative method for getting a running example working on Windows? |
Hi, I am currently investigating how to fix this bug. Unfortunately, I don't think there is a workaround until I find a fix. |
Quick question: do you know if you or a dependency using yara-rust make use of the "bundled" feature of yara-rust ? |
We don't explicitly use "bundled" - we're not sure if any dependencies use it though. |
I think I see the problem(s):
I see two solutions:
|
Thanks a lot for looking into it and thanks for the link to the pipeline. We spend a lot of time compiling on Windows and ran into various problems with different compilers installed and diff header files. We'll try again with inspiration from that pipeline. |
There should be no problem using bindgen with yara, assuming you have a correctly functioning cross-compilation toolchain (with appropriate environment variables to let it find the system headers). There is a pain point here: rust-lang/rust-bindgen#2009. Here's my setup: I use https://github.com/roblabla/msvc-wine, which acquires the MSVC headers and libs, and sets up
After doing this, and using this PR for yara-src-rs, yara builds and links without issue, generating the bindings dynamically. |
I think I have a similar issue. On Windows, when trying to run the example, it tells me Clang is missing: main.rs use yara::Compiler;
const RULES: &str = r#"
rule contains_rust {
strings:
$rust = "rust" nocase
condition:
$rust
}
"#;
fn main() {
let compiler = Compiler::new().unwrap();
let compiler = compiler
.add_rules_str(RULES)
.expect("Should have parsed rule");
let rules = compiler
.compile_rules()
.expect("Should have compiled rules");
let results = rules
.scan_mem("I love Rust!".as_bytes(), 5)
.expect("Should have scanned");
assert!(results.iter().any(|r| r.identifier == "contains_rust"));
} Cargo.toml: [package]
name = "experimenting"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
yara = "0.20.0" Exception: Compiling yara-sys v0.20.0
error: failed to run custom build command for `yara-sys v0.20.0`
Caused by:
process didn't exit successfully: `C:\Users\...\experimenting\target\debug\build\yara-sys-f32a719f96a9cdca\build-script-build` (exit code: 101)
--- stdout
cargo:rustc-link-lib=dylib=yara
cargo:rerun-if-env-changed=YARA_LIBRARY_PATH
cargo:rerun-if-env-changed=YARA_LIBRARY_PATH_x86_64-pc-windows-msvc
cargo:rerun-if-env-changed=YARA_LIBRARY_PATH_x86_64_pc_windows_msvc
--- stderr
thread 'main' panicked at 'Unable to find libclang: "couldn't find any valid shared libraries matching: ['clang.dll', 'libclang.dll'], set the `LIBCLANG_PATH` environment variable to a path where one of these files can be found (invalid: [])"', C:\Users\...\.cargo\registry\src\index.crates.io-6f17d22bba15001f\bindgen-0.64.0\./lib.rs:2393:31
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace I probably just need to download the missing dll? |
yara uses bindgen by default which requires clang to be installed yes: https://rust-lang.github.io/rust-bindgen/requirements.html#clang |
Thank you, it might be useful to put this in the documentation for noobs like me that don't know it. |
C:\Users\victim\Desktop\simpleantivirus>cargo build Caused by: --- stderr |
@HydraDragonAntivirus You probably don't have yara installed and need to use the vendored feature. See #121 (comment) |
I tried to compile from yara-sys folder then this happened. I probably making same mistake. : Compiling yara-sys v0.24.0 (C:\Users\victim\Downloads\yara-rust-master\yara-sys) Caused by: --- stderr |
Also can't install bindegen. But can install clang and already setted them. #if !defined (YR_MAJOR_VERSION) || !defined (YR_MINOR_VERSION) error "Yara version macro not defined."#endif #if YR_MAJOR_VERSION != 4 if YR_MAJOR_VERSION < 4error "Only Yara v4 is supported."elsewarning "Yara versons above v4 are not supported. Please use Yara v4."endif#endif and where is the yara.h? |
I fixed the problem by set YARA_INCLUDE_DIR=C:\Users\victim\Desktop\hydradragonav adding yara.h and other yarac include things. |
Hi,
We're trying to cross-compile this little program:
to Windows from Linux by issuing:
cargo build --bin thomas --target x86_64-pc-windows-gnu
We have set the correct inc dir:
YARA_INCLUDE_DIR="../yara-3.11.0/libyara/include"
The error we get is:
The text was updated successfully, but these errors were encountered: