Skip to content

Commit

Permalink
bazel runfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
zaucy committed Feb 20, 2023
1 parent 9cbbdb4 commit d6b220e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion ecsact_dylib_runtime/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
15 changes: 11 additions & 4 deletions ecsact_dylib_runtime/build.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion ecsact_system_execution_context/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
15 changes: 11 additions & 4 deletions ecsact_system_execution_context/build.rs
Original file line number Diff line number Diff line change
@@ -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(
Expand Down

0 comments on commit d6b220e

Please sign in to comment.