-
Notifications
You must be signed in to change notification settings - Fork 636
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify khronos_api patch for Bazel build
Use relative paths to CARGO_MANIFEST_DIR in build.rs. Patch is also submitted upstream at brendanzab/gl-rs#549
- Loading branch information
Showing
4 changed files
with
51 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
examples/bazel_build/external_crate_builds/0001-Fix-build-with-Bazel.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Copyright © 2025 SixtyFPS GmbH | ||
# SPDX-License-Identifier: MIT | ||
|
||
# See https://github.com/brendanzab/gl-rs/pull/549 | ||
|
||
From ff5fd1fa0a2416ddff942173d047e95979aa6dfd Mon Sep 17 00:00:00 2001 | ||
From: Simon Hausmann <[email protected]> | ||
Date: Sun, 5 Jan 2025 10:43:59 +0100 | ||
Subject: [PATCH] Fix build with Bazel | ||
|
||
When building Rust applications with Bazel instead of cargo, typically a | ||
sandbox is in place, where each process invocation (rustc, build.rs | ||
program, etc.) runs in its own "root", where the view on the filesystem | ||
is the same, but the absolute paths are different. As a consequence, | ||
CARGO_MANIFEST_DIR differs between the invocation of build.rs and rustc. | ||
|
||
That means that absolute paths in the generated webgl_exts.rs don't | ||
work. Fortunately, the source files are relative to the | ||
CARGO_MANIFEST_DIR, which, while changing between invocations, remains | ||
valid. | ||
--- | ||
khronos_api/build.rs | 5 +++-- | ||
1 file changed, 3 insertions(+), 2 deletions(-) | ||
|
||
diff --git a/khronos_api/build.rs b/khronos_api/build.rs | ||
index 160179b..f7fc439 100644 | ||
--- a/build.rs | ||
+++ b/build.rs | ||
@@ -29,7 +29,8 @@ 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 cargo_manifest_dir = PathBuf::from(std::env::var_os("CARGO_MANIFEST_DIR").unwrap()); | ||
+ let root = cargo_manifest_dir.join("api_webgl/extensions"); | ||
|
||
// Generate a slice literal, looking like this: | ||
// `&[&*include_bytes!(..), &*include_bytes!(..), ..]` | ||
@@ -53,7 +54,7 @@ fn main() { | ||
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(); | ||
+ writeln!(file, "&*include_bytes!(concat!(env!(\"CARGO_MANIFEST_DIR\"), \"/\", {:?})),", ext_path.strip_prefix(cargo_manifest_dir.clone()).unwrap().to_str().unwrap()).unwrap(); | ||
} | ||
} | ||
} | ||
-- | ||
2.39.5 (Apple Git-154) | ||
|
58 changes: 0 additions & 58 deletions
58
examples/bazel_build/external_crate_builds/khronos_api_webgl_exts_rs.BUILD.bazel
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
examples/bazel_build/external_crate_builds/khronos_apis_fix_build.patch
This file was deleted.
Oops, something went wrong.