Skip to content

Use -j parameter directly instead of GNUMAKEFLAGS#1491

Open
JSGette wants to merge 4 commits intobazel-contrib:mainfrom
JSGette:jsgette/macos_make_j_parameter
Open

Use -j parameter directly instead of GNUMAKEFLAGS#1491
JSGette wants to merge 4 commits intobazel-contrib:mainfrom
JSGette:jsgette/macos_make_j_parameter

Conversation

@JSGette
Copy link
Copy Markdown

@JSGette JSGette commented Mar 16, 2026

make that is installed on macos Tahoe 26.2 is too old and doesn't support GNUMAKEFLAGS. It makes usage of resource size for make and configure make unusable on macos (technically, you can use them but mac will just ignore -j parameter altogether and just build everything in a single thread). This PR addresses it by introducing a helper function that sets -j directly as an argument. Original intention of using GNUMAKEFLAGS was to not make nmake choke on unknown -j argument, the helper function has a check to ignore -j in case it's nmake and not GNU make.

Currently installed version of make:

GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

@novas0x2a
Copy link
Copy Markdown
Collaborator

So, unfortunately, this approach doesn't work when make is invoked indirectly, something the env-variable-based version generally works around. This perhaps potentially speaks to the need to replace make with a wrapper (similar to ninja and meson), sigh. Maybe we need a more centralized approach to writing wrappers, since it seems like pretty much every tool needs one?

More directly in your case, though, I'd probably recommend that you use the rfcc source-built make instead of the system make, since GNUMAKEFLAGS came with gmake 4.0 (released in 2013) and you're probably going to run into other bugs with such an old system make. You can do that by setting register_preinstalled_tools=False and then (if you want to use other preinstalled tools, though i'd recommend against that in general) calling register_toolchains individually on any preinstalled toolchains you want to use

@novas0x2a novas0x2a self-requested a review March 19, 2026 06:24
@JSGette
Copy link
Copy Markdown
Author

JSGette commented Mar 19, 2026

So, unfortunately, this approach doesn't work when make is invoked indirectly, something the env-variable-based version generally works around. This perhaps potentially speaks to the need to replace make with a wrapper (similar to ninja and meson), sigh. Maybe we need a more centralized approach to writing wrappers, since it seems like pretty much every tool needs one?

More directly in your case, though, I'd probably recommend that you use the rfcc source-built make instead of the system make, since GNUMAKEFLAGS came with gmake 4.0 (released in 2013) and you're probably going to run into other bugs with such an old system make. You can do that by setting register_preinstalled_tools=False and then (if you want to use other preinstalled tools, though i'd recommend against that in general) calling register_toolchains individually on any preinstalled toolchains you want to use

The funny thing is that I experienced a bug using source-build make but didn't have any issues with the one that is already on my system:

register_toolchains(
    "@rules_foreign_cc//toolchains:preinstalled_cmake_toolchain",
    "@rules_foreign_cc//toolchains:preinstalled_make_toolchain",
    "@rules_foreign_cc//toolchains:preinstalled_ninja_toolchain",
    "@rules_foreign_cc//toolchains:preinstalled_meson_toolchain",
    "@rules_foreign_cc//toolchains:preinstalled_autoconf_toolchain",
    "@rules_foreign_cc//toolchains:preinstalled_automake_toolchain",
    "@rules_foreign_cc//toolchains:preinstalled_m4_toolchain",
    "@rules_foreign_cc//toolchains:preinstalled_pkgconfig_toolchain",
)

The challenge in our case is that we support Windows, Linux and MacOS (both architectures) and it makes things a lot more complicated

@novas0x2a
Copy link
Copy Markdown
Collaborator

we use the source-built make on all three of those, too; what problem did you run into?

@JSGette
Copy link
Copy Markdown
Author

JSGette commented Mar 19, 2026

pkgconfig fails to build on Windows. I ensured that both sed and expr are available, I have set BAZEL_SH, I tried manipulating with PATH but couldn't make this work so just used whatever is already there as a part of MinGW:

ERROR: C:/users/containeradministrator/_bazel_containeradministrator/4tbrhmfj/external/rules_foreign_cc+/toolchains/private/BUILD.bazel:177:15: BootstrapPkgConfig external/rules_foreign_cc+/toolchains/private/pkgconfig [for tool] failed: (Exit 1): bash.exe failed: error executing BootstrapPkgConfig command (from target @[@rules_foreign_cc](https://t.me/rules_foreign_cc)+//toolchains/private:pkgconfig_tool_default) 
  cd /d C:/users/containeradministrator/_bazel_containeradministrator/4tbrhmfj/execroot/_main
  SET CMAKE_BUILD_PARALLEL_LEVEL=2
    SET MESON_NUM_PROCESSES=2
    SET NINJA_JOBS=2
    SET PATH=C:\tools\msys64\usr\bin;C:\tools\msys64\bin;C:\Windows;C:\Windows\System32;C:\Windows\System32\WindowsPowerShell\v1.0
    SET RUNFILES_MANIFEST_ONLY=1
  C:\tools\msys64\usr\bin\bash.exe -c bazel-out/x64_windows-opt-exec-ST-d57f47055a04/bin/external/rules_foreign_cc+/toolchains/private/pkgconfig_tool_default_foreign_cc/wrapper_build_[script.sh](https://script.sh/)
# Configuration: bf931d2df1d54d768b946d7f1a036691b586a27004e35ed93282d8b2603bf048
# Execution platform: @[@platforms](https://t.me/platforms)//host:host
rules_foreign_cc: Build failed!
rules_foreign_cc: Printing build logs:
___ BEGIN BUILD LOGS ___
+ PATH='C:/tools/msys64/usr/bin;C:/tools/msys64/mingw64/bin'
+ AR=C:/tools/msys64/mingw64/bin/ar
+ ARFLAGS=
+ CC=C:/tools/msys64/mingw64/bin/gcc
+ CFLAGS='-no-canonical-prefixes -fno-canonical-system-headers -Wno-builtin-macro-redefined -DDATE=\\"redacted\\" -DTIMESTAMP=\\"redacted\\" -DTIME=\\"redacted\\" -Wno-int-conversion -std=gnu90'
+ LD=C:/tools/msys64/mingw64/bin/g++
+ LDFLAGS=-Wl,-S
+ MAKE=C:/users/containeradministrator/_bazel_containeradministrator/4tbrhmfj/execroot/_main/bazel-out/x64_windows-opt-exec-ST-d57f47055a04/bin/external/rules_foreign_cc+/toolchains/private/make/bin/make.exe
+ ./configure --with-internal-glib --prefix=C:/users/containeradministrator/_bazel_containeradministrator/4tbrhmfj/execroot/_main/bazel-out/x64_windows-opt-exec-ST-d57f47055a04/bin/external/rules_foreign_cc+/toolchains/private/pkgconfig
./configure: line 482: sed: command not found
./configure: line 481: expr: command not found
./configure: line 482: sed: command not found
./configure: line 496: sed: command not found
: error: cannot create .lineno; rerun with a POSIX shell
___ END BUILD LOGS ___
rules_foreign_cc: Build wrapper script location: bazel-out/x64_windows-opt-exec-ST-d57f47055a04/bin/external/rules_foreign_cc+/toolchains/private/pkgconfig_tool_default_foreign_cc/wrapper_build_[script.sh](https://script.sh/)
rules_foreign_cc: Build script location: bazel-out/x64_windows-opt-exec-ST-d57f47055a04/bin/external/rules_foreign_cc+/toolchains/private/pkgconfig_tool_default_foreign_cc/build_[script.sh](https://script.sh/)
rules_foreign_cc: Build log location: bazel-out/x64_windows-opt-exec-ST-d57f47055a04/bin/external/rules_foreign_cc+/toolchains/private/pkgconfig_tool_default_foreign_cc/BootstrapPkgConfig.log
rules_foreign_cc: Keeping these below directories for debug, but note that the directories inside a sandbox
rules_foreign_cc: are still cleaned unless you specify the '--sandbox_debug' Bazel command line flag.
rules_foreign_cc: Build Dir: C:/users/containeradministrator/_bazel_containeradministrator/4tbrhmfj/execroot/_main/bazel-out/x64_windows-opt-exec-ST-d57f47055a04/bin/external/rules_foreign_cc+/toolchains/private/[pkgconfig.build](https://pkgconfig.build/)_tmpdir
rules_foreign_cc: Deps Dir: C:/users/containeradministrator/_bazel_containeradministrator/4tbrhmfj/execroot/_main/bazel-out/x64_windows-opt-exec-ST-d57f47055a04/bin/external/rules_foreign_cc+/toolchains/private/pkgconfig.ext_build_deps

@novas0x2a
Copy link
Copy Markdown
Collaborator

So, that didn't even get far enough to invoke make, so whatever's happening with system make vs source make is a side effect. Things to try:

  1. are you absolutely completely sure that all three of these: 1) the bash that is being used in the script 2) the bash you set BAZEL_SH to 3) whatever bash is first in your PATH outside bazel are the mingw bash and not the git-bash wrapper? The git-bash wrapper is a pretty reliable path to sadness.
  2. Are you following all the guidance here including running from powershell or cmd, not bash?
  3. Your terminal looks like it's corrupting pathnames... (wrapper_build_[script.sh](https://script.sh/)) (hopefully that's just cosmetic?
  4. With those out of the way, the next step would probably be to copy all of the logs mentioned after the END BUILD LOGS block; do a successful build with the system make, copy the files out, then bazel clean and repeat with the src make, then diff them. We might learn something from that.

@novas0x2a
Copy link
Copy Markdown
Collaborator

novas0x2a commented Mar 19, 2026

@JSGette just realized: your log shows this:

+ PATH='C:/tools/msys64/usr/bin;C:/tools/msys64/mingw64/bin'

bash would interpret that as

(
"C"
"/tools/msys64/usr/bin;C"
"/tools/msys64/mingw64/bin"
)

and that would explain why it can't find sed and friends.

Not sure if this is an option for you, but in the strongest possible way I recommend using --incompatible_strict_action_env; it is so difficult to deal with the fractal ways build machines can be different, and controlling the env helps so much

gh-worker-dd-mergequeue-cf854d bot pushed a commit to DataDog/datadog-agent that referenced this pull request Mar 21, 2026
Depends on #48082.

### Motivation
Moving the unreleased tip of main allows to address Bazel 9 related issues instead of patching locally:
- bazel-contrib/rules_foreign_cc#1493
- bazel-contrib/rules_foreign_cc#1492 (`CcInfo` and other `Cc*` symbols)

Other notable commits since:
- bazel-contrib/rules_foreign_cc#1483
- bazel-contrib/rules_foreign_cc#1490
- bazel-contrib/rules_foreign_cc#1496

### Additional Notes
Patches 0002 (bazel-contrib/rules_foreign_cc#1452) and 0003 (bazel-contrib/rules_foreign_cc#1491) are still carried locally as neither has landed upstream yet (but we're working on it).

Co-authored-by: regis.desgroppes <regis.desgroppes@datadoghq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants