diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-11-08 00:02:00 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-11-08 00:02:00 +0000 |
commit | 6d828bc80bb0c4d70b17781a1e634894dc57cb86 (patch) | |
tree | f1a6b282cd125a0975c96bae83ce6f65018cd994 | |
parent | 8afed913f03331a79c47a48e692462accd616abe (diff) | |
parent | 070f48f6532d5cd764e3280b0c5f6dadc612edb0 (diff) | |
download | libbootloader-6d828bc80bb0c4d70b17781a1e634894dc57cb86.tar.gz |
Snap for 11065517 from 070f48f6532d5cd764e3280b0c5f6dadc612edb0 to 24Q1-release
Change-Id: I8c3a042dafe528274316a64880b2394faaff456a
-rw-r--r-- | gbl/README.md | 39 | ||||
-rw-r--r-- | gbl/WORKSPACE.bazel | 4 | ||||
-rw-r--r-- | gbl/tools/build/build_gbl.py | 149 | ||||
-rw-r--r-- | gbl/workspace.bzl | 186 |
4 files changed, 11 insertions, 367 deletions
diff --git a/gbl/README.md b/gbl/README.md index b5fc6ec..49f1d23 100644 --- a/gbl/README.md +++ b/gbl/README.md @@ -6,48 +6,31 @@ can be loaded directly from the firmware. ## Build -The library and the EFI application can be built using the -[build_gbl.py](tools/build/build_gbl.py) script. There are two ways of invoking -it: - -### Build from AOSP - -If this repo is checked out from a full -[AOSP](https://source.android.com/docs/setup/download/downloading) or +The GBL project are intended to be built from the [Android Bootloader](https://source.android.com/docs/setup/create/cuttlefish-bootloader-dev#develop-bootloader) -super project, you can simply run - -```.sh -python3 build_gbl.py <output directory> -``` +super project checkout. -The script will auto select the needed dependencies from the super project. -After build completes, the EFI image will be available in -`<output director>/gbl/`. By default, the script builds for all of `x86_64`, -`x86_32`, `aarch64` and `riscv64` architectures. If you only want to build for -a subset, append option `--arch <x86_64|x86_32|aarch64|riscv64>` one by one. +To build the EFI application: -### Build without AOSP +``` +./tools/bazel run //u-boot:gbl_efi_dist --extra_toolchains=@gbl//toolchain:all +``` +The above builds the EFI application for all of `x86_64`, `x86_32`, `aarch64` +and `riscv64` platforms. -If a full super project checkout is too heavy-weight, use the following options, -which only requires a Bazel binary. +To run the set of unit tests: ``` -python3 build_gbl.py \ - --bazel=<path to Bazel executable> \ - <output directory> +./tools/bazel test @gbl//tests --extra_toolchains=@gbl//toolchain:all ``` -The above command will automatically download necessary toolchains from -Android prebuilts. - ## Run on emulator ### Run on Cuttlefish If you have a main AOSP checkout and is setup to run [Cuttlefish](https://source.android.com/docs/setup/create/cuttlefish), you can -run the EFI image directly with it: +run the EFI image directly with: ``` launch_cvd --android_efi_loader=<path to the EFI image> ... diff --git a/gbl/WORKSPACE.bazel b/gbl/WORKSPACE.bazel index 4fe1ea6..b151725 100644 --- a/gbl/WORKSPACE.bazel +++ b/gbl/WORKSPACE.bazel @@ -13,7 +13,3 @@ # limitations under the License. workspace(name = "gbl") - -load("@gbl//:workspace.bzl", "define_gbl_workspace") - -define_gbl_workspace() diff --git a/gbl/tools/build/build_gbl.py b/gbl/tools/build/build_gbl.py deleted file mode 100644 index ea6c28e..0000000 --- a/gbl/tools/build/build_gbl.py +++ /dev/null @@ -1,149 +0,0 @@ -#!/usr/bin/env python3 -# -# Copyright (C) 2023 The Android Open Source Project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# See gbl/README.md for usage. - -import argparse -import os -import pathlib -import shutil -import sys -import subprocess - -# GBL bazel root. -GBL_DIR = pathlib.Path(__file__).resolve().parents[2] - -# Super project root directory. -# Assumes that the project is checkout as "bootable/libbootloader/gbl" -SUPER_PROJECT_ROOT = pathlib.Path(__file__).resolve().parents[5] - -ARCHS = ["x86_64", "x86_32", "aarch64", "riscv64"] - -# Version used by Trusty and u-boot -DEFAULT_CLANG_VERSION = "clang-r475365b" -DEFAULT_LINUX_SYS_ROOT_VERSION = "x86_64-linux-glibc2.17-4.8" - - -def parse_args(): - parser = argparse.ArgumentParser() - parser.add_argument("--aosp_root", help="Path to Android root source") - parser.add_argument("--bazel", help="Override path to bazel executable") - parser.add_argument("--test", action="store_true", help="Run unittests") - parser.add_argument( - "--arch", - help="Add a specific target architecture to build list", - action='append', - choices=ARCHS) - parser.add_argument("out", help="Output directory") - - return parser.parse_args() - - -AOSP_GET_CLANG_VERSION_SCRIPT = pathlib.Path( - "build") / "soong" / "scripts" / "get_clang_version.py" - - -def aosp_get_clang() -> str: - try: - return subprocess.run([AOSP_GET_CLANG_VERSION_SCRIPT], - check=True, - text=True, - capture_output=True, - cwd=str(SUPER_PROJECT_ROOT)).stdout.strip('\n') - except: - return None - - -def get_clang_version() -> str: - from_env = os.environ.get("GBL_CLANG_VERSION", None) - if from_env: - return f"clang-{from_env}" - - if aosp_get_clang(): - return aosp_get_clang() - - return DEFAULT_CLANG_VERSION - - -def run_bazel(bazel, out, args): - """Wrapper for running bazel command""" - command = [bazel, f"--output_user_root={out}"] + args - subprocess.run(command, cwd=str(GBL_DIR), check=True) - - -def main() -> int: - args = parse_args() - if args.bazel: - # Standalone build - bazel = pathlib.Path(args.bazel).resolve() - else: - # Assume the project lives in a super project. - print(f"Looking for super project at: {SUPER_PROJECT_ROOT}") - - llvm = str(SUPER_PROJECT_ROOT / "prebuilts" / "clang" / "host" / - "linux-x86" / get_clang_version()) - sysroot = str(SUPER_PROJECT_ROOT / "prebuilts" / "gcc" / "linux-x86" / - "host" / DEFAULT_LINUX_SYS_ROOT_VERSION) - bazel = (SUPER_PROJECT_ROOT / "prebuilts" / "bazel" / "linux-x86_64" / - "bazel") - - if not os.path.isdir(str(llvm)): - raise EnvironmentError(f"LLVM not found at {llvm}") - - if not os.path.isdir(str(sysroot)): - raise EnvironmentError(f"Linux sysroot not found at {sysroot}") - - if not bazel.exists(): - raise EnvironmentError(f"Bazel binary not found {bazel}") - - os.environ["GBL_LLVM_PREBUILTS"] = str(llvm) - os.environ["GBL_LINUX_SYSROOT"] = str(sysroot) - print(f'LLVM: {os.environ["GBL_LLVM_PREBUILTS"]}') - print(f'Linux Sysroot: {os.environ["GBL_LINUX_SYSROOT"]}') - - archs = args.arch if args.arch else ARCHS - - out_dir = (pathlib.Path(args.out) / "gbl").resolve() - os.makedirs(str(out_dir), exist_ok=True) - - print(f"Output: {out_dir}") - print(f"Target architectures: {archs}") - - if args.test: - run_bazel(bazel, out_dir, - ["test", "@gbl//tests", "--verbose_failures"]) - - out_paths = [] - for arch in archs: - run_bazel(bazel, out_dir, - ["build", f"@gbl//efi:{arch}", "--verbose_failures"]) - out_path = out_dir / f"gbl_{arch}.efi" - # Delete old image first. Otherwise if the image doesn't have write permission, - # copy fails. - out_path.unlink(missing_ok=True) - shutil.copy( - (GBL_DIR / "bazel-bin" / "efi" / f"gbl_{arch}.efi").resolve(), - out_path) - out_paths.append(out_path) - - for path in out_paths: - print(f"Image output at {path}") - - return 0 - - -if __name__ == "__main__": - sys.exit(main()) diff --git a/gbl/workspace.bzl b/gbl/workspace.bzl deleted file mode 100644 index eac8db7..0000000 --- a/gbl/workspace.bzl +++ /dev/null @@ -1,186 +0,0 @@ -# Copyright (C) 2023 The Android Open Source Project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -""" -This file contains rules and logic to initialize GBL workspace. -""" - -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") -load("@gbl//toolchain:gbl_workspace_util.bzl", "gbl_llvm_prebuilts") - -def _android_external_rust_crate_archive(name, rev, build_file): - crate_url = "https://android.googlesource.com/platform/external/rust/crates/" + \ - "{}/+archive/{}.tar.gz".format(name, rev) - - http_archive( - name = name, - url = crate_url, - build_file = build_file, - ) - -def fetch_remote_dependencies(): - """Download external dpendencies needed by GBL""" - - # Bazel rust rules, i.e. `rust_library()`/`rust_binary()` etc. - http_archive( - name = "rules_rust", - url = "https://android.googlesource.com/platform/external/bazelbuild-rules_rust/+archive/78760f889ea04beeb880185cdee6a0ebcc71aeb2.tar.gz", - ) - - # Dependency of `@rules_rust`. - http_archive( - name = "rules_rust_tinyjson", - build_file = "@rules_rust//util/process_wrapper:BUILD.tinyjson.bazel", - url = "https://android.googlesource.com/platform/external/rust/crates/tinyjson/+archive/bd3c80f2d602fe6aab658d32af8380febee844e2.tar.gz", - ) - - # Fetch LLVM prebuilts. We used the same prebuilt branch used by Trusty and u-boot. - http_archive( - name = "llvm_linux_x86_64_prebuilts", - url = "https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86/+archive/18420bf70dde33f6fae92624a1dad774aeae0e83/clang-r475365b.tar.gz", - build_file_content = "", - ) - - # Fetch Linux sysroot which is needed to configure host toolchain. - http_archive( - name = "linux_x86_64_sysroot", - url = "https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.17-4.8/+archive/refs/heads/main.tar.gz", - build_file_content = "", - ) - - # Fetch Android upstream rust prebuilts: - # https://android.googlesource.com/platform/prebuilts/rust - http_archive( - name = "rust_prebuilts", - build_file = "@gbl//toolchain:BUILD.android_rust_prebuilts.bazel", - url = "https://android.googlesource.com/platform/prebuilts/rust/+archive/72697c0b73f7df92389bdad2ba6a8a513f00269a/linux-x86/1.72.0.tar.gz", - ) - - # Fetch `bindgen` from Android upstream prebuilts. It is part of - # https://android.googlesource.com/platform/prebuilts/clang-tools - http_archive( - name = "bindgen", - build_file_content = """exports_files(["bindgen"])""", - url = "https://android.googlesource.com/platform/prebuilts/clang-tools/+archive/820ba880a1e95afd4cb6645356f724b7898d387c/linux-x86/bin.tar.gz", - ) - - # Fetch `elfutils` repo which contains ELF definitions needed for the `libelf` library. - http_archive( - name = "elfutils", - build_file_content = """ -cc_library( - name = "elf_type_header", - hdrs = ["libelf/elf.h"], - visibility = ["//visibility:public"], -) -""", - url = "https://android.googlesource.com/platform/external/elfutils/+archive/refs/heads/main.tar.gz", - ) - - # Fetch `googletest` for C/C++ unit-tests - http_archive( - name = "googletest", - url = "https://android.googlesource.com/platform/external/googletest/+archive/refs/heads/main.tar.gz", - ) - - # Following are third party rust crates from android/external/rust/crates used by GBL. - # - # Note: To pull in a new crate, Add a new _android_external_rust_crate_archive() rule below to - # fetch the crate and provide a BUILD file for it. Android.bp is a good reference for writing - # BUILD file as for most part it has an one-to-one mapping to a Bazel rule. If the target - # crate has additional dependencies, repeat for all of them until all needed crates are - # fetched. - - _android_external_rust_crate_archive( - name = "bitflags", - rev = "4cb5dac10a9ca8a0c9b78ea24f0f23e7972576e2", - build_file = "@gbl//android_external_rust_crates:BUILD.bitflags.bazel", - ) - - _android_external_rust_crate_archive( - name = "byteorder", - rev = "69440f2e49ba4d846f091a57c1826a268d04656e", - build_file = "@gbl//android_external_rust_crates:BUILD.byteorder.bazel", - ) - - _android_external_rust_crate_archive( - name = "cfg-if", - rev = "3a308fd77901411c7ed5161012cebeb2cf8dab1a", - build_file = "@gbl//android_external_rust_crates:BUILD.cfg-if.bazel", - ) - - _android_external_rust_crate_archive( - name = "crc32fast", - rev = "7225fa79b53d6a75f4dadcd974ca82c666044953", - build_file = "@gbl//android_external_rust_crates:BUILD.crc32fast.bazel", - ) - - _android_external_rust_crate_archive( - name = "hex", - rev = "1ddb3bec93394eeb62ee4f4187e8579b489c3d07", - build_file = "@gbl//android_external_rust_crates:BUILD.hex.bazel", - ) - - _android_external_rust_crate_archive( - name = "proc-macro2", - rev = "5c471c4a5c3e80c810dadb19c5996e420426c3bc", - build_file = "@gbl//android_external_rust_crates:BUILD.proc-macro2.bazel", - ) - - _android_external_rust_crate_archive( - name = "quote", - rev = "9791b3d2d985ed9aae113fc5112e9a607c6c5741", - build_file = "@gbl//android_external_rust_crates:BUILD.quote.bazel", - ) - - _android_external_rust_crate_archive( - name = "syn", - rev = "035a68a559d23e0f60aa2c274a4b4c6f7247bc3b", - build_file = "@gbl//android_external_rust_crates:BUILD.syn.bazel", - ) - - _android_external_rust_crate_archive( - name = "unicode-ident", - rev = "2d1f5f891da7f9645c864e54fa08a0aabc7ab65f", - build_file = "@gbl//android_external_rust_crates:BUILD.unicode-ident.bazel", - ) - - _android_external_rust_crate_archive( - name = "zerocopy", - rev = "38d9439810f66c9f287a7f1caee1f6e3cf076d38", - build_file = "@gbl//android_external_rust_crates:BUILD.zerocopy.bazel", - ) - - _android_external_rust_crate_archive( - name = "zerocopy-derive", - rev = "e987328e0df1334022cb8ada4233e672a2e4ea0e", - build_file = "@gbl//android_external_rust_crates:BUILD.zerocopy-derive.bazel", - ) - -def define_gbl_workspace(name = None): - """Set up worksapce for building GBL targets - - This rule API can be used to integrate GBL build targets into other projects that use Bazel - build system. To do so, simply call this API in the project's WORKSPACE.bazel file. - - Args: - name (String): Placeholder for buildifier check. - """ - fetch_remote_dependencies() - - # Set up a repo to export llvm tool/library/header/sysroot paths - gbl_llvm_prebuilts(name = "gbl_llvm_prebuilts") - - # Register all the LLVM/Rust toolchains. - native.register_toolchains("@gbl//toolchain:all") |