# Copyright 2021-2022, 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#+PROPERTY: header-args :mkdirp yes :main no

#+BEGIN_SRC bazel-module :tangle MODULE.bazel
bazel_dep(name = "rules_cc", version = "0.2.17")
#+END_SRC

#+BEGIN_SRC bazel-build :tangle package/BUILD
load("@rules_cc//cc:cc_library.bzl", "cc_library")

cc_library(
    name = "test",
    srcs = ["test.cc"],
    deprecation = "Deprecated!",
)
#+END_SRC

#+BEGIN_SRC C++ :tangle package/test.cc
UnknownType foo;
#+END_SRC

Merged standard output and error from Bazel:

#+BEGIN_SRC fundamental :tangle bazel.out
INFO: Invocation ID: 106c722c-f5b5-47a7-8a68-7c6ea5680d95
Computing main repo mapping: 
Computing main repo mapping: 
Computing main repo mapping: 
Computing main repo mapping: 
Computing main repo mapping: 
Loading: 
Loading: 1 packages loaded
WARNING: %ROOTDIR%/package/BUILD:3:11: target '//package:test' is deprecated: Deprecated!
bazel: Entering directory `%ROOTDIR%/'
Analyzing: target //package:test (6 packages loaded, 6 targets configured)
Analyzing: target //package:test (6 packages loaded, 6 targets configured)

Analyzing: target //package:test (58 packages loaded, 7 targets configured)

Analyzing: target //package:test (76 packages loaded, 429 targets configured)

Analyzing: target //package:test (76 packages loaded, 429 targets configured)

Analyzing: target //package:test (80 packages loaded, 444 targets configured)

INFO: Analyzed target //package:test (84 packages loaded, 465 targets configured).
[2 / 4] Compiling package/test.cc; 0s disk-cache, darwin-sandbox
ERROR: %ROOTDIR%/package/BUILD:3:11: Compiling package/test.cc failed: (Exit 1): cc_wrapper.sh failed: error executing CppCompile command (from cc_library rule target //package:test) external/rules_cc++cc_configure_extension+local_config_cc/cc_wrapper.sh -U_FORTIFY_SOURCE -fstack-protector -Wall -Wthread-safety -Wself-assign -Wunused-but-set-parameter -Wno-free-nonheap-object ... (remaining 21 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
package/test.cc:1:1: error: unknown type name 'UnknownType'
    1 | UnknownType foo;
      | ^
1 error generated.
bazel: Leaving directory `%ROOTDIR%/'
Target //package:test failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 12.217s, Critical Path: 0.40s
INFO: 3 processes: 3 internal.
ERROR: Build did NOT complete successfully
#+END_SRC
