From b97ec770f2db8c4e6eb4ef08aed0868064430ae5 Mon Sep 17 00:00:00 2001 From: "Victor M. Alvarez" Date: Wed, 27 Mar 2024 09:54:44 +0100 Subject: [PATCH] chore: rename `yara-x.h` to `yara_x.h` for consistency with library names --- capi/Cargo.toml | 2 +- capi/build.rs | 2 +- capi/include/{yara-x.h => yara_x.h} | 0 capi/src/lib.rs | 25 +++++++++++++++++++------ go/main.go | 6 +++--- 5 files changed, 24 insertions(+), 11 deletions(-) rename capi/include/{yara-x.h => yara_x.h} (100%) diff --git a/capi/Cargo.toml b/capi/Cargo.toml index e02ded7d5..87ffcefad 100644 --- a/capi/Cargo.toml +++ b/capi/Cargo.toml @@ -29,7 +29,7 @@ cbindgen = { workspace = true } # This section is used by `cargo-c`, for generating the header file and [package.metadata.capi.header] # Name of the header file, without the `.h` extension. -name = "yara-x" +name = "yara_x" # Install the header into a subdirectory with the name of the crate. This # is enabled by default, pass `false` or "" to disable it. subdirectory = "" diff --git a/capi/build.rs b/capi/build.rs index a8d64d4e9..94683b5ce 100644 --- a/capi/build.rs +++ b/capi/build.rs @@ -5,7 +5,7 @@ fn main() { println!("cargo:rerun-if-changed=cbindgen.toml"); let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); - let output_file = "include/yara-x.h".to_owned(); + let output_file = "include/yara_x.h".to_owned(); match cbindgen::generate(crate_dir) { Ok(header) => { diff --git a/capi/include/yara-x.h b/capi/include/yara_x.h similarity index 100% rename from capi/include/yara-x.h rename to capi/include/yara_x.h diff --git a/capi/src/lib.rs b/capi/src/lib.rs index 9e3f23b5a..063d496d1 100644 --- a/capi/src/lib.rs +++ b/capi/src/lib.rs @@ -2,7 +2,7 @@ This crate defines the C-compatible API that C/C++ programs can use for interfacing with the YARA-X Rust library. A header file for this library -(`yara-x.h`) will be automatically generated by [`cbindgen`][1], during +(`yara_x.h`) will be automatically generated by [`cbindgen`][1], during compilation, together with dynamic-linking and static-linking versions of the library. @@ -47,15 +47,16 @@ cargo cinstall -p yara-x-capi --release ``` The command above will put the library and header files in the correct path -in your system (usually `/usr/local/lib` and `/usr/local/include`, respectively), -and will generate a `.pc` file so that `pkg-config` knows about the library. +in your system (usually `/usr/local/lib` and `/usr/local/include` for Linux +and MacOS users), and will generate a `.pc` file so that `pkg-config` knows +about the library. -You can check if everything went fine by compiling a simple test program, like -this: +In Linux and MacOS you can check if everything went fine by compiling a simple +test program, like this: ```text cat < test.c -#include +#include int main() { YRX_RULES* rules; yrx_compile("rule dummy { condition: true }", &rules); @@ -68,11 +69,23 @@ EOF gcc `pkg-config --cflags yara_x_capi` `pkg-config --libs yara_x_capi` test.c ``` +The compilation should succeed without errors. + +Windows users can find all the files you need for importing the YARA-X library +in your project in the `target/x86_64-pc-windows-msvc/release` directory. This +includes: + +* A header file (`yara_x.h`) +* A [module definition file][4] (`yara_x_capi.def`) +* A DLL file (`yara_x_capi.dll`) with its corresponding import library (`yara_x_capi.dll.lib`) +* A static library (`yara_x_capi.lib`) + [1]: https://github.com/mozilla/cbindgen [2]: https://github.com/lu-zero/cargo-c [3]: https://brew.sh [4]: https://vcpkg.io/ +[4]: https://learn.microsoft.com/en-us/cpp/build/reference/module-definition-dot-def-files */ #![allow(non_camel_case_types)] diff --git a/go/main.go b/go/main.go index 050e09561..ed80ee9c7 100644 --- a/go/main.go +++ b/go/main.go @@ -1,9 +1,9 @@ // Package yara_x provides Go bindings to the YARA-X library. package yara_x -// #cgo !static_link pkg-config: yara_x_capi +// #cgo !static_link pkg-config: yara_x_capi // #cgo static_link pkg-config: --static yara_x_capi -// #import +// #import import "C" import ( "errors" @@ -87,7 +87,7 @@ type Rules struct{ cRules *C.YRX_RULES } // Scan some data with the compiled rules. // // Returns a slice with the rules that matched. -func (r* Rules) Scan(data []byte) ([]*Rule, error) { +func (r *Rules) Scan(data []byte) ([]*Rule, error) { scanner := NewScanner(r) return scanner.Scan(data) }