Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build_args don't seem to work for cmake #976

Open
TylerBrock opened this issue Oct 23, 2022 · 1 comment
Open

build_args don't seem to work for cmake #976

TylerBrock opened this issue Oct 23, 2022 · 1 comment

Comments

@TylerBrock
Copy link

TylerBrock commented Oct 23, 2022

When creating a cmake target the build_args don't seem to be getting passed to the cmake build command. For example:

WORKSPACE

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")

# This sets up some common toolchains for building targets. For more details, please see
# https://github.com/bazelbuild/rules_foreign_cc/tree/main/docs#rules_foreign_cc_dependencies
rules_foreign_cc_dependencies()

_ALL_CONTENT = """\
filegroup(
    name = "all_srcs",
    srcs = glob(["**"]),
    visibility = ["//visibility:public"],
)
"""

http_archive(
    name = "com_mongodb_wiredtiger",
    urls = ["https://github.com/wiredtiger/wiredtiger/archive/refs/tags/11.0.0.tar.gz"],
    strip_prefix = "wiredtiger-11.0.0",
    sha256 = "1dad4afb604fa0dbebfa8024739226d6faec1ffd9f36b1ea00de86a7ac832168",
    build_file_content = _ALL_CONTENT,
)

BUILD

load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")
cmake(
    name = "wiredtiger",
    lib_source = "@com_mongodb_wiredtiger//:all_srcs",
    lib_name = "libwiredtiger",
    generate_args = ["-DENABLE_STATIC=1"],
    build_args = ["-j10"],
) 

This seems to build a lot slower than running cmake build -j10 or cmake build --parallel 10 manually myself for the library. Is there any way to have rules_foreign_cc show the output of the command used to invoke cmake? I'd love to be able to have some parallelism in my foreign_cc builds.

Also this is a pretty hacky way to get the parallelism -- it would be great if rules_foreign_cc could detect my number of processors and do this automatically to speed up builds.

@jsharpe
Copy link
Collaborator

jsharpe commented Oct 24, 2022

You can find the scripts generated to see the command line that bazel is invoking cmake with in the build artifacts in the _foreign_cc directory.
Regarding parallel build - see #329 for some discussion around the complexity of supporting this. The easiest way to get parallelism at the moment is to use ninja as the generator as ninja does what you are asking - it automatically spawns jobs based on the number of processors on the machine. Note though that this can lead to over subscription of your build machine as bazel assumes each action only requires 1 core and so will concurrently spawn other actions at the same time.

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

No branches or pull requests

2 participants