Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bazel build with changing path in include_bytes. #536

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions khronos_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ documentation = "https://docs.rs/khronos_api"
homepage = "https://github.com/brendanzab/gl-rs/"
repository = "https://github.com/brendanzab/gl-rs/"
readme = "README.md"
edition = "2018"

# Only include what we need here. The git submodules are quite large, and would
# exceed the maximimum crate size if we didn't do this
Expand Down
19 changes: 15 additions & 4 deletions khronos_api/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ fn main() {
// The absolute path is needed, because we don't know where the output
// directory will be, and `include_bytes!(..)` resolves paths relative to the
// containing file.
let root = env::current_dir().unwrap().join("api_webgl/extensions");
let manifest_path = env::var("CARGO_MANIFEST_DIR").unwrap();
let root_base = Path::new(&manifest_path);
let root = match root_base.join("khronos_api/api_webgl/extensions").exists() {
true => root_base.join("khronos_api/api_webgl/extensions"),
false => root_base.join("api_webgl/extensions"),
};

// Generate a slice literal, looking like this:
// `&[&*include_bytes!(..), &*include_bytes!(..), ..]`
Expand All @@ -38,7 +43,11 @@ fn main() {
// The slice will have one entry for each WebGL extension. To find the
// extensions we mirror the behaviour of the `api_webgl/extensions/find-exts`
// shell script.
let mut paths: Vec<_> = root.read_dir().unwrap().map(|e| e.unwrap().path()).collect();
let mut paths: Vec<_> = root
.read_dir()
.unwrap()
.map(|e| e.unwrap().path())
.collect();
// Sort the list of paths in order for the webgl_exts.rs file to be created
// deterministically.
paths.sort();
Expand All @@ -52,8 +61,10 @@ fn main() {
// really is an extension.
let ext_path = path.join("extension.xml");
if ext_path.is_file() {
// Include the XML file, making sure to use an absolute path.
writeln!(file, "&*include_bytes!({:?}),", ext_path.to_str().unwrap()).unwrap();
// Fix absolute path for bazel build
let abs_out_path = ext_path.canonicalize().unwrap();
let abs_out_path = abs_out_path.to_str().unwrap();
writeln!(file, "&*include_bytes!({:?}),", abs_out_path).unwrap();
}
}
}
Expand Down