Skip to content

zadlg/rules_gnumake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

9058b93 · Mar 10, 2024

History

27 Commits
Mar 10, 2024
Mar 10, 2024
Mar 10, 2024
Mar 10, 2024
Feb 14, 2024
Mar 10, 2024
Feb 11, 2024
Feb 11, 2024
Mar 10, 2024
Feb 12, 2024
Feb 11, 2024
Mar 10, 2024
Feb 19, 2024
Feb 19, 2024

Repository files navigation

GNU Make toolchain for Buck2.

This repository implements a Buck2 toolchain for using GNU Make.

GNU Make binaries are not downloaded from some source. Instead, the source code is built from the source.

TL;DR: See gnumake.

Dependencies

python_bootstrap, genrule and cxx toolchains.

python_bootstrap, genrule and cxx toolchains must be enabled.

To do so, make sure that the following two rules are called:

load("@prelude//toolchains:cxx.bzl", "system_cxx_toolchain")
load("@prelude//toolchains:genrule.bzl", "system_genrule_toolchain")
load("@prelude//toolchains:python.bzl", "system_python_bootstrap_toolchain", "system_python_toolchain")

system_python_bootstrap_toolchain(
    name = "python_bootstrap",
    visibility = ["PUBLIC"],
)

system_genrule_toolchain(
    name = "genrule",
    visibility = ["PUBLIC"],
)

system_cxx_toolchain(
    name = "cxx",
    visibility = ["PUBLIC"],
)

Installation

Clone this repository to your repository. Then, to enable the GNU Make toolchain, add the following cell:

# .buckconfig

[repositories]
rules_gnumake = <path_to_gnumake>/

[parser]
target_platform_detector_spec = target:rules_gnumake//...->prelude//platforms:default

Example

First, we clone the repository under external_deps/rules_gnumake:

$ mkdir -p external_deps/rules_gnumake
$ git clone 'https://github.com/zadlg/rules_gnumake.git' external_deps/rules_gnumake

Then, we declare the cell by adding an entry under the section repositories of the .buckconfig file:

# .buckconfig

[repositories]
rules_gnumake = external_deps/rules_gnumake

Finally, we add a new entry under the section parser to tell Buck which platforms should be targeted for the rules_gnumake cell:

# .buckconfig

[parser]
target_platform_detector_spec = target:rules_gnumake//...->prelude//platforms:default

Usage

Enable the toolchain

First, we have to enable the GNU Make toolchain. To do so, edit your toolchain BUCK file (usually under toolchains/BUCK), and add the following:

load("@rules_gnumake//gnumake:gnumake.bzl", "gnumake_toolchain")

gnumake_toolchain(
    name = "gnumake",
    visibility = ["PUBLIC"],
)

Import and use the rule

Once the toolchain is enabled, one can do the following:

# BUCK file

load("@rules_gnumake//gnumake:rules.bzl", "gnumake")

gnumake(
    name = "mylib",
    srcs = glob(["Makefile", "*.c"]),
    compiler_flags = ["-DENABLE_MY_FEATURE"],
)

To build your target, simply use buck:

$ buck2 build //:mylib

Examples

See examples/.

License

Apache2, see License.