|
| 1 | +## Third-Party Crate Working Process |
1 | 2 |
|
2 | | -"https://static.crates.io/crates/{crate}/{crate}-{version}.crate" |
| 3 | +### Download crate without cargo |
| 4 | + |
| 5 | +The crate URL is `https://static.crates.io/crates/{crate}/{crate}-{version}.crate`, download the crate using `wget` like this: |
| 6 | + |
| 7 | +```bash |
| 8 | +wget https://static.crates.io/crates/cfg-if/cfg-if-1.0.0.crate |
| 9 | +tar -xvf cfg-if-1.0.0.crate |
| 10 | +rm cfg-if-1.0.0.crate |
| 11 | +mv cfg-if-1.0.0 1.0.0 |
| 12 | +pwd |
| 13 | +# buck2-rust-third-party/third-party/rust/crates/cfg-if/1.0.0 |
| 14 | +``` |
| 15 | + |
| 16 | +### Add Buck2 configs |
| 17 | + |
| 18 | +Copy `toolchains` folder and `.buckconfig` file from other crate into working directory: |
| 19 | + |
| 20 | +``` |
| 21 | +cd 1.0.0 |
| 22 | +mkdir toolchains |
| 23 | +cp -r ../../shlex/1.3.0/toolchains . |
| 24 | +cp ../../shlex/1.3.0/.buckconfig . |
| 25 | +``` |
| 26 | + |
| 27 | +### Add crate to project as dependency |
| 28 | + |
| 29 | +Add `//third-party/rust/crates/cfg-if/1.0.0:cfg-if` to `deps` list: |
| 30 | + |
| 31 | +``` |
| 32 | +load("@prelude//rust:cargo_package.bzl", "cargo") |
| 33 | +
|
| 34 | +cargo.rust_binary( |
| 35 | + name = "buck2-rust-third-party", |
| 36 | + edition = "2021", |
| 37 | + srcs = glob(["src/**/*.rs"]), |
| 38 | + crate_root = "src/main.rs", |
| 39 | + deps = [ |
| 40 | + "//third-party/rust/crates/libc/0.2.169:libc", |
| 41 | + "//third-party/rust/crates/shlex/1.3.0:shlex", |
| 42 | + "//third-party/rust/crates/zstd-sys/2.0.13+zstd.1.5.6:zstd-sys", |
| 43 | + "//third-party/rust/crates/cfg-if/1.0.0:cfg-if", |
| 44 | + ], |
| 45 | + visibility = ["PUBLIC"], |
| 46 | +) |
| 47 | +``` |
| 48 | + |
| 49 | +### Write BUCK for the crate |
| 50 | + |
| 51 | +``` |
| 52 | +load("@prelude//rust:cargo_package.bzl", "cargo") |
| 53 | +
|
| 54 | +cargo.rust_library( |
| 55 | + name = "cfg-if", |
| 56 | + srcs = glob(["**/*.rs"]), |
| 57 | + edition = "2018", |
| 58 | + visibility = ["PUBLIC"], |
| 59 | + deps = [], |
| 60 | +) |
| 61 | +``` |
| 62 | + |
| 63 | +### Clean the crate folder |
| 64 | + |
| 65 | +``` |
| 66 | +cd .. |
| 67 | +rm -rf 1.0.0 |
| 68 | +``` |
| 69 | + |
| 70 | +### Clean the crate folder |
| 71 | + |
| 72 | +``` |
| 73 | +cd .. |
| 74 | +rm -rf .github |
| 75 | +rm -rf .devcontainer |
| 76 | +``` |
| 77 | + |
| 78 | +### Tips |
| 79 | + |
| 80 | +For now, I am trying to generate `BUCK` with `Cargo.toml` with Claude, and the promote words in Chinese: |
| 81 | + |
| 82 | +``` |
| 83 | +
|
| 84 | +``` |
0 commit comments