Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add release flag #6

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from pants.util.logging import LogLevel

from pants_cargo_porcelain.internal.build import CargoBinary, CargoBinaryRequest
from pants_cargo_porcelain.subsystems import RustSubsystem
from pants_cargo_porcelain.target_types import CargoBinaryNameField, CargoPackageSourcesField


Expand All @@ -33,16 +34,25 @@ class CargoBinaryFieldSet(PackageFieldSet, RunFieldSet):


@rule(desc="Package Cargo binary", level=LogLevel.DEBUG)
async def package_cargo_binary(field_set: CargoBinaryFieldSet) -> BuiltPackage:
async def package_cargo_binary(
field_set: CargoBinaryFieldSet,
rust: RustSubsystem,
) -> BuiltPackage:
output_filename = PurePath(field_set.output_path.value_or_default(file_ending=None))
binary = await Get(
CargoBinary,
CargoBinaryRequest(field_set.address, field_set.sources, field_set.binary_name.value),
)

build_level = "debug"
if rust.release:
build_level = "release"

removed_prefix = await Get(
Digest,
RemovePrefix(binary.digest, f".cargo-target-cache/{field_set.address.spec_path}/debug"),
RemovePrefix(
binary.digest, f".cargo-target-cache/{field_set.address.spec_path}/{build_level}"
),
)

renamed_output_digest = await Get(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ def platform_to_target(platform: Platform):

@rule
async def build_cargo_binary(
req: CargoBinaryRequest, rust: RustSubsystem, rustup: RustupTool, platform: Platform
req: CargoBinaryRequest,
rust: RustSubsystem,
rustup: RustupTool,
platform: Platform,
) -> CargoBinary:
source_files, toolchain = await MultiGet(
Get(
Expand All @@ -58,18 +61,27 @@ async def build_cargo_binary(
),
)

extra_args = []
if rust.release:
extra_args.append("--release")

build_level = "debug"
if rust.release:
build_level = "release"

process_result = await Get(
ProcessResult,
CargoProcessRequest(
toolchain,
(
"build",
*extra_args,
f"--manifest-path={req.address.spec_path}/Cargo.toml",
"--locked",
f"--bin={req.binary_name}",
),
source_files.snapshot.digest,
output_files=(f"{{cache_path}}/debug/{req.binary_name}",),
output_files=(f"{{cache_path}}/{build_level}/{req.binary_name}",),
cache_path=req.address.spec_path,
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ class RustSubsystem(Subsystem):
advanced=True,
)

release = BoolOption(
default=False,
help=softwrap("""If true, build in release mode."""),
advanced=True,
)

skip = SkipOption("fmt", "lint")


Expand Down