-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split into multiple examples, one for hybrid Cargo + Buck projects
- Loading branch information
1 parent
cd39aa4
commit ea56b0e
Showing
34 changed files
with
306 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,21 @@ | ||
[repositories] | ||
root = . | ||
prelude = prelude | ||
toolchains = toolchains | ||
none = none | ||
|
||
[repository_aliases] | ||
config = prelude | ||
fbcode = none | ||
fbsource = none | ||
buck = none | ||
|
||
[external_cells] | ||
prelude = bundled | ||
|
||
[parser] | ||
target_platform_detector_spec = target:root//...->prelude//platforms:default | ||
|
||
[rust] | ||
default_edition = 2021 | ||
remap_src_paths = yes |
Empty file.
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 @@ | ||
latest |
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,7 @@ | ||
/buck-out | ||
/target | ||
.cargo | ||
|
||
# You can also preserve config.toml, if you need to change cargo settings. | ||
# !.cargo/config.toml | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,7 @@ | ||
[workspace] | ||
|
||
members = ["project"] | ||
resolver = "2" | ||
|
||
# Local patches - typically git references | ||
[patch.crates-io] |
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,36 @@ | ||
# Hybrid Cargo + Buck project | ||
|
||
This example is for using both Cargo and Buck on the same project. This is | ||
useful if you want to: | ||
|
||
- use Cargo to do things like `cargo fmt`; | ||
- have it work out of the box with `rust-analyzer`, so it's easy to contribute; | ||
- ultimately build your code with Buck; | ||
- or support building with either. | ||
|
||
The key is the `reindeer.toml` in the root, which stitches together a Cargo | ||
workspace and a Buck package (`third-party`) to buckify Cargo dependencies | ||
into. | ||
|
||
## Running the example | ||
|
||
```sh | ||
cargo install --path . | ||
cd examples/hybrid | ||
|
||
# Add a dependency | ||
cargo add -p project serde --features derive | ||
|
||
# Buckify deps. Do this every time you modify the Cargo.tomls, in general. | ||
reindeer buckify | ||
|
||
# Note that both buck and cargo can build this project | ||
buck2 run //project:test | ||
cargo run -p project | ||
``` | ||
|
||
## Missing from this example | ||
|
||
This example does no vendoring or anything fancy with fixups. You will have to | ||
follow the other examples to get a non-trivial Cargo project built with Buck. | ||
|
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,7 @@ | ||
rust_binary( | ||
name = "test", | ||
srcs = ["src/main.rs"], | ||
deps = [ | ||
"//third-party:once_cell", | ||
], | ||
) |
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,14 @@ | ||
[package] | ||
# Pseudo-package whose dependencies are imported and buckified | ||
name = "project" | ||
version = "0.0.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
# List of packages to be imported, with version constraints, features | ||
# and all options Cargo supports. | ||
[dependencies] | ||
once_cell = "1.4" | ||
|
||
# Local patches - typically git references | ||
[patch.crates-io] |
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,16 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
use once_cell::sync::Lazy; | ||
|
||
const MAGIC: &str = "this is a magic string"; | ||
|
||
static SPECIAL: Lazy<String> = Lazy::new(|| MAGIC.to_string()); | ||
|
||
fn main() { | ||
println!("{}", &*SPECIAL); | ||
} |
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,97 @@ | ||
## | ||
## Reindeer Config for a hybrid Cargo + Buck project | ||
## | ||
|
||
# Paths | ||
# | ||
# This is a workspace Cargo.toml. For all default workspace members, it will | ||
# recursively buckify their dependencies to third-party/BUCK. | ||
manifest_path = "Cargo.toml" | ||
third_party_dir = "third-party" | ||
include_top_level = false | ||
fixup_templates = true | ||
|
||
# Platforms (see other examples) | ||
# | ||
[platform.linux-x86_64] | ||
x86_64-unknown-linux-gnu = [] # true for a boolean test | ||
target_arch = ["x86_64"] | ||
target_endian = ["little"] | ||
target_env = ["gnu"] | ||
target_family = ["unix"] | ||
target_feature = ["fxsr", "sse", "sse2"] | ||
target_has_atomic = ["8", "16", "32", "64", "ptr"] | ||
target_os = ["linux"] | ||
target_pointer_width = ["64"] | ||
target_vendor = ["unknown"] | ||
|
||
# Fortanix SGX | ||
[platform.fortanix-sgx] | ||
x86_64-fortanix-unknown-sgx = [] | ||
target_arch = ["x86_64"] | ||
target_endian = ["little"] | ||
target_env = ["sgx"] | ||
target_feature = ["fxsr", "rdrand", "rdseed", "sse", "sse2"] | ||
target_has_atomic = ["8", "16", "32", "64", "ptr"] | ||
target_os = ["unknown"] | ||
target_pointer_width = ["64"] | ||
target_vendor = ["fortanix"] | ||
|
||
# macOS - x86_64-apple-darwin | ||
[platform.macos] | ||
x86_64-apple-darwin = [] | ||
target_arch = ["x86_64"] | ||
target_endian = ["little"] | ||
target_env = [] | ||
target_family = ["unix"] | ||
target_feature = ["cmpxchg16b", "fxsr", "sse", "sse2", "sse3", "ssse3"] | ||
target_has_atomic = ["8", "16", "32", "64", "128", "ptr"] | ||
target_os = ["macos"] | ||
target_pointer_width = ["64"] | ||
target_vendor = ["apple"] | ||
|
||
# Windows with MSVC toolchain - x86_64-pc-windows-msvc | ||
[platform.windows] | ||
x86_64-pc-windows-msvc = [] | ||
target_arch = ["x86_64"] | ||
target_endian = ["little"] | ||
target_env = ["msvc"] | ||
target_family = ["windows"] | ||
target_feature = ["fxsr", "sse", "sse2"] | ||
target_has_atomic = ["8", "16", "32", "64", "ptr"] | ||
target_os = ["windows"] | ||
target_pointer_width = ["64"] | ||
target_vendor = ["pc"] | ||
|
||
# Windows with GNU toolchain - x86_64-pc-windows-gnu | ||
[platform.windows-gnu] | ||
x86_64-pc-windows-gnu = [] | ||
target_arch = ["x86_64"] | ||
target_endian = ["little"] | ||
target_env = ["gnu"] | ||
target_family = ["windows"] | ||
target_feature = ["fxsr", "sse", "sse2"] | ||
target_has_atomic = ["8", "16", "32", "64", "ptr"] | ||
target_os = ["windows"] | ||
target_pointer_width = ["64"] | ||
target_vendor = ["pc"] | ||
|
||
# Configuration for generated BUCK file | ||
# See other examples | ||
[buck] | ||
file_name = "BUCK" | ||
rust_library = "cargo.rust_library" | ||
rust_binary = "cargo.rust_binary" | ||
buildscript_genrule = "buildscript_run" | ||
buckfile_imports = """ | ||
load("@prelude//rust:cargo_buildscript.bzl", "buildscript_run") | ||
load("@prelude//rust:cargo_package.bzl", "cargo") | ||
""" | ||
generated_file_header = """ | ||
## | ||
## \u0040generated by reindeer | ||
## Do not edit by hand. | ||
## | ||
## See README.md for directions on how to update this. | ||
## | ||
""" |
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,31 @@ | ||
# Ignore Cargo-related stuff | ||
.cargo/registry | ||
.cargo/git | ||
/registry | ||
/git | ||
.package-cache | ||
|
||
# Various cruft in vendored packages | ||
vendor/*/target | ||
vendor/*/Cargo.lock | ||
vendor/**/.buckconfig | ||
vendor/**/BUCK | ||
vendor/**/OWNERS | ||
vendor/**/*~ | ||
vendor/**/*.bzl | ||
vendor/*/.github/** | ||
vendor/*/.appveyor.yml | ||
vendor/*/.travis.yml | ||
/target/** | ||
|
||
# Bad Windows names - oh for case-insensitive regex matching! | ||
vendor/**/[Aa][Uu][Xx] | ||
vendor/**/[Aa][Uu][Xx].* | ||
vendor/**/[Cc][Oo][Mm][1-9] | ||
vendor/**/[Cc][Oo][Mm][1-9].* | ||
vendor/**/[Cc][Oo][Nn] | ||
vendor/**/[Cc][Oo][Nn].* | ||
vendor/**/[Ll][Pp][Tt][1-9] | ||
vendor/**/[Ll][Pp][Tt][1-9].* | ||
vendor/**/[Nn][Uu][Ll] | ||
vendor/**/[Nn][Uu][Ll].* |
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,48 @@ | ||
## | ||
## @generated by reindeer | ||
## Do not edit by hand. | ||
## | ||
## See README.md for directions on how to update this. | ||
## | ||
|
||
load("@prelude//rust:cargo_buildscript.bzl", "buildscript_run") | ||
load("@prelude//rust:cargo_package.bzl", "cargo") | ||
|
||
alias( | ||
name = "once_cell", | ||
actual = ":once_cell-1.20.2", | ||
visibility = ["PUBLIC"], | ||
) | ||
|
||
http_archive( | ||
name = "once_cell-1.20.2.crate", | ||
sha256 = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775", | ||
strip_prefix = "once_cell-1.20.2", | ||
urls = ["https://static.crates.io/crates/once_cell/1.20.2/download"], | ||
visibility = [], | ||
) | ||
|
||
cargo.rust_library( | ||
name = "once_cell-1.20.2", | ||
srcs = [":once_cell-1.20.2.crate"], | ||
crate = "once_cell", | ||
crate_root = "once_cell-1.20.2.crate/src/lib.rs", | ||
edition = "2021", | ||
features = [ | ||
"alloc", | ||
"default", | ||
"race", | ||
"std", | ||
], | ||
visibility = [], | ||
) | ||
|
||
cargo.rust_binary( | ||
name = "project-0.0.0-project", | ||
srcs = ["../project/src/main.rs"], | ||
crate = "project", | ||
crate_root = "../project/src/main.rs", | ||
edition = "2021", | ||
visibility = [], | ||
deps = [":once_cell-1.20.2"], | ||
) |
Empty file.
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,2 @@ | ||
load("@prelude//toolchains:demo.bzl", "system_demo_toolchains") | ||
system_demo_toolchains() |
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 @@ | ||
// Dummy source to keep Cargo happy | ||
|
||
fn main() {} |