blob: 974cf81817bdc0ae6cc29f988871bdac679775f4 [file] [log] [blame]
# Copyright 2021 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Recipe for building and uploading bindgen to CIPD."""
from recipe_engine.recipe_api import Property
DEPS = [
"fuchsia/git",
"fuchsia/macos_sdk",
"fuchsia/status_check",
"fuchsia/upload",
"recipe_engine/cipd",
"recipe_engine/context",
"recipe_engine/file",
"recipe_engine/path",
"recipe_engine/platform",
"recipe_engine/properties",
"recipe_engine/step",
]
PROPERTIES = {
"dry_run": Property(
kind=bool, help="Whether this is being executed for a dry run or a real build."
),
}
BINDGEN_REPO_URL = (
"https://fuchsia.googlesource.com/third_party/github.com/rust-lang/rust-bindgen"
)
CLANG_PKG = ("fuchsia/third_party/clang/${platform}", "integration")
# TODO(fxbug.dev/73442) use `integration` instead of `latest` for the rust package
RUST_PKG = ("fuchsia/third_party/rust/${platform}", "latest")
def RunSteps(api, dry_run):
cipd_dir = api.path["start_dir"].join("cipd")
src_dir = api.path["start_dir"].join("bindgen")
with api.context(infra_steps=True):
pkgs = api.cipd.EnsureFile()
for pkg in [CLANG_PKG, RUST_PKG]:
pkgs.add_package(*pkg)
api.cipd.ensure(cipd_dir, pkgs)
with api.step.nest("checkout"):
revision = api.git.checkout_from_build_input(
repo=BINDGEN_REPO_URL, path=src_dir,
)
install_dir = api.path["start_dir"].join("install")
with api.step.nest("build"), api.macos_sdk(), api.context(
cwd=src_dir, env_prefixes={"PATH": [cipd_dir.join("bin")]}
):
api.step("cargo build", ["cargo", "build", "--release"])
api.file.ensure_directory("ensure the install directory exists", install_dir)
api.file.move(
"move binary to install directory",
src_dir.join("target/release/bindgen"),
install_dir.join("bindgen"),
)
if dry_run:
api.upload.upload_isolated(install_dir)
else:
api.upload.cipd_package(
"fuchsia/third_party/rust_bindgen/${platform}",
install_dir,
[api.upload.DirectoryPath(install_dir)],
{"git_revision": revision},
)
def GenTests(api):
yield api.status_check.test("ci") + api.platform.name("linux") + api.properties(
dry_run=True
)
yield api.status_check.test("prod") + api.platform.name("mac") + api.properties(
dry_run=False
)