| # Copyright 2022 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 Yasm.""" |
| |
| from PB.go.chromium.org.luci.common.proto.srcman.manifest import Manifest |
| from PB.recipes.fuchsia.contrib.yasm import InputProperties |
| |
| DEPS = [ |
| "fuchsia/buildbucket_util", |
| "fuchsia/cas_util", |
| "fuchsia/cipd_util", |
| "fuchsia/cmake", |
| "fuchsia/git_checkout", |
| "fuchsia/macos_sdk", |
| "fuchsia/ninja", |
| "fuchsia/platform_util", |
| "fuchsia/windows_sdk", |
| "recipe_engine/buildbucket", |
| "recipe_engine/cipd", |
| "recipe_engine/context", |
| "recipe_engine/file", |
| "recipe_engine/path", |
| "recipe_engine/platform", |
| "recipe_engine/properties", |
| "recipe_engine/step", |
| ] |
| |
| PROPERTIES = InputProperties |
| |
| GIT_URL = "https://fuchsia.googlesource.com/third_party/yasm" |
| |
| CIPD_SERVER_HOST = "chrome-infra-packages.appspot.com" |
| |
| |
| def RunSteps(api, props): |
| host_platform = api.platform_util.host |
| target_platform = ( |
| api.platform_util.platform(props.platform) if props.platform else host_platform |
| ) |
| |
| manifest = Manifest() |
| |
| src_dir = api.path["start_dir"].join("src", "yasm") |
| _, revision = api.git_checkout( |
| GIT_URL, path=src_dir, fallback_ref="refs/heads/upstream/master" |
| ) |
| git_checkout = manifest.directories[relpath(api, src_dir)].git_checkout |
| git_checkout.repo_url = GIT_URL |
| git_checkout.revision = revision |
| |
| with api.step.nest("ensure packages"), api.context(infra_steps=True): |
| cipd_dir = api.path["start_dir"].join("cipd") |
| pkgs = api.cipd.EnsureFile() |
| pkgs.add_package("fuchsia/third_party/clang/${platform}", "integration") |
| if api.platform.is_linux: |
| pkgs.add_package( |
| "fuchsia/third_party/sysroot/linux", |
| "integration", |
| "sysroot", |
| ) |
| ensured = api.cipd.ensure(cipd_dir, pkgs) |
| for subdir, pins in ensured.items(): |
| directory = manifest.directories[relpath(api, cipd_dir.join(subdir))] |
| directory.cipd_server_host = CIPD_SERVER_HOST |
| for pin in pins: |
| directory.cipd_package[pin.package].instance_id = pin.instance_id |
| |
| with api.macos_sdk(), api.windows_sdk(): |
| options = [] |
| if target_platform.is_win: |
| options.extend( |
| [ |
| f"-DCMAKE_ASM_COMPILER={cipd_dir.join('bin', 'clang-cl.exe')}", |
| f"-DCMAKE_C_COMPILER={cipd_dir.join('bin', 'clang-cl.exe')}", |
| f"-DCMAKE_CXX_COMPILER={cipd_dir.join('bin', 'clang-cl.exe')}", |
| f"-DCMAKE_MAKE_PROGRAM={api.ninja.path}", |
| f"-DCMAKE_SYSROOT={api.windows_sdk.sdk_dir}", |
| "-DCMAKE_MT=mt.exe", |
| "-DCMAKE_RC=rc.exe", |
| ] |
| ) |
| else: |
| options.extend( |
| [ |
| f"-DCMAKE_ASM_COMPILER={cipd_dir.join('bin', 'clang')}", |
| f"-DCMAKE_C_COMPILER={cipd_dir.join('bin', 'clang')}", |
| f"-DCMAKE_CXX_COMPILER={cipd_dir.join('bin', 'clang++')}", |
| f"-DCMAKE_MAKE_PROGRAM={api.ninja.path}", |
| ] |
| ) |
| if target_platform.is_linux: |
| options.extend([f"-DCMAKE_SYSROOT={cipd_dir.join('sysroot')}"]) |
| if target_platform.is_mac: |
| options.extend( |
| [f"-DCMAKE_SYSROOT={api.macos_sdk.sysroot}"] |
| + [ |
| f"-DCMAKE_{mode}_LINKER_FLAGS=-nostdlib++ {cipd_dir.join('lib', 'libc++.a')}" |
| for mode in ["SHARED", "MODULE", "EXE"] |
| ] |
| ) |
| |
| build_dir = api.path["start_dir"].join("src", "yasm-build") |
| install_dir = api.path["start_dir"].join("yasm") |
| api.cmake.build_with_ninja( |
| src_dir=src_dir, |
| build_dir=build_dir, |
| build_type="Release", |
| extra_args=[ |
| "-DCMAKE_INSTALL_PREFIX=", |
| "-DBUILD_SHARED_LIBS=OFF", |
| ] |
| + [slashes(api, option) for option in options], |
| install_dir=install_dir, |
| ) |
| |
| api.file.write_proto( |
| "source manifest", install_dir.join("source_manifest.json"), manifest, "JSONPB" |
| ) |
| |
| # Upload the installation to CAS. |
| api.cas_util.upload(install_dir, output_property="isolated") |
| |
| if api.buildbucket.build.builder.bucket == "prod": |
| # Upload the installation to CIPD for production builds. |
| api.cipd_util.upload_package( |
| f"fuchsia/third_party/yasm/{target_platform}", |
| install_dir, |
| search_tag={"git_revision": revision}, |
| ) |
| |
| |
| def relpath(api, path): |
| return str(api.path.relpath(path, api.path["start_dir"])) |
| |
| |
| def slashes(api, path): |
| # CMake only accept '/' as path delimiter. This helper function replaces '\' |
| # with '/' on Windows platform. |
| return path.replace("\\", "/") if api.platform.is_win else path |
| |
| |
| def GenTests(api): |
| for platform in ("linux", "mac", "win"): |
| yield ( |
| api.buildbucket_util.test( |
| platform, bucket="prod", git_repo=GIT_URL, revision="a" * 40 |
| ) |
| + api.platform.name(platform) |
| ) |
| |
| yield ( |
| api.buildbucket_util.test( |
| "cross", bucket="prod", git_repo=GIT_URL, revision="a" * 40 |
| ) |
| + api.platform.name("mac") |
| + api.properties(platform="mac-arm64") |
| ) |