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
673 stars 248 forks source link

Errors during `BootstrapGNUMake` after upgrading to macos v15 sdk #1099

Open jungleraptor opened 1 year ago

jungleraptor commented 1 year ago

We've observed at least two separate issues during the BootstrapGNUMake step on users who've upgraded their machines to the latest v15 release of the mac command line tools or the new xcode sdk.

Macos version: Venture 13.6

Bazel version: 6.2.0

rules_foreign_cc: d4b19bb010ca5d433850c1d9db0510c2fd395aae758ae37f02930944596220ec

Error 1:

+ cat build.cfg
# Configuration for building GNU Make in the absence of any 'make' program.
# build.cfg.  Generated from build.cfg.in by configure.

# Copyright (C) 1993-2020 Free Software Foundation, Inc.
# This file is part of GNU Make.
#
# GNU Make is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 3 of the License, or (at your option) any later
# version.
#
# GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program.  If not, see <http://www.gnu.org/licenses/>.

# See Makefile.in for comments describing these variables.

top_srcdir='.'

prefix='/private/var/tmp/_bazel_isaac.torres/a00f253b0b0fdebf676f9472a6bd7fc6/sandbox/darwin-sandbox/28/execroot/libswiftnav/bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/rules_foreign_cc/toolchains/make'
exec_prefix=`eval echo ${prefix}`

CC='/private/var/tmp/_bazel_isaac.torres/a00f253b0b0fdebf676f9472a6bd7fc6/sandbox/darwin-sandbox/28/execroot/libswiftnav/external/local_config_cc/cc_wrapper.sh'
AR='/usr/bin/libtool'
CFLAGS='-U_FORTIFY_SOURCE -fstack-protector -Wall -Wthread-safety -Wself-assign -Wunused-but-set-parameter -Wno-free-nonheap-object -fcolor-diagnostics -fno-omit-frame-pointer -g0 -O2 -D_FORTIFY_SOURCE=1 -DNDEBUG -ffunction-sections -fdata-sections -no-canonical-prefixes -Wno-builtin-macro-redefined -D__DATE__=redacted -D__TIMESTAMP__=redacted -D__TIME__=redacted '
CPPFLAGS=''
DEFS='-DHAVE_CONFIG_H'
ARFLAGS='-static -s -o'
LDFLAGS='-rdynamic -undefined dynamic_lookup -headerpad_max_install_names -lc++ -lm -undefined error'
ALLOCA=''
LOADLIBES='   -Wl,-framework -Wl,CoreFoundation'
REMOTE='stub'
OBJEXT='o'
EXEEXT=''
+ ./build.sh
config.status: creating ./lib/alloca.h__
config.status: creating ./lib/fcntl.h__
config.status: creating ./lib/limits.h__
config.status: creating ./lib/fnmatch.h__
config.status: creating ./lib/glob.h__
config.status: creating ./lib/stdint.h__
config.status: creating ./lib/stdio.h__
config.status: creating ./lib/stdlib.h__
config.status: creating ./lib/string.h__
config.status: creating ./lib/sys/types.h__
config.status: creating ./lib/unistd.h__
compiling lib/concat-filename.c...
compiling lib/dirname-lgpl.c...
compiling lib/basename-lgpl.c...
compiling lib/stripslash.c...
compiling lib/exitfail.c...
compiling lib/fd-hook.c...
compiling lib/findprog-in.c...
./lib/findprog-in.c:137:25: error: call to undeclared function 'eaccess'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
                    if (eaccess (progpathname, X_OK) == 0)
                        ^
./lib/findprog-in.c:137:25: note: did you mean 'access'?
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/unistd.h:431:6: note: 'access' declared here
int      access(const char *, int);
         ^
./lib/findprog-in.c:211:21: error: call to undeclared function 'eaccess'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
                if (eaccess (progpathname, X_OK) == 0)
                    ^
2 errors generated.
_____ END BUILD LOGS _____
rules_foreign_cc: Build wrapper script location: bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/rules_foreign_cc/toolchains/make_tool_foreign_cc/wrapper_build_script.sh
rules_foreign_cc: Build script location: bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/rules_foreign_cc/toolchains/make_tool_foreign_cc/build_script.sh
rules_foreign_cc: Build log location: bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/rules_foreign_cc/toolchains/make_tool_foreign_cc/BootstrapGNUMake.log

INFO: Elapsed time: 86.633s, Critical Path: 52.19s
INFO: 52 processes: 23 internal, 29 darwin-sandbox.
FAILED: Build did NOT complete successfully

Error 2:

+ cat build.cfg
# Configuration for building GNU Make in the absence of any 'make' program.
# build.cfg.  Generated from build.cfg.in by configure.

# Copyright (C) 1993-2020 Free Software Foundation, Inc.
# This file is part of GNU Make.
#
# GNU Make is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 3 of the License, or (at your option) any later
# version.
#
# GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program.  If not, see <http://www.gnu.org/licenses/>.

# See Makefile.in for comments describing these variables.

top_srcdir='.'

prefix='/private/var/tmp/_bazel_isaac.torres/d66fcbe6a777458f4c1d3687ee3816a5/sandbox/darwin-sandbox/1522/execroot/foo/bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/rules_foreign_cc/toolchains/make'
exec_prefix=`eval echo ${prefix}`

CC='/private/var/tmp/_bazel_isaac.torres/d66fcbe6a777458f4c1d3687ee3816a5/sandbox/darwin-sandbox/1522/execroot/starling/external/rules_swiftnav/cc/toolchains/llvm/x86_64-darwin/wrappers/clang --sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk'
AR='/usr/bin/libtool'
CFLAGS='-U_FORTIFY_SOURCE --target=x86_64-apple-macosx -U_FORTIFY_SOURCE -fstack-protector -fno-omit-frame-pointer -ffp-contract=off -fcolor-diagnostics -Wall -Wthread-safety -Wself-assign -g0 -O3 -D_FORTIFY_SOURCE=1 -ffunction-sections -fdata-sections -no-canonical-prefixes -Wno-builtin-macro-redefined -D__DATE__=redacted -D__TIMESTAMP__=redacted -D__TIME__=redacted '
CPPFLAGS=''
DEFS='-DHAVE_CONFIG_H'
ARFLAGS='-static -s -o'
LDFLAGS='-rdynamic --target=x86_64-apple-macosx -lm -no-canonical-prefixes -headerpad_max_install_names -undefined dynamic_lookup -Wl,-no_fixup_chains -L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib -lc++ -lc++abi -L/private/var/tmp/_bazel_isaac.torres/d66fcbe6a777458f4c1d3687ee3816a5/sandbox/darwin-sandbox/1522/execroot/foo/external/x86_64-darwin-llvm/lib -undefined error'
ALLOCA=''
LOADLIBES='  '
REMOTE='stub'
OBJEXT='o'
EXEEXT=''
+ ./build.sh
config.status: creating ./lib/alloca.h__
config.status: creating ./lib/fcntl.h__
config.status: creating ./lib/limits.h__
config.status: creating ./lib/fnmatch.h__
config.status: creating ./lib/glob.h__
config.status: creating ./lib/stdint.h__
config.status: creating ./lib/stdio.h__
config.status: creating ./lib/stdlib.h__
config.status: creating ./lib/string.h__
config.status: creating ./lib/sys/types.h__
config.status: creating ./lib/unistd.h__
compiling lib/concat-filename.c...
compiling lib/dirname-lgpl.c...
compiling lib/basename-lgpl.c...
compiling lib/stripslash.c...
compiling lib/exitfail.c...
compiling lib/fd-hook.c...
compiling lib/findprog-in.c...
./lib/findprog-in.c:137:25: warning: implicit declaration of function 'eaccess' is invalid in C99 [-Wimplicit-function-declaration]
                    if (eaccess (progpathname, X_OK) == 0)
                        ^
./lib/findprog-in.c:211:21: warning: implicit declaration of function 'eaccess' is invalid in C99 [-Wimplicit-function-declaration]
                if (eaccess (progpathname, X_OK) == 0)
                    ^
2 warnings generated.
compiling lib/getprogname.c...
compiling lib/fnmatch.c...
compiling lib/glob.c...
./lib/glob.c:823:27: warning: incompatible pointer types passing 'char **' to parameter of type 'char *'; dereference with * [-Wincompatible-pointer-types]
            = (char **) realloc (pglob->gl_pathv,
                                 ^~~~~~~~~~~~~~~
                                 *
./lib/glob.c:942:24: warning: incompatible pointer types passing 'char **' to parameter of type 'char *'; dereference with * [-Wincompatible-pointer-types]
                = (char **) realloc (pglob->gl_pathv,
                                     ^~~~~~~~~~~~~~~
                                     *
./lib/glob.c:997:39: warning: incompatible pointer types passing 'char **' to parameter of type 'char *'; dereference with * [-Wincompatible-pointer-types]
              new_pathv = (char **) realloc (pglob->gl_pathv,
                                             ^~~~~~~~~~~~~~~
                                             *
./lib/glob.c:1388:23: warning: incompatible pointer types passing 'char **' to parameter of type 'char *'; dereference with * [-Wincompatible-pointer-types]
        = (char **) realloc (pglob->gl_pathv,
                             ^~~~~~~~~~~~~~~
                             *
4 warnings generated.
compiling lib/unistd.c...
compiling lib/xmalloc.c...
compiling lib/xalloc-die.c...
compiling lib/xconcat-filename.c...
compiling lib/close.c...
compiling lib/error.c...
compiling lib/msvc-inval.c...
./lib/msvc-inval.c:124:7: warning: implicit declaration of function '_set_invalid_parameter_handler' is invalid in C99 [-Wimplicit-function-declaration]
      _set_invalid_parameter_handler (gl_msvc_invalid_parameter_handler);
      ^
1 warning generated.
compiling lib/msvc-nothrow.c...
./lib/msvc-nothrow.c:25:10: fatal error: 'windows.h' file not found
#include <windows.h>
         ^~~~~~~~~~~
1 error generated.
_____ END BUILD LOGS _____
rules_foreign_cc: Build wrapper script location: bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/rules_foreign_cc/toolchains/make_tool_foreign_cc/wrapper_build_script.sh
rules_foreign_cc: Build script location: bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/rules_foreign_cc/toolchains/make_tool_foreign_cc/build_script.sh
rules_foreign_cc: Build log location: bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/rules_foreign_cc/toolchains/make_tool_foreign_cc/BootstrapGNUMake.log

INFO: Elapsed time: 727.325s, Critical Path: 92.92s
INFO: 2122 processes: 405 internal, 1717 darwin-sandbox.
FAILED: Build did NOT complete successfully
iamricard commented 1 year ago

We're observing this too. From what I could tell, the final LDFLAGS passed to bootstrap GNUMake end up being -Wl,-S -headerpad_max_install_names -lc++ -lm -undefined error -undefined dynamic_lookup. Which seems to make it so that the -undefined dynamic_lookup overrides -undefined error (which was a fixed introduced in https://github.com/bazelbuild/rules_foreign_cc/pull/894).

This patch seems to fix it:

From f84270c6bd0b513dbd77431688ab387ddd0f4916 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ricard=20Sol=C3=A9?= <ricard.sole@datadoghq.com>
Date: Thu, 12 Oct 2023 18:03:11 +0200
Subject: [PATCH] gnumake: unsets -undefined dynamic_build if found

---
 foreign_cc/built_tools/make_build.bzl | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/foreign_cc/built_tools/make_build.bzl b/foreign_cc/built_tools/make_build.bzl
index 0baaa5c..f807d27 100644
--- a/foreign_cc/built_tools/make_build.bzl
+++ b/foreign_cc/built_tools/make_build.bzl
@@ -71,8 +71,10 @@ def _make_tool_impl(ctx):
         if absolute_ar == "libtool" or absolute_ar.endswith("/libtool"):
             arflags.append("-o")

+        _joined_non_sysroot_ldflags = _join_flags_list(ctx.workspace_name, non_sysroot_ldflags)
         if os_name(ctx) == "macos":
-            non_sysroot_ldflags += ["-undefined", "error"]
+            _joined_non_sysroot_ldflags = _joined_non_sysroot_ldflags.replace("-undefined dynamic_lookup", "")
+            _joined_non_sysroot_ldflags += " -undefined error"

         env.update({
             "AR": absolute_ar,
@@ -80,7 +82,7 @@ def _make_tool_impl(ctx):
             "CC": absolute_cc,
             "CFLAGS": _join_flags_list(ctx.workspace_name, non_sysroot_cflags),
             "LD": absolute_ld,
-            "LDFLAGS": _join_flags_list(ctx.workspace_name, non_sysroot_ldflags),
+            "LDFLAGS": _joined_non_sysroot_ldflags,
         })

         configure_env = " ".join(["%s=\"%s\"" % (key, value) for key, value in env.items()])
-- 
2.38.1
vymao commented 1 year ago

Believe I am seeing this as well, MacOS 13.5

(transformers-v2) victor@Victors-MBP cpp % pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
package-id: com.apple.pkg.CLTools_Executables
version: 15.0.0.0.1.1690355577
volume: /
location: /
install-time: 1691358267
codingl2k1 commented 11 months ago

Same issue on MacOS 14

pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
package-id: com.apple.pkg.CLTools_Executables
version: 15.0.0.0.1.1694021235
volume: /
location: /
install-time: 1696925492

I am using the latest version: rules_foreign_cc-0.10.1