Skip to content

Commit

Permalink
define for relevant simd
Browse files Browse the repository at this point in the history
  • Loading branch information
djellemah committed May 4, 2024
1 parent f6ce305 commit 139ec8b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
21 changes: 21 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,34 @@ fn main() {
std::process::exit(1)
}

let wrapper_defs_dir = &env::var_os("OUT_DIR").unwrap();
let wrapper_defs_dir = Path::new(&wrapper_defs_dir);
let dest_path = wrapper_defs_dir.join("wrapper_defs.h");
use std::env;
use std::path::Path;
let target_env = std::env::var("TARGET");
let define_value = match target_env {
// srsly. There must be a better way.
Ok(s) if s == "x86_64-unknown-linux-gnu" => "#define RAPIDJSON_SSE42".into(),
Ok(s) if s == "x86_64-pc-windows-gnu" => "#define RAPIDJSON_SSE42".into(),
Ok(s) if s == "arm64e-apple-darwin"=> "#define RAPIDJSON_NEON".into(),
wut => format!("// whaddya mean {:?}", wut),
};
if option_env!("RAPIDJSON_SSE42").is_some() {
std::fs::write(&dest_path, define_value).unwrap();
} else {
std::fs::write(&dest_path, "").unwrap();
}

cxx_build::bridge("src/rapid.rs")
.include(rapidjson_include)
.include(wrapper_defs_dir)
.file("src/wrapper.cc")
.cpp(true)
.std("c++20")
.compile("rapid");

println!("cargo::rerun-if-changed=build.rs");
println!("cargo::rerun-if-changed=src/rapid.rs");
println!("cargo::rerun-if-changed=src/wrapper.cc");
println!("cargo::rerun-if-changed=src/wrapper.h");
Expand Down
6 changes: 3 additions & 3 deletions src/wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
// NOTE jch is just what cxx-build wants to call it, because of the cargo package name.
#include "jch/src/rapid.rs.h"

// turn on simd instructions
// #define RAPIDJSON_SSE42
// Turn on simd instructions for the architecture.
// The file is generated by build.rs
#include "wrapper_defs.h"

// TODO vendor or git-submodule this into the build tree
#include "rapidjson/fwd.h"
#include "rapidjson/rapidjson.h"
#include "rapidjson/reader.h"
Expand Down

0 comments on commit 139ec8b

Please sign in to comment.