Skip to content

Commit 2f2b9f3

Browse files
cormacrelffacebook-github-bot
authored andcommitted
Workspace Cargo.toml support + overhaul examples (#54)
Summary: Fixes #51 by - Running cargo commands in current dir & prefixing `vendor` with third-party/... - Adding --manifest-path flag - Adding `manifest_path = "..."` + `third_party_dir = "..."` to reindeer.toml, allowing it to live at your workspace root and just point to where the output should go. - (This always bugged me about reindeer, the only real way to use it was with a wrapper script. No longer.) - Remaining compatible with the old CLI ways, hopefully. - Now that you can run on a workspace toml, filter out workspace members from the BUCK file by default; `include_workspace_members = false` (default false) because you often want to write your own BUCK files for those instead of having them mixed into a huge generated BUCK file. - **Overhauls the example, now it's 3 examples with much more documentation.** Browse the tree at <https://github.com/cormacrelf/reindeer/tree/workspace_cargo_toml/examples> to see how it looks. Altogether you get `reindeer --manifest-path ./Cargo.toml --third-party-dir subdirectory buckify`, and because this is not something I expect people will want to type, the new config parameters get that down to just `reindeer buckify`. The layout is as as below. ```sh ; cat reindeer.toml manifest_path = "Cargo.toml" third_party_dir = "third-party/rust" ... ; reindeer buckify . ├── Cargo.lock ├── Cargo.toml ├── reindeer.toml └── third-party └── rust ├── .cargo/... ├── BUCK └── vendor ``` Includes a cargo fmt, let me know if this is wrong, maybe there is configuration drift between this repo & others at meta. Pull Request resolved: #54 Differential Revision: D72935124 Pulled By: dtolnay fbshipit-source-id: fa4e831c4b91a9657c4d168d6bed7fad2fb1140e
1 parent a4828e9 commit 2f2b9f3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1171
-123
lines changed

.github/workflows/build-and-test.yml

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,39 @@ jobs:
2020
- run: cargo build --locked
2121
- run: cargo test
2222
- uses: dtolnay/install-buck2@latest
23-
- name: Build example project (Ubuntu, macOS)
23+
- name: Build example projects (Ubuntu, macOS)
24+
if: matrix.os == 'ubuntu' || matrix.os == 'macos'
2425
run: |-
25-
cd example
26-
reindeer --third-party-dir third-party buckify
27-
buck2 init --git
26+
pushd examples/01-intro
27+
reindeer buckify
2828
buck2 run "//project:test"
29-
if: matrix.os == 'ubuntu' || matrix.os == 'macos'
30-
- name: Build example project (Windows)
29+
popd
30+
31+
pushd examples/02-hybrid
32+
reindeer buckify
33+
buck2 run "//project:test"
34+
cargo run -p project
35+
popd
36+
37+
pushd examples/03-complex-fixups
38+
reindeer buckify
39+
buck2 run "//project:test"
40+
popd
41+
- name: Build example projects (Windows)
42+
if: matrix.os == 'windows'
3143
run: |-
32-
cd example
33-
& reindeer --third-party-dir third-party buckify
34-
& buck2 init --git
44+
cd examples/01-intro
45+
& reindeer buckify
3546
& buck2 run "//project:test"
36-
if: matrix.os == 'windows'
47+
cd ../..
48+
49+
cd examples/02-hybrid
50+
& reindeer buckify
51+
& buck2 run "//project:test"
52+
& cargo run -p project
53+
cd ../..
54+
55+
cd examples/03-complex-fixups
56+
& reindeer buckify
57+
& buck2 run "//project:test"
58+
cd ../..

docs/MANUAL.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,19 @@ environment matches this.)
3030

3131
## An Example
3232

33-
See the [example directory](../example/README.md) as a starting point. This has:
33+
See the [first example directory](../examples/01-intro/) as a starting point.
34+
This has:
3435

3536
- Your first-party code in "project" (though of course it can be anywhere and
3637
everywhere), and
37-
- A [third-party](../example/third-party) directory which is managed by Reindeer
38-
- A [`setup.sh`](../example/setup.sh) script to get you bootstrapped
38+
- A [third-party](../examples/01-intro/third-party) directory which is managed
39+
by Reindeer
40+
- A [`setup.sh`](../examples/01-intro/setup.sh) script to get you bootstrapped
3941

4042
Running `setup.sh` will build Reindeer (using Cargo) and then use it to vendor
4143
the small number of third-party dependencies defined in
42-
[`third-party/Cargo.toml`](../third-party/Cargo.toml) and generate build rules
43-
for them in `third-party/BUCK`.
44+
[`third-party/Cargo.toml`](../examples/01-intro/third-party/Cargo.toml) and
45+
generate build rules for them in `third-party/BUCK`.
4446

4547
I recommend using this as a starting template for your own project, at least
4648
until you're familiar enough with how everything works to do it yourself.

example/third-party/macros/rust_third_party.bzl

Lines changed: 0 additions & 7 deletions
This file was deleted.

examples/01-intro/.buckconfig

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[cells]
2+
root = .
3+
prelude = prelude
4+
toolchains = toolchains
5+
none = none
6+
7+
[cell_aliases]
8+
config = prelude
9+
ovr_config = prelude
10+
fbcode = none
11+
fbsource = none
12+
fbcode_macros = none
13+
buck = none
14+
15+
# Uses a copy of the prelude bundled with the buck2 binary. You can alternatively delete this
16+
# section and vendor a copy of the prelude to the `prelude` directory of your project.
17+
[external_cells]
18+
prelude = bundled
19+
20+
[parser]
21+
target_platform_detector_spec = target:root//...->prelude//platforms:default
22+
23+
[build]
24+
execution_platforms = prelude//platforms:default
File renamed without changes.

examples/01-intro/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/buck-out
2+
/target

examples/01-intro/BUCK

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# A list of available rules and their signatures can be found here: https://buck2.build/docs/prelude/globals/
2+
3+
genrule(
4+
name = "hello_world",
5+
out = "out.txt",
6+
cmd = "echo BUILT BY BUCK2> $OUT",
7+
)

example/README.md renamed to examples/01-intro/README.md

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,39 @@ generate a BUCK file of build rules for them.
88
This will require a Rust installation (stable, but probably fairly recent), and
99
Buck to actually make use of the generated files.
1010

11-
You can learn more about Buck at [buck.build](https://buck.build). The
12-
[getting started](https://buck.build/setup/getting_started.html) page should
11+
You can learn more about Buck at [buck.build](https://buck2.build). The
12+
[getting started](https://buck2.build/docs/about/getting_started/) page should
1313
help with getting it installed.
1414

1515
## Buck and its Configuration
1616

1717
The `.buckconfig` file both configures Buck and tells it where the top of the
18-
"cell" is (current working tree). This only contains some very minimal Rust
19-
configuration; most notable is overriding the default to Rust 2018.
20-
21-
(`.buck-java11` won't generally be needed.)
18+
"cell" is (current working tree).
2219

2320
## Reindeer configuration
2421

2522
The files and directories Reindeer cares about are under `third-party/`:
2623

27-
- reindeer.toml - Reindeer's configuration. The directory containing this file
24+
- `reindeer.toml` - Reindeer's configuration. The directory containing this file
2825
is also the base for any relative paths mentioned in the file.
29-
- Cargo.toml - You edit this to specify which packages you want to import, along
30-
with other settings like features, patches and so on, using the full syntax
31-
Cargo allows
32-
- Cargo.lock - The resolved dependencies
33-
- BUCK - The generated Buck build rules (once generated)
34-
- .gitignore - This is used to ignore various inconvenient files in vendored
26+
- `Cargo.toml` - You edit this to specify which packages you want to import,
27+
along with other settings like features, patches and so on, using the full
28+
syntax Cargo allows
29+
- `Cargo.lock` - The resolved dependencies
30+
- `BUCK` - The generated Buck build rules (once generated)
31+
- `.gitignore` - This is used to ignore various inconvenient files in vendored
3532
code. Reindeer itself will look at this to edit them out of the vendored
3633
checksum.json files so that Cargo doesn't get upset.
3734

3835
In addition to these files, there are a few significant directories:
3936

40-
- vendor/ - where all the vendored code goes
41-
- fixups/ - fixups tell Reindeer how to handle packages with build scripts and
37+
- `vendor/` - where all the vendored code goes
38+
- `fixups/` - fixups tell Reindeer how to handle packages with build scripts and
4239
other special cases; most packages won't need anything here
43-
- macros/ - Buck macros which map from the rules Reindeer generates to the
40+
- `macros/` - Buck macros which map from the rules Reindeer generates to the
4441
actual build environment. This directory is not hard-coded and could be
4542
anywhere. The macros included here are quite minimal.
46-
- top/ - Cargo needs a dummy package for the Cargo.toml (it doesn't allow a
43+
- `top/` - Cargo needs a dummy package for the Cargo.toml (it doesn't allow a
4744
package which is _all_ dependencies)
4845

4946
## Project

examples/01-intro/project/BUCK

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
rust_binary(
2+
name = "test",
3+
srcs = ["src/main.rs"],
4+
deps = [
5+
"//third-party:once_cell",
6+
],
7+
)

examples/01-intro/project/src/main.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
use once_cell::sync::Lazy;
9+
10+
const MAGIC: &str = "this is a magic string";
11+
12+
static SPECIAL: Lazy<String> = Lazy::new(|| MAGIC.to_string());
13+
14+
fn main() {
15+
println!("static {}", &*SPECIAL);
16+
}

0 commit comments

Comments
 (0)