diff --git a/ecsact_dylib_runtime/BUILD.bazel b/ecsact_dylib_runtime/BUILD.bazel index d247911..1975a08 100644 --- a/ecsact_dylib_runtime/BUILD.bazel +++ b/ecsact_dylib_runtime/BUILD.bazel @@ -8,7 +8,7 @@ cargo_build_script( name = "build_script", srcs = ["build.rs"], aliases = aliases(), - deps = all_crate_deps( + deps = ["@rules_rust//tools/runfiles"] + all_crate_deps( build = True, ), build_script_env = { diff --git a/ecsact_dylib_runtime/build.rs b/ecsact_dylib_runtime/build.rs index 0bb8d7d..7aad4b4 100644 --- a/ecsact_dylib_runtime/build.rs +++ b/ecsact_dylib_runtime/build.rs @@ -1,5 +1,7 @@ extern crate bindgen; +// TODO(zaucy): Optionally include runfiles only while compiling with bazel +use runfiles::Runfiles; use std::env; use std::path::PathBuf; use std::process::Command; @@ -8,12 +10,17 @@ fn ecsact_include_dir() -> String { // This environment variable is really only for the bazel build. Users should // just use the `ecsact` command line in their PATH let rt_headers = env::var("ECSACT_RUNTIME_HEADERS"); - if let Ok(rt_headers) = rt_headers { - let rt_headers: Vec<&str> = rt_headers.split(' ').collect(); - let header = rt_headers.first().unwrap().to_owned().replace("\\", "/"); + if rt_headers.is_ok() { + let runfiles = Runfiles::create().unwrap(); + let header = runfiles + .rlocation("ecsact_runtime/ecsact/runtime.h") + .into_os_string() + .into_string() + .unwrap() + .replace("\\", "/"); let header_index = header.find("/ecsact/").unwrap(); let include_dir = &header[..header_index]; - return "../".to_string() + include_dir.into(); + return include_dir.into(); } let ecsact_config = json::parse(&String::from_utf8_lossy( diff --git a/ecsact_system_execution_context/BUILD.bazel b/ecsact_system_execution_context/BUILD.bazel index ce78d95..967e79c 100644 --- a/ecsact_system_execution_context/BUILD.bazel +++ b/ecsact_system_execution_context/BUILD.bazel @@ -8,7 +8,7 @@ cargo_build_script( name = "build_script", srcs = ["build.rs"], aliases = aliases(), - deps = all_crate_deps( + deps = ["@rules_rust//tools/runfiles"] + all_crate_deps( build = True, ), build_script_env = { diff --git a/ecsact_system_execution_context/build.rs b/ecsact_system_execution_context/build.rs index 64147ad..08d6f84 100644 --- a/ecsact_system_execution_context/build.rs +++ b/ecsact_system_execution_context/build.rs @@ -1,17 +1,24 @@ extern crate bindgen; +// TODO(zaucy): Optionally include runfiles only while compiling with bazel +use runfiles::Runfiles; use std::process::Command; fn ecsact_include_dir() -> String { // This environment variable is really only for the bazel build. Users should // just use the `ecsact` command line in their PATH let rt_headers = std::env::var("ECSACT_RUNTIME_HEADERS"); - if let Ok(rt_headers) = rt_headers { - let rt_headers: Vec<&str> = rt_headers.split(" ").collect(); - let header = rt_headers.first().unwrap().to_owned().replace("\\", "/"); + if rt_headers.is_ok() { + let runfiles = Runfiles::create().unwrap(); + let header = runfiles + .rlocation("ecsact_runtime/ecsact/runtime.h") + .into_os_string() + .into_string() + .unwrap() + .replace("\\", "/"); let header_index = header.find("/ecsact/").unwrap(); let include_dir = &header[..header_index]; - return "../".to_string() + include_dir.into(); + return include_dir.into(); } let ecsact_config = json::parse(&String::from_utf8_lossy(