2
0
Fork 0
mirror of https://github.com/bazel-contrib/rules_foreign_cc synced 2024-11-25 17:31:25 +00:00
rules_foreign_cc/for_workspace/cmake_build.bzl
irengrig 0aab4e65c5
Win changes (#85)
* Allow execution on Windows, use utils_win.sh, copy instead of symlink

* Prepare for execution on Windows: set up environment, convert path

also rename TMPDIR since it can clash with widely used variable
2018-09-11 11:43:13 +02:00

45 lines
1.2 KiB
Python

""" Rule for building CMake from sources. """
load(":detect_root.bzl", "detect_root")
def _cmake_tool(ctx):
root = detect_root(ctx.attr.cmake_srcs)
cmake = ctx.actions.declare_directory("cmake")
script_text = "\n".join([
"BUILD_DIR=$(pwd)",
"export BUILD_TMPDIR=$(mktemp -d)",
"cp -R ./{}/. $BUILD_TMPDIR".format(root),
"mkdir " + cmake.path,
"pushd $BUILD_TMPDIR",
"./bootstrap --prefix=install",
"make install",
"cp -a ./install/. $BUILD_DIR/" + cmake.path,
"popd",
])
ctx.actions.run_shell(
mnemonic = "BootstrapCMake",
inputs = ctx.attr.cmake_srcs.files,
outputs = [cmake],
tools = [],
use_default_shell_env = True,
command = script_text,
execution_requirements = {"block-network": ""},
)
return [DefaultInfo(files = depset([cmake]))]
""" Rule for building CMake. Invokes bootstrap script and make install.
Attributes:
cmake_srcs - target with the CMake sources
"""
cmake_tool = rule(
attrs = {
"cmake_srcs": attr.label(mandatory = True),
},
fragments = ["cpp"],
output_to_genfiles = True,
implementation = _cmake_tool,
)