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

EXPERIMENT: build jujutsu with buck2 #1997

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from
Draft
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
115 changes: 115 additions & 0 deletions .buckconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
[cells]
# 'cells' that are defined in the project. all 'jj' code should remain under
# 'root', while 'prelude' is the prelude, and third-party is where any vendored
# code should go.
root = .
mode = buck/mode
prelude = buck/prelude
toolchains = buck/toolchains
third-party = buck/third-party
none = none

[external_cells]
# use the built-in prelude that is packaged inside of the buck2 executable. at
# any time we could vendor it, or use a 'git' cell, if we needed to apply custom
# patches
prelude = bundled

[cell_aliases]
# these aliases are all required by the upstream buck2 prelude, with stubs for
# meta-specific cells. 'config//' is occasionally useful for select() calls
config = prelude
buck = none
fbcode = none
fbsource = none

[buildfile]
name = BUILD
# for the sake of future compatibility and migrations, we don't want any BUILD
# files in the project to use raw, un-imported symbols from the prelude like
# 'cxx_library()'; we instead want to make sure every rule is explicitly
# wrapped, load()ed and called, i.e. they should use 'jj.cxx_library()' instead.
# do this by loading noprelude.bzl into every BUILD file, which will stub out
# these bad symbols with an error message.
includes = root//buck/shims/noprelude.bzl

[buck2]
# use sha256 since everything supports it. XXX FIXME (aseipp): blake3?
digest_algorithms = SHA256

# enable deferred materialization. this means that intermediate outputs will
# never get written to disk, and instead will be stored in the remote cache for
# all intermediate execution steps.
#
# we don' use RE yet, but keep these enabled so we don' have to change things or
# find problems later. this also enables (local disk) sqlite materialization
# state, and defers writes to the end of actions to help improve performance.
materializations = deferred
sqlite_materializer_state = true
defer_write_actions = true

# hash all commands in the action graph; this helps avoid some spurious
# recompilations when the action graph changes, but the actual commands don't.
# NOTE: this requires `materializations = deferred`
hash_all_commands = true

# deferred materialization requires that cache outputs never expire. if they do,
# a command might fail if it expects a hit on an object that was supposed to be
# an input. in that case, the buck2d daemon needs to restart to 'purge' its
# knowledge of that object. this enables that.
restarter = true

# enable checking the peak memory in the interpreter, and also set a byte limit
# for the interpreter. this is useful for catching runaway memory usage in BUILD
# files just in case people start going crazy with them.
check_starlark_peak_memory = true
# default limit is 5MiB = 5 * 1024 * 1024 = 5242880 bytes
default_starlark_peak_memory = 5242880
# also, enforce a max callstack size to prevent ridiculous stack sizes and
# put a limit on how deep/abstract things can get.
starlark_max_callstack_size = 50

[build]
# set the default execution platform for builds on this machine. NOTE: this
# platform definition is where remote execution (optionally) is enabled via
# ExecutionPlatformRegistrationInfo
execution_platforms = root//buck/platforms:default

[parser]
# set the default execution platform for several target patterns. this is
# required; the main documentation for the format is the source code, I think...
target_platform_detector_spec = \
target:root//...->root//buck/platforms:default \
target:third-party//...->root//buck/platforms:default \
target:toolchains//...->root//buck/platforms:default

[project]
# things that should not be scanned by buck2 for file changes. if you notice
# something strange is being scanned, it might be worth adding here.
ignore = \
.jj, \
.git, \
.direnv, \
.watchman-cookie** \
target

[buck2_re_client]
# default address for the cas/actioncache. this should be public for users so
# they can always get build results. this does NOT include the 'engine_address'
# service, which enables actual remote execution. that must be enabled
# explicitly in .buckconfig.local
cas_address = https://builds.example.com
action_cache_address = https://builds.example.com

# 'instance name', which in RBE is the basic unit of isolation for projects; we
# always default this for simplicity
instance_name = jujutsu

# always use TLS for all build products
tls = true

# in .buckconfig.local:
#
# [buck2_re_client]
# engine_address = https://builds.jujutsu.dev
# http_headers = x-build-api-key:$BUILD_API_KEY
Empty file added .buckroot
Empty file.
30 changes: 30 additions & 0 deletions .github/actions/install-dotslash/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Install DotSlash
description: Install DotSlash on the current system
inputs:
version:
description: "version of dotslash"
required: false
default: "0.4.1"
runs:
using: "composite"
steps:
- name: Install DotSlash
shell: bash
run: |
mkdir -p $RUNNER_TEMP/dotslash
echo "$RUNNER_TEMP/dotslash" >> $GITHUB_PATH

if [[ "$RUNNER_OS" == "Windows" ]]; then
C:\\msys64\\usr\\bin\\wget.exe https://github.com/facebook/dotslash/releases/download/v0.4.1/dotslash-windows.v0.4.1.tar.gz
tar xf dotslash-windows.v0.4.1.tar.gz
mv dotslash.exe $RUNNER_TEMP/dotslash
else
if [[ "$RUNNER_OS" == "macOS" ]]; then
wget https://github.com/facebook/dotslash/releases/download/v0.4.1/dotslash-macos.v0.4.1.tar.gz
tar xf dotslash-macos.v0.4.1.tar.gz
elif [[ "$RUNNER_OS" == "Linux" ]]; then
wget https://github.com/facebook/dotslash/releases/download/v0.4.1/dotslash-ubuntu-22.04.x86_64.v0.4.1.tar.gz
tar xf dotslash-ubuntu-22.04.x86_64.v0.4.1.tar.gz
fi
mv dotslash $RUNNER_TEMP/dotslash
fi
55 changes: 55 additions & 0 deletions .github/workflows/build-buck2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: buck2

on:
push:
branches:
- main
pull_request:

permissions: read-all

jobs:
buck2:
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
abi: x86_64-unknown-linux-gnu
- os: windows-latest
abi: x86_64-pc-windows-msvc
- os: macos-latest
abi: aarch64-apple-darwin
# NOTE: macos-13 is the most recent x86_64 macos runner
#- os: macos-13
# abi: x86_64-apple-darwin
runs-on: ${{ matrix.os }}
timeout-minutes: 15 # NOTE (aseipp): keep in-sync with the build.yml timeout limit

name: build with buck2
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
- name: (Linux) Install Mold
if: runner.os == 'Linux'
run: |
sudo apt-get update && sudo apt-get install -y mold
- name: Install DotSlash
uses: ./.github/actions/install-dotslash
- name: Add build tools to $PATH
run: echo "$PWD/tools/bin" >> $GITHUB_PATH
# FIXME (aseipp): use 'buck2' out of `$PATH` after we have dotslash .exe
# shim files for windows. until then just invoke manually
- name: buck2 build //...
run: |
mkdir -p out
dotslash ./tools/bin/buck2 build @mode//debug //...
cp buck-out/v2/log/*.pb.zst out
dotslash ./tools/bin/buck2 build @mode//debug cli --out out/jj.exe
./out/jj.exe version

- name: "Upload artifact"
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808
with:
name: jj-${{ matrix.abi }}
path: out
retention-days: 14
2 changes: 1 addition & 1 deletion .github/workflows/codespell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ jobs:
with:
check_filenames: true
check_hidden: true
skip: ./target,./.jj,*.lock
skip: ./target,./.jj,*.lock,./buck/third-party/rust/BUILD
ignore_words_list: crate,NotIn,Wirth
30 changes: 30 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"files.insertFinalNewline": true,
"files.trimTrailingWhitespace": true,

"files.associations": {
".buckconfig": "ini",
".buckconfig.local": "ini",
"*.bzl": "starlark",
"*.bxl": "starlark",
"BUILD": "starlark",
"PACKAGE": "starlark",
},

"rust-analyzer.workspace.discoverConfig": {
"command": [
"rust-project",
"develop-json",
"--sysroot-mode=rustc",
"{arg}"
],
"progressLabel": "rust-analyzer[buck2]",
"filesToWatch": ["BUILD", "PACKAGE"]
},

"rust-analyzer.check.overrideCommand": [
"rust-project",
"check",
"$saved_file",
]
}
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ documentation = "https://martinvonz.github.io/jj/"
categories = ["version-control", "development-tools"]
keywords = ["VCS", "DVCS", "SCM", "Git", "Mercurial"]

[workspace.lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(buck_build)'] }

[workspace.dependencies]
anyhow = "1.0.89"
assert_cmd = "2.0.8"
Expand Down
2 changes: 2 additions & 0 deletions buck/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
prelude/* linguist-generated=true merge=binary
prelude/**/* linguist-generated=true merge=binary
5 changes: 5 additions & 0 deletions buck/mode/.buckconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[cells]
mode = .

[buildfile]
name = BUILD
18 changes: 18 additions & 0 deletions buck/mode/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

MODES = [ 'debug', 'release' ]

constraint_setting(name = 'build-mode')

[
constraint_value(
name = f'build-mode-{name}',
constraint_setting = ':build-mode'
) for name in MODES
]

[
config_setting(
name = name,
constraint_values = [ f'mode//:build-mode-{name}' ]
) for name in MODES
]
4 changes: 4 additions & 0 deletions buck/mode/PACKAGE
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

package(
visibility = [ 'PUBLIC' ],
)
1 change: 1 addition & 0 deletions buck/mode/debug
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--config=jj.buildmode=debug
1 change: 1 addition & 0 deletions buck/mode/local
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--config=buck2_re_client.default_enabled=false
1 change: 1 addition & 0 deletions buck/mode/release
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--config=jj.buildmode=release
1 change: 1 addition & 0 deletions buck/mode/remote
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--config=buck2_re_client.default_enabled=true
14 changes: 14 additions & 0 deletions buck/platforms/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
load("@prelude//utils/buckconfig.bzl", "read_choice")
load(":defs.bzl", "generate_platforms", "default_platforms")

build_config = read_choice("jj", "buildmode", [
"debug",
"release",
], "debug")

default_constraints = [
# build mode: debug or release
('mode//:{}'.format(build_config))
]

generate_platforms(default_platforms, default_constraints)
Loading
Loading