While using the default Bazel C++ toolchain to build Yocto native tools
(bazel build --host_crosstool_top=@bazel_tools//tools/cpp:toolchain),
it failed with `bazel references a path outside of the execution root',

Add Yocto native sysroot dir (YOCTO_NATIVE_SYSROOT) to
builtin_include_directories could fix the issue

If not set YOCTO_NATIVE_SYSROOT, use NOT_SET_YOCTO_NATIVE_SYSROOT
to replace as a warning

Set YOCTO_NATIVE_SYSROOT in bazel.bbclass

Signed-off-by: Hongxu Jia <hongxu....@windriver.com>
---
 classes/bazel.bbclass                         |  2 +
 recipes-devtools/bazel/bazel-native_3.1.0.bb  |  1 +
 ...-sysroot-dir-to-the-default-Bazel-to.patch | 39 +++++++++++++++++++
 3 files changed, 42 insertions(+)
 create mode 100644 
recipes-devtools/bazel/files/0001-add-Yocto-native-sysroot-dir-to-the-default-Bazel-to.patch

diff --git a/classes/bazel.bbclass b/classes/bazel.bbclass
index 65d2932..b4c2a7f 100644
--- a/classes/bazel.bbclass
+++ b/classes/bazel.bbclass
@@ -109,3 +109,5 @@ EXPORT_FUNCTIONS do_configure
 CCACHE_DISABLE = "1"
 
 inherit unsupportarch
+
+export 
YOCTO_NATIVE_SYSROOT="${BAZEL_OUTPUTBASE_DIR}/external/yocto_compiler/recipe-sysroot-native"
diff --git a/recipes-devtools/bazel/bazel-native_3.1.0.bb 
b/recipes-devtools/bazel/bazel-native_3.1.0.bb
index f3efde1..0555f2f 100644
--- a/recipes-devtools/bazel/bazel-native_3.1.0.bb
+++ b/recipes-devtools/bazel/bazel-native_3.1.0.bb
@@ -9,6 +9,7 @@ SRC_URI = 
"https://github.com/bazelbuild/bazel/releases/download/${PV}/bazel-${P
            file://0001-HttpDownloader-save-download-tarball-to-distdir.patch \
            file://0001-fix-unzip-command-not-found.patch \
            file://0001-python3.patch \
+           
file://0001-add-Yocto-native-sysroot-dir-to-the-default-Bazel-to.patch \
 "
 
 inherit native python3native
diff --git 
a/recipes-devtools/bazel/files/0001-add-Yocto-native-sysroot-dir-to-the-default-Bazel-to.patch
 
b/recipes-devtools/bazel/files/0001-add-Yocto-native-sysroot-dir-to-the-default-Bazel-to.patch
new file mode 100644
index 0000000..b08c65a
--- /dev/null
+++ 
b/recipes-devtools/bazel/files/0001-add-Yocto-native-sysroot-dir-to-the-default-Bazel-to.patch
@@ -0,0 +1,39 @@
+From 707ba08068432262b3d02b29804c00afe7133ff6 Mon Sep 17 00:00:00 2001
+From: Hongxu Jia <hongxu....@windriver.com>
+Date: Thu, 10 Dec 2020 16:12:51 +0800
+Subject: [PATCH] add Yocto native sysroot dir to the default Bazel toolchain
+
+While using the default Bazel C++ toolchain to build Yocto native tools
+(bazel build --host_crosstool_top=@bazel_tools//tools/cpp:toolchain),
+it failed `bazel references a path outside of the execution root',
+
+Add Yocto native sysroot dir (YOCTO_NATIVE_SYSROOT) to
+builtin_include_directories could fix the issue
+
+If not set YOCTO_NATIVE_SYSROOT, use NOT_SET_YOCTO_NATIVE_SYSROOT
+to replace as a warning
+
+Upstream-Status: Inappropriate [oe specific]
+
+Signed-off-by: Hongxu Jia <hongxu....@windriver.com>
+---
+ tools/cpp/unix_cc_configure.bzl | 3 +++
+ 1 file changed, 3 insertions(+)
+
+diff --git a/tools/cpp/unix_cc_configure.bzl b/tools/cpp/unix_cc_configure.bzl
+index 84f5479..e17aa9d 100755
+--- a/tools/cpp/unix_cc_configure.bzl
++++ b/tools/cpp/unix_cc_configure.bzl
+@@ -424,6 +424,9 @@ def configure_unix_toolchain(repository_ctx, cpu_value, 
overriden_tools):
+         ),
+     )
+ 
++    # Customize for Yocto
++    
builtin_include_directories.append(get_env_var(repository_ctx,"YOCTO_NATIVE_SYSROOT",
 "NOT_SET_YOCTO_NATIVE_SYSROOT"))
++
+     write_builtin_include_directory_paths(repository_ctx, cc, 
builtin_include_directories)
+     repository_ctx.template(
+         "BUILD",
+-- 
+2.18.2
+
-- 
2.21.0

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#51775): https://lists.yoctoproject.org/g/yocto/message/51775
Mute This Topic: https://lists.yoctoproject.org/mt/78999765/21656
Group Owner: yocto+ow...@lists.yoctoproject.org
Unsubscribe: https://lists.yoctoproject.org/g/yocto/unsub 
[arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to