cfrantz / crt_demo

Demo of Compiler Repository Toolkit

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Compiler Repository Toolkit Demonstration

This repository demonstrates how to use the Compiler Repository Toolkit.

Configuration

  • .bazelrc - In order to enable toolchain resolution, this file must contain the following line:

    build --incompatible_enable_cc_toolchain_resolution
    
  • WORKSPACE.bazel - Your workspace file needs to load the crt repository and its dependencies. It must also register the toolchains you want to use.

    load("@crt//config:registration.bzl", "crt_register_toolchains")
    crt_register_toolchains(
        # Choose the toolchains you want:
        arm = True,
        win64 = True,
    )
  • Building software is controlled by constraints. cc_library and cc_binaries can be restricted to certain platforms by use of the target_compatible_with attribute. In order to build software targeted at a particular platform, you can invoke bazel with the --platforms flag:

    bazel build //some:label --platforms=@crt//platforms/arm:cortex_m
  • Platform targets can also be defined using a transition. Transitions cause bazel to evaluate the dependency graph as if a certain configuration were defined. For example, the target_platform rule evaluates the build graph as if --platforms were set to a particular value.

    For example, to build a target for cortex_m:

    target_platform(
        name = "rule-name",
        platform = "@crt//platforms/arm:cortex_m",
        target = "label to a binary artifact",
    )
  • Targets can be executed under a emulation with the runner rule. The runner rule is also a transition rule: it declares the target platform and the execution configuration for that platform.

    For example:

    runner(
        name = "demo",
        binary = ":sieve",
        platform = "@crt//platforms/arm:cortex_m",
        exec_config = "@crt//platforms/arm:qemu",
    )

About

Demo of Compiler Repository Toolkit

License:Apache License 2.0


Languages

Language:C++ 65.0%Language:Starlark 18.6%Language:C 9.8%Language:Assembly 6.6%