GithubHelp home page GithubHelp logo

agoessling / bazel_bootlin Goto Github PK

View Code? Open in Web Editor NEW
12.0 4.0 11.0 37 KB

Hermetic C/C++ toolchains for Bazel

License: MIT License

Starlark 48.48% Python 18.63% C 0.30% C++ 0.44% Shell 32.15%
bazel toolchain cpp c hermetic toolchain-packages toolchains

bazel_bootlin's Introduction

bazel_bootlin

Provides hermetic Bazel C/C++ toolchains based on Buildroot toolchains provided by Bootlin.

Usage

WORKSPACE

To incorporate bazel_bootlin toolchains into your project, copy the following into your WORKSPACE file.

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

http_archive(
    name = "bazel_bootlin",
    # See release page for latest version url and sha.
)

load("@bazel_bootlin//toolchains:toolchains.bzl", "bootlin_all_toolchain_deps")

bootlin_all_toolchain_deps()

This will bring all of the available toolchains (and their associated platform definitions) into your project. The toolchains will only be downloaded when actually utilized, but if you prefer, you can only import a specific toolchain:

load("@bazel_bootlin//toolchains:toolchains.bzl", "bootlin_toolchain_deps")

bootlin_toolchain_deps(
    architecture = "x86-64-core-i7",
    cstdlib = "glibc",
    buildroot_version = "2020.08-1",
)

Available Toolchains

Currently bazel_bootlin only provides the "glibc--stable" version of the following Bootlin toolchains:

Architecture cstdlib Buildroot Version
x86-64 glibc 2022.08-1, 2021.11-5
x86-64-core-i7 glibc 2020.08-1
aarch64 glibc, musl 2021.11-1, 2020.08-1
armv7-eabihf glibc 2020.08-1
riscv64-lp64d glibc 2024.02-1

This list is easily expanded. If a toolchain of interest isn't available feel free to submit and issue, or alternatively take a look at _AVAILABLE_TOOLCHAINS in setup_toolchains.py and create a pull request. Don't forget to actually run setup_toolchains.py after adding a toolchain and before submitting a PR:

bazel run //:setup_toolchains

Platforms

bazel_bootlin defines a different platform for each toolchain that is included. The platforms specify constraint_value for the canonical @platforms//os:os and @platforms//cpu:cpu constraint_setting:

platform(
    name = "{architecture}-linux-{cstdlib}-{buildroot_version}",
    constraint_values = [
        "@platforms//cpu:{architecture}",
        "@platforms//os:linux",
        "@bazel_bootlin//platforms:{buildroot_version}",
    ],
)

Specifying one of these platforms will cause Bazel to use the corresponding toolchain during build.

Building With Toolchain

In order to enable toolchain selection via platforms, Bazel requires a special flag along with the target platform:

bazel build --incompatible_enable_cc_toolchain_resolution --platforms=@bazel_bootlin//platforms:{architecture}-linux-{cstdlib}-{buildroot_version} //...

The ergonomics can be improved by placing the flags in a .bazelrc file:

build --incompatible_enable_cc_toolchain_resolution
build --platforms=@bazel_bootlin//platforms:{architecture}-linux-{cstdlib}-{buildroot_version}

Then a simple bazel build //... will utilize the desired toolchain.

bazel_bootlin's People

Contributors

agoessling avatar matte1 avatar oliverlee avatar phongt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

bazel_bootlin's Issues

MAC OS support

Hello,
Thanks for this great repo!

In any case, do you have any plan to support mac os with Apple silicon chip?
Also, I am wondering if I can build a target for linux machine deployment on Mac OS host.

Thanks in advance.

aarch64 doesn't use hermetic toolchain

I did a fresh checkout of the repo and on aarch64 It looks like /usr/bin/gcc is used instead of the gcc wrapper.

uname -a
Linux aarch64 5.15.49-linuxkit-pr #1 SMP PREEMPT Thu May 25 07:27:39 UTC 2023 aarch64 aarch64 aarch64 GNU/Linux
bazel --version
bazel 6.3.2

bazel build //... -s --platforms=@bazel_bootlin//platforms:aarch64-linux-gnu-2021.11-1
SUBCOMMAND: # //test:test_c [action 'Compiling test/test_c.c', configuration: 95105f2896e296b36620e135202c42732efc426859ef352e00c38145703cde07, execution platform: @local_config_platform//:host]
(cd /home/vscode/.cache/bazel/_bazel_vscode/1b5ddfc1c5d8e8325371095e85f8fe98/execroot/bazel_bootlin && \
  exec env - \
    PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
    PWD=/proc/self/cwd \
  /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -MD -MF bazel-out/aarch64-fastbuild/bin/test/_objs/test_c/test_c.pic.d '-frandom-seed=bazel-out/aarch64-fastbuild/bin/test/_objs/test_c/test_c.pic.o' -fPIC '-DBAZEL_CURRENT_REPOSITORY=""' -iquote . -iquote bazel-out/aarch64-fastbuild/bin -iquote external/bazel_tools -iquote bazel-out/aarch64-fastbuild/bin/external/bazel_tools -fno-canonical-system-headers -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' -c test/test_c.c -o bazel-out/aarch64-fastbuild/bin/test/_objs/test_c/test_c.pic.o)
# Configuration: 95105f2896e296b36620e135202c42732efc426859ef352e00c38145703cde07
# Execution platform: @local_config_platform//:host
SUBCOMMAND: # //test:test_cpp [action 'Compiling test/test_cpp.cc', configuration: 95105f2896e296b36620e135202c42732efc426859ef352e00c38145703cde07, execution platform: @local_config_platform//:host]
(cd /home/vscode/.cache/bazel/_bazel_vscode/1b5ddfc1c5d8e8325371095e85f8fe98/execroot/bazel_bootlin && \
  exec env - \
    PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
    PWD=/proc/self/cwd \
  /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer '-std=c++0x' -MD -MF bazel-out/aarch64-fastbuild/bin/test/_objs/test_cpp/test_cpp.pic.d '-frandom-seed=bazel-out/aarch64-fastbuild/bin/test/_objs/test_cpp/test_cpp.pic.o' -fPIC '-DBAZEL_CURRENT_REPOSITORY=""' -iquote . -iquote bazel-out/aarch64-fastbuild/bin -iquote external/bazel_tools -iquote bazel-out/aarch64-fastbuild/bin/external/bazel_tools -fno-canonical-system-headers -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' -c test/test_cpp.cc -o bazel-out/aarch64-fastbuild/bin/test/_objs/test_cpp/test_cpp.pic.o)
# Configuration: 95105f2896e296b36620e135202c42732efc426859ef352e00c38145703cde07
# Execution platform: @local_config_platform//:host
SUBCOMMAND: # //test:test_c [action 'Linking test/test_c', configuration: 95105f2896e296b36620e135202c42732efc426859ef352e00c38145703cde07, execution platform: @local_config_platform//:host]
(cd /home/vscode/.cache/bazel/_bazel_vscode/1b5ddfc1c5d8e8325371095e85f8fe98/execroot/bazel_bootlin && \
  exec env - \
    PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
    PWD=/proc/self/cwd \
  /usr/bin/gcc @bazel-out/aarch64-fastbuild/bin/test/test_c-2.params)
# Configuration: 95105f2896e296b36620e135202c42732efc426859ef352e00c38145703cde07
# Execution platform: @local_config_platform//:host
SUBCOMMAND: # //test:test_cpp [action 'Linking test/test_cpp', configuration: 95105f2896e296b36620e135202c42732efc426859ef352e00c38145703cde07, execution platform: @local_config_platform//:host]
(cd /home/vscode/.cache/bazel/_bazel_vscode/1b5ddfc1c5d8e8325371095e85f8fe98/execroot/bazel_bootlin && \
  exec env - \
    PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
    PWD=/proc/self/cwd \
  /usr/bin/gcc @bazel-out/aarch64-fastbuild/bin/test/test_cpp-2.params)
# Configuration: 95105f2896e296b36620e135202c42732efc426859ef352e00c38145703cde07
# Execution platform: @local_config_platform//:host
INFO: Elapsed time: 10.369s, Critical Path: 1.28s
INFO: 15 processes: 11 internal, 4 processwrapper-sandbox.
INFO: Build completed successfully, 15 total actions

Here is the output from x64 ubuntu:

uname -a
Linux x86 5.15.49-linuxkit-pr #1 SMP PREEMPT Thu May 25 07:27:39 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

bazel --version
bazel 6.3.2

bazel build //... -s --platforms=@bazel_bootlin//platforms:x86-64-linux-gnu-2022.08-1
SUBCOMMAND: # //test:test_cpp [action 'Compiling test/test_cpp.cc', configuration: 4dff85ffdc8e7302948846e7d4e1db364902c5cc05c8d89536748cd758395c6c, execution platform: @local_config_platform//:host]
(cd /home/vscode/.cache/bazel/_bazel_vscode/1b5ddfc1c5d8e8325371095e85f8fe98/execroot/bazel_bootlin && \
  exec env - \
    PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
    PWD=/proc/self/cwd \
  toolchains/tool_wrappers/x86-64/2022.08-1/x86-64-linux-gnu-2022.08-1-gcc -MD -MF bazel-out/k8-fastbuild/bin/test/_objs/test_cpp/test_cpp.pic.d '-frandom-seed=bazel-out/k8-fastbuild/bin/test/_objs/test_cpp/test_cpp.pic.o' -fPIC '-DBAZEL_CURRENT_REPOSITORY=""' -iquote . -iquote bazel-out/k8-fastbuild/bin -iquote external/bazel_tools -iquote bazel-out/k8-fastbuild/bin/external/bazel_tools -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -fdiagnostics-color -no-canonical-prefixes -fno-canonical-system-headers '--sysroot=external/x86-64-linux-gnu-2022.08-1/x86_64-buildroot-linux-gnu/sysroot' -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' '-std=c++17' -c test/test_cpp.cc -o bazel-out/k8-fastbuild/bin/test/_objs/test_cpp/test_cpp.pic.o)
# Configuration: 4dff85ffdc8e7302948846e7d4e1db364902c5cc05c8d89536748cd758395c6c
# Execution platform: @local_config_platform//:host
SUBCOMMAND: # //test:test_c [action 'Compiling test/test_c.c', configuration: 4dff85ffdc8e7302948846e7d4e1db364902c5cc05c8d89536748cd758395c6c, execution platform: @local_config_platform//:host]
(cd /home/vscode/.cache/bazel/_bazel_vscode/1b5ddfc1c5d8e8325371095e85f8fe98/execroot/bazel_bootlin && \
  exec env - \
    PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
    PWD=/proc/self/cwd \
  toolchains/tool_wrappers/x86-64/2022.08-1/x86-64-linux-gnu-2022.08-1-gcc -MD -MF bazel-out/k8-fastbuild/bin/test/_objs/test_c/test_c.pic.d '-frandom-seed=bazel-out/k8-fastbuild/bin/test/_objs/test_c/test_c.pic.o' -fPIC '-DBAZEL_CURRENT_REPOSITORY=""' -iquote . -iquote bazel-out/k8-fastbuild/bin -iquote external/bazel_tools -iquote bazel-out/k8-fastbuild/bin/external/bazel_tools -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -fdiagnostics-color -no-canonical-prefixes -fno-canonical-system-headers '--sysroot=external/x86-64-linux-gnu-2022.08-1/x86_64-buildroot-linux-gnu/sysroot' -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' -c test/test_c.c -o bazel-out/k8-fastbuild/bin/test/_objs/test_c/test_c.pic.o)
# Configuration: 4dff85ffdc8e7302948846e7d4e1db364902c5cc05c8d89536748cd758395c6c
# Execution platform: @local_config_platform//:host
ERROR: /home/vscode/bazel_bootlin/test/BUILD:7:8: Compiling test/test_c.c failed: undeclared inclusion(s) in rule '//test:test_c':
this rule is missing dependency declarations for the following files included by 'test/test_c.c':
  '/proc/self/cwd/external/x86-64-linux-gnu-2022.08-1/lib/gcc/x86_64-buildroot-linux-gnu/11.3.0/include/stddef.h'
  '/proc/self/cwd/external/x86-64-linux-gnu-2022.08-1/lib/gcc/x86_64-buildroot-linux-gnu/11.3.0/include/stdarg.h'
INFO: Elapsed time: 13.111s, Critical Path: 4.29s
INFO: 3 processes: 3 internal.
FAILED: Build did NOT complete successfully

It's using the gcc from toolchain but for some reason it doesn't find these headers. I might have closed out this too soon: #5

execvp fails for x86-64-linux-gnu-2022.08-1

Hi, I'm trying to setup this toolchain and for some reason it works for aarch64 but not x86-64:

failed: (Exit 1): x86-64-linux-gnu-2022.08-1-gcc failed: error executing command (from target //common:hex_dump) external/bazel_bootlin/toolchains/tool_wrappers/x86-64/2022.08-1/x86-64-linux-gnu-2022.08-1-gcc -MD -MF bazel-out/k8-fastbuild/bin/common/_objs/hex_dump/hex_dump.pic.d ... (remaining 40 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
src/main/tools/process-wrapper-legacy.cc:80: "execvp(external/bazel_bootlin/toolchains/tool_wrappers/x86-64/2022.08-1/x86-64-linux-gnu-2022.08-1-gcc, ...)": No such file or directory

Here is the WORKSPACE file:

git_repository(
    name = "bazel_bootlin",
    remote = "https://github.com/agoessling/bazel_bootlin",
    commit = "b65607ab1418b102ffc4a7113996c26c581a8e78",
)

load("@bazel_bootlin//toolchains:toolchains.bzl", "bootlin_all_toolchain_deps")

bootlin_all_toolchain_deps()

.bazelrc
build --incompatible_enable_cc_toolchain_resolution

invoked with:
bazel build //... --platforms=@bazel_bootlin//platforms:x86-64-linux-gnu-2022.08-1
and
bazel build //... --platforms=@bazel_bootlin//platforms:aarch64-linux-gnu-2021.11-1

Is there anything I missed?
Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.