-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
3498: feat(ci): enable release and debug builds r=adamhjk a=adamhjk This PR enables release and debug builds for buck2. By default, we will always do debug builds (or, more accurately, whatever the rustc compiler thinks the defaults should be). If you want to build for release or debug explicitly, you can do that with: ``` $ buck2 build `@//mode/release` //bin/sdf:sdf ``` And the result will be compiled with release optimizations. You can also use ``@//mode/debug`` if you want. Those files are just ways of DRY-ing up the configuration options - you could also pass them directly on the command line. We can add as many configuration options as we want, and as many toolchain configurations as we want, by extending the options in the `//config` tree, adding a new toolchain statement, and extending the select statement for the `:rust` alias. <img src="https://media1.giphy.com/media/MFg6kb46z2tNOEIBox/giphy.gif"/> Co-authored-by: Adam Jacob <[email protected]>
- Loading branch information
Showing
9 changed files
with
208 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
constraint_setting(name = "rust_build_mode", visibility = ["PUBLIC"]) | ||
constraint_value(name = "build_debug", constraint_setting = ":rust_build_mode", visibility = ["PUBLIC"]) | ||
constraint_value(name = "build_release", constraint_setting = ":rust_build_mode", visibility = ["PUBLIC"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--config=rustc.mode=build_debug |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--config=rustc.mode=build_release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# The custom platform for SI. This is taken from the prelude, but includes our customizations for | ||
# rust build flags. | ||
# | ||
# Essentially, we should be adding any custom configuration into root//config, and then plumbing it | ||
# through the execution_platform defined below. | ||
# | ||
# To actually add new configuration, you'll extend the relevant python function to output the | ||
# correct configuration info, and then you can use it in a select() statement at will. | ||
|
||
load(":defs.bzl", "execution_platform", "host_configuration") | ||
|
||
prelude = native | ||
|
||
_rust_build_mode = read_root_config("rustc", "mode", "build_debug") | ||
_rust_build_mode_constraint = "root//config:" + _rust_build_mode | ||
|
||
execution_platform( | ||
name = "default", | ||
cpu_configuration = host_configuration.cpu, | ||
os_configuration = host_configuration.os, | ||
rust_build_mode = _rust_build_mode_constraint, | ||
use_windows_path_separators = host_info().os.is_windows, | ||
) | ||
|
||
prelude.constraint_setting( | ||
name = "runs_remote", | ||
) | ||
|
||
prelude.constraint_value( | ||
name = "may_run_remote", | ||
constraint_setting = ":runs_remote", | ||
visibility = ["PUBLIC"], | ||
) | ||
|
||
prelude.constraint_setting( | ||
name = "runs_local", | ||
visibility = ["PUBLIC"], | ||
) | ||
|
||
prelude.constraint_value( | ||
name = "may_run_local", | ||
constraint_setting = ":runs_local", | ||
visibility = ["PUBLIC"], | ||
) | ||
|
||
prelude.constraint_setting( | ||
name = "runs_only", | ||
) | ||
|
||
prelude.constraint_value( | ||
name = "runs_only_local", | ||
constraint_setting = ":runs_only", | ||
visibility = ["PUBLIC"], | ||
) | ||
|
||
prelude.constraint_value( | ||
name = "runs_only_remote", | ||
constraint_setting = ":runs_only", | ||
visibility = ["PUBLIC"], | ||
) | ||
|
||
prelude.constraint_setting( | ||
name = "fat_platform_marker", | ||
) | ||
|
||
prelude.constraint_value( | ||
name = "fat_platform_enabled", | ||
constraint_setting = ":fat_platform_marker", | ||
visibility = ["PUBLIC"], | ||
) | ||
|
||
# This is mostly here for a rule type to add a dependency on it to mark all | ||
# instances of that rule type as incompatible with a fat platform. Ideally, | ||
# toolchains could affect the target compatibility of their users directly but | ||
# toolchains are currently all exec deps and so cannot do that. We'd like | ||
# buck2 to support a form of dep that inherited its users execution platform | ||
# so that toolchains could basically get visibility and affect both target and | ||
# execution configuration, but that's not implemented yet. | ||
export_file( | ||
name = "fat_platform_incompatible", | ||
# @oss-disable: src = "TARGETS.v2", | ||
src = "BUCK", # @oss-enable | ||
target_compatible_with = select({ | ||
":fat_platform_enabled": ["config//:none"], | ||
"DEFAULT": [], | ||
}), | ||
visibility = ["PUBLIC"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# | ||
# This source code is licensed under both the MIT license found in the | ||
# LICENSE-MIT file in the root directory of this source tree and the Apache | ||
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory | ||
# of this source tree. | ||
|
||
def _execution_platform_impl(ctx: AnalysisContext) -> list[Provider]: | ||
constraints = dict() | ||
constraints.update(ctx.attrs.cpu_configuration[ConfigurationInfo].constraints) | ||
constraints.update(ctx.attrs.os_configuration[ConfigurationInfo].constraints) | ||
constraints.update(ctx.attrs.rust_build_mode[ConfigurationInfo].constraints) | ||
cfg = ConfigurationInfo(constraints = constraints, values = {}) | ||
|
||
name = ctx.label.raw_target() | ||
platform = ExecutionPlatformInfo( | ||
label = name, | ||
configuration = cfg, | ||
executor_config = CommandExecutorConfig( | ||
local_enabled = True, | ||
remote_enabled = False, | ||
use_windows_path_separators = ctx.attrs.use_windows_path_separators, | ||
), | ||
) | ||
|
||
return [ | ||
DefaultInfo(), | ||
platform, | ||
PlatformInfo(label = str(name), configuration = cfg), | ||
ExecutionPlatformRegistrationInfo(platforms = [platform]), | ||
] | ||
|
||
execution_platform = rule( | ||
impl = _execution_platform_impl, | ||
attrs = { | ||
"cpu_configuration": attrs.dep(providers = [ConfigurationInfo]), | ||
"os_configuration": attrs.dep(providers = [ConfigurationInfo]), | ||
"rust_build_mode": attrs.dep(providers = [ConfigurationInfo]), | ||
"use_windows_path_separators": attrs.bool(), | ||
}, | ||
) | ||
|
||
def _host_cpu_configuration() -> str: | ||
arch = host_info().arch | ||
if arch.is_aarch64: | ||
return "prelude//cpu:arm64" | ||
elif arch.is_arm: | ||
return "prelude//cpu:arm32" | ||
elif arch.is_i386: | ||
return "prelude//cpu:x86_32" | ||
else: | ||
return "prelude//cpu:x86_64" | ||
|
||
def _host_os_configuration() -> str: | ||
os = host_info().os | ||
if os.is_macos: | ||
return "prelude//os:macos" | ||
elif os.is_windows: | ||
return "prelude//os:windows" | ||
else: | ||
return "prelude//os:linux" | ||
|
||
host_configuration = struct( | ||
cpu = _host_cpu_configuration(), | ||
os = _host_os_configuration(), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
def _toolchain_alias_impl(ctx: AnalysisContext) -> list[Provider]: | ||
return ctx.attrs.actual.providers | ||
|
||
toolchain_alias = rule( | ||
doc=""" | ||
toolchain_alias acts like alias but for toolchain rules. | ||
The toolchain_alias itself is a toolchain rule and the `actual` argument is | ||
expected to be a toolchain_rule as well. | ||
""", | ||
attrs={ | ||
"actual": attrs.toolchain_dep( | ||
doc="The actual toolchain that is being aliased. This should be a toolchain rule." | ||
) | ||
}, | ||
impl=_toolchain_alias_impl, | ||
is_toolchain_rule=True, | ||
) |