Skip to content

Commit

Permalink
chore: rename yara-x.h to yara_x.h for consistency with library n…
Browse files Browse the repository at this point in the history
…ames
  • Loading branch information
plusvic committed Mar 27, 2024
1 parent 8b364f2 commit b97ec77
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion capi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down
2 changes: 1 addition & 1 deletion capi/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
File renamed without changes.
25 changes: 19 additions & 6 deletions capi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 <<EOF > test.c
#include <yara-x.h>
#include <yara_x.h>
int main() {
YRX_RULES* rules;
yrx_compile("rule dummy { condition: true }", &rules);
Expand All @@ -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)]
Expand Down
6 changes: 3 additions & 3 deletions go/main.go
Original file line number Diff line number Diff line change
@@ -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 <yara-x.h>
// #import <yara_x.h>
import "C"
import (
"errors"
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit b97ec77

Please sign in to comment.