bazel-contrib / bazel-contrib/rules_foreign_cc

Passing Environment Variables in Bazel for rules_foreign_cc while using QNX Toolchain

Open
#1,367 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Starlark
Stars
737
Forks
270
PR merge metrics
No merged PRs in 30d

Description

I am currently working on building an example application using rules_foreign_cc with Bazel for QNX toolchain. While I am able to successfully build the hello-world application using the QNX toolchain which use cc_binary, I am facing an issue when building an example project that relies on make.

Project Structure:

![Image](https://github.com/user-attachments/assets/60b47089-89f9-49a0-8cdd-a1d13c99fed7)

**Working Case (hello-world)**

BUILD file (main/BUILD):

```
load("@rules_cc//cc:defs.bzl", "cc_binary")
cc_binary(
name = "hello-world",
srcs = ["hello-world.cc"],
)
```

**Build Command:**

bazel build --platforms=//platforms:qcc_x86_64 --sandbox_debug //main:hello-world --config=qnx_env Environment Variables in Sandbox (Visible):

QNX_HOST=/home/shravan/qnx800_2/host/linux/x86_64 QNX_TARGET=/home/shravan/qnx800_2/target/qnx

The build completes successfully.

**Failing Case (example with rules_foreign_cc)**

BUILD file (example/BUILD):

```
load("@rules_foreign_cc//foreign_cc:make.bzl", "make")
filegroup(
name = "srcs",
srcs = glob(["**"]),
visibility = ["//example/example:__pkg__"],
)

make(
name = "example",
lib_source = "srcs",
out_data_dirs = ["share"],
out_static_libs = ["example.a"],
visibility = ["//example/example:__pkg__"],
)
```
**Build command:**

bazel build --platforms=//platforms:qcc_x86_64 --sandbox_debug //example:example --config=qnx_env

**Error message:**

configure: error: C compiler cannot create executables ntox86_64-gcc: fatal error: error: environment variables 'QNX_HOST' and 'QNX_TARGET' not defined Environment Variables in Sandbox (Missing QNX-related paths):

PATH=/home/shravan/qnx800_2/host/linux/x86_64/usr/bin:/home/shravan/.qnx/bin:/jre/bin:/host/common/bin:/home/shravan/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin TMPDIR=/tmp

What I Have Tried: Set --action_env in .bazelrc:

```
build:qnx_env --action_env=QNX_HOST=/home/shravan/qnx800_2/host/linux/x86_64
build:qnx_env --action_env=QNX_TARGET=/home/shravan/qnx800_2/target/qnx

```
Verified that the variables are present in the hello-world build but missing when rules_foreign_cc is used.

Question: How can I ensure that QNX_HOST and QNX_TARGET are passed correctly when using rules_foreign_cc with Bazel? Is there a way to explicitly define these variables for rules_foreign_cc?

Contributor guide

Open the contributing guide

Research direction

Start with example/BUILD, the rules_foreign_cc make rule loaded from foreign_cc/make.bzl, and the .bazelrc qnx_env configuration. Reproduce the failing build with --sandbox_debug and compare its action environment with the working //main:hello-world build; done means QNX_HOST and QNX_TARGET are available to the make-based configure step.

Written by the indexing model from the issue text.

Assessment

Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.