mirror of
https://github.com/openai/codex.git
synced 2026-11-22 23:00:42 +00:00
feat: support local development using Buck2
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
load("@prelude//rust:rust_toolchain.bzl", "PanicRuntime", "RustToolchainInfo")
|
||||
|
||||
_DEFAULT_TRIPLE = select({
|
||||
"prelude//os:linux": select({
|
||||
"prelude//cpu:arm64": "aarch64-unknown-linux-gnu",
|
||||
"prelude//cpu:riscv64": "riscv64gc-unknown-linux-gnu",
|
||||
"prelude//cpu:x86_64": "x86_64-unknown-linux-gnu",
|
||||
}),
|
||||
"prelude//os:macos": select({
|
||||
"prelude//cpu:arm64": "aarch64-apple-darwin",
|
||||
"prelude//cpu:x86_64": "x86_64-apple-darwin",
|
||||
}),
|
||||
"prelude//os:windows": select({
|
||||
"prelude//cpu:arm64": select({
|
||||
# Rustup's default ABI for the host on Windows is MSVC, not GNU.
|
||||
"DEFAULT": "aarch64-pc-windows-msvc",
|
||||
"prelude//abi:gnu": "aarch64-pc-windows-gnu",
|
||||
"prelude//abi:msvc": "aarch64-pc-windows-msvc",
|
||||
}),
|
||||
"prelude//cpu:x86_64": select({
|
||||
"DEFAULT": "x86_64-pc-windows-msvc",
|
||||
"prelude//abi:gnu": "x86_64-pc-windows-gnu",
|
||||
"prelude//abi:msvc": "x86_64-pc-windows-msvc",
|
||||
}),
|
||||
}),
|
||||
})
|
||||
|
||||
|
||||
def _codex_rust_toolchain_impl(ctx):
|
||||
# Buck doesn't have a built-in notion of "Cargo profiles", but it's useful
|
||||
# to provide a simple local knob that roughly matches `cargo build` vs
|
||||
# `cargo build --release`.
|
||||
#
|
||||
# Default is "dev" to match local development expectations.
|
||||
rust_profile = read_config("codex", "rust_profile", "dev")
|
||||
extra_rustc_flags = []
|
||||
if rust_profile == "release":
|
||||
# Roughly mirrors Cargo's release defaults (not a perfect match).
|
||||
extra_rustc_flags = [
|
||||
"-C",
|
||||
"opt-level=3",
|
||||
"-C",
|
||||
"debuginfo=0",
|
||||
]
|
||||
|
||||
return [
|
||||
DefaultInfo(),
|
||||
RustToolchainInfo(
|
||||
allow_lints = ctx.attrs.allow_lints,
|
||||
clippy_driver = RunInfo(args = [ctx.attrs.clippy_driver]),
|
||||
clippy_toml = ctx.attrs.clippy_toml[DefaultInfo].default_outputs[0] if ctx.attrs.clippy_toml else None,
|
||||
compiler = RunInfo(args = [ctx.attrs.rustc]),
|
||||
default_edition = ctx.attrs.default_edition,
|
||||
deny_lints = ctx.attrs.deny_lints,
|
||||
doctests = ctx.attrs.doctests,
|
||||
nightly_features = ctx.attrs.nightly_features,
|
||||
panic_runtime = PanicRuntime("unwind"),
|
||||
report_unused_deps = ctx.attrs.report_unused_deps,
|
||||
rustc_binary_flags = ctx.attrs.rustc_binary_flags,
|
||||
rustc_flags = ctx.attrs.rustc_flags + extra_rustc_flags,
|
||||
rustc_target_triple = ctx.attrs.rustc_target_triple,
|
||||
rustc_test_flags = ctx.attrs.rustc_test_flags,
|
||||
rustdoc = RunInfo(args = [ctx.attrs.rustdoc]),
|
||||
rustdoc_flags = ctx.attrs.rustdoc_flags,
|
||||
warn_lints = ctx.attrs.warn_lints,
|
||||
# Enable the prelude's "metadata-only rlib" behavior consistently
|
||||
# across the crate graph. This avoids rustc "found possibly newer
|
||||
# version of crate ..." (E0460) mismatches between binaries and
|
||||
# libraries in large Rust graphs.
|
||||
advanced_unstable_linking = ctx.attrs.advanced_unstable_linking,
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
codex_rust_toolchain = rule(
|
||||
impl = _codex_rust_toolchain_impl,
|
||||
attrs = {
|
||||
"advanced_unstable_linking": attrs.bool(default = True),
|
||||
"allow_lints": attrs.list(attrs.string(), default = []),
|
||||
# Prefer explicit tool paths so the Buck execution directory doesn't
|
||||
# affect rustup toolchain resolution.
|
||||
"clippy_driver": attrs.string(default = "clippy-driver"),
|
||||
"clippy_toml": attrs.option(attrs.dep(providers = [DefaultInfo]), default = None),
|
||||
"default_edition": attrs.option(attrs.string(), default = None),
|
||||
"deny_lints": attrs.list(attrs.string(), default = []),
|
||||
"doctests": attrs.bool(default = False),
|
||||
"nightly_features": attrs.bool(default = False),
|
||||
"report_unused_deps": attrs.bool(default = False),
|
||||
"rustc": attrs.string(default = "rustc"),
|
||||
"rustc_binary_flags": attrs.list(attrs.arg(), default = []),
|
||||
"rustc_flags": attrs.list(attrs.arg(), default = []),
|
||||
"rustc_target_triple": attrs.string(default = _DEFAULT_TRIPLE),
|
||||
"rustc_test_flags": attrs.list(attrs.arg(), default = []),
|
||||
"rustdoc": attrs.string(default = "rustdoc"),
|
||||
"rustdoc_flags": attrs.list(attrs.arg(), default = []),
|
||||
"warn_lints": attrs.list(attrs.string(), default = []),
|
||||
},
|
||||
is_toolchain_rule = True,
|
||||
)
|
||||
Reference in New Issue
Block a user