bazel-contrib / rules_foreign_cc

Build rules for interfacing with "foreign" (non-Bazel) build systems (CMake, configure-make, GNU Make, boost, ninja, Meson)
https://bazel-contrib.github.io/rules_foreign_cc
Apache License 2.0
674 stars 248 forks source link

sysroot flag missing from cppflags #1306

Closed voxeljorge closed 3 weeks ago

voxeljorge commented 3 weeks ago

The sysroot flag is missing from cppflags which can cause some mis-detections in configure scripts. The FFmpeg configure script is an example of this, where building with toolchains_llvm on darwin results in build failures with the following in the log:

/private/var/tmp/_bazel_jorge/862b8030974cf02a39c34a9f577dde03/sandbox/darwin-sandbox/8940/execroot/_main/external/toolchains_llvm~~llvm~llvm_toolchain/bin/cc_wrapper.sh -std=c17 -c -o /var/folders/xs/28lmfy2175xc86hm2yn27z440000gn/T//ffconf.qXmb5gvD/test.o /var/folders/xs/28lmfy2175xc86hm2yn27z440000gn/T//ffconf.qXmb5gvD/test.c
/var/folders/xs/28lmfy2175xc86hm2yn27z440000gn/T//ffconf.qXmb5gvD/test.c:1:10: fatal error: 'ctype.h' file not found
    1 | #include <ctype.h>
      |          ^~~~~~~~~
1 error generated.
check_host_cflags_cc -std=c11 ctype.h __STDC_VERSION__ >= 201112L
test_host_cflags_cc -std=c11 ctype.h __STDC_VERSION__ >= 201112L
test_host_cc -std=c11
BEGIN /var/folders/xs/28lmfy2175xc86hm2yn27z440000gn/T//ffconf.qXmb5gvD/test.c
    1   #include <ctype.h>
    2   #if !(__STDC_VERSION__ >= 201112L)
    3   #error "unsatisfied condition: __STDC_VERSION__ >= 201112L"
    4   #endif
END /var/folders/xs/28lmfy2175xc86hm2yn27z440000gn/T//ffconf.qXmb5gvD/test.c
/private/var/tmp/_bazel_jorge/862b8030974cf02a39c34a9f577dde03/sandbox/darwin-sandbox/8940/execroot/_main/external/toolchains_llvm~~llvm~llvm_toolchain/bin/cc_wrapper.sh -std=c11 -c -o /var/folders/xs/28lmfy2175xc86hm2yn27z440000gn/T//ffconf.qXmb5gvD/test.o /var/folders/xs/28lmfy2175xc86hm2yn27z440000gn/T//ffconf.qXmb5gvD/test.c
/var/folders/xs/28lmfy2175xc86hm2yn27z440000gn/T//ffconf.qXmb5gvD/test.c:1:10: fatal error: 'ctype.h' file not found
    1 | #include <ctype.h>
      |          ^~

As you can see there is no sysroot specified on this command, while previous checks in this same log do show the sysroot pointing at my xcode installation. I suspect this is because the sysroot is in CFLAGS but not CPPFLAGS (which lists flags only necessary to run the pre-processor)

voxeljorge commented 3 weeks ago

Ah actually this appears to be yet another interesting unusual configuration detail regarding ffmpeg, --host-cc and --host-cflags need to be set or configure may not behave correctly.