facebookincubator / reindeer

Reindeer is a tool to transform Rust Cargo dependencies into generated Buck build rules
MIT License
185 stars 30 forks source link

Unresolved dependencies with specs crate #17

Closed photex closed 1 year ago

photex commented 1 year ago

Hello!

I'm giving reindeer a shot and trying it out on the specs crate ended up with some failures to build. The ahash create seemed to have missed the once_cell dependency, and when you look at the cargo manifest https://github.com/tkaitchuck/aHash/blob/master/Cargo.toml it does seem like a weird one!

So after trying some variations to figure out what is actually failing I know at least a couple of things:

Thanks!

zertosh commented 1 year ago

We're using ahash just fine internally. Do you have a commit or something I can check out to see what you're seeing?

photex commented 1 year ago

Sure, here is a minimal example: https://git.sr.ht/~photex/rlt

The only crates dep is ahash 0.7 which fails to find the once_cell dep.

If you add getrandom, or num_cpus you should run into the missing libc issue.

Ultimately I'm just trying to use specs though, I isolated these as the issue. I'll also update reindeer too. I think I built it a couple of days ago but it would be worthwhile stepping through it as well and see if there isn't some easily the matter.

zertosh commented 1 year ago

I checked out your repo at 177ccade8 and it's incomplete. With a minimal reindeer.toml and a few fixups, running reindeer buckify will produce the right BUCK file. Here's what it should look like:

Patch ```diff commit 2e0e73d Author: Andres Suarez Date: Sat Jul 8 00:15:15 2023 -0400 reindeer diff --git a/third_party/BUCK b/third_party/BUCK index ef516e2..51d6eb6 100644 --- a/third_party/BUCK +++ b/third_party/BUCK @@ -1,3 +1,5 @@ +# @generated by `reindeer buckify` + load("@prelude//rust:cargo_buildscript.bzl", "buildscript_run") load("@prelude//rust:cargo_package.bzl", "cargo") @@ -25,5 +27,190 @@ cargo.rust_library( "default", "std", ], + platform = { + "linux-arm64": dict( + deps = [ + ":getrandom-0.2.10", + ":once_cell-1.18.0", + ], + ), + "linux-x86_64": dict( + deps = [ + ":getrandom-0.2.10", + ":once_cell-1.18.0", + ], + ), + "macos-arm64": dict( + deps = [ + ":getrandom-0.2.10", + ":once_cell-1.18.0", + ], + ), + "macos-x86_64": dict( + deps = [ + ":getrandom-0.2.10", + ":once_cell-1.18.0", + ], + ), + "windows-gnu": dict( + deps = [ + ":getrandom-0.2.10", + ":once_cell-1.18.0", + ], + ), + "windows-msvc": dict( + deps = [ + ":getrandom-0.2.10", + ":once_cell-1.18.0", + ], + ), + }, + rustc_flags = ["@$(location :ahash-0.7.6-build-script-run[rustc_flags])"], + visibility = [], +) + +cargo.rust_binary( + name = "ahash-0.7.6-build-script-build", + srcs = [":ahash-0.7.6.crate"], + crate = "build_script_build", + crate_root = "ahash-0.7.6.crate/build.rs", + edition = "2018", + features = [ + "default", + "std", + ], + visibility = [], + deps = [":version_check-0.9.4"], +) + +buildscript_run( + name = "ahash-0.7.6-build-script-run", + package_name = "ahash", + buildscript_rule = ":ahash-0.7.6-build-script-build", + features = [ + "default", + "std", + ], + version = "0.7.6", +) + +http_archive( + name = "cfg-if-1.0.0.crate", + sha256 = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd", + strip_prefix = "cfg-if-1.0.0", + urls = ["https://crates.io/api/v1/crates/cfg-if/1.0.0/download"], + visibility = [], +) + +cargo.rust_library( + name = "cfg-if-1.0.0", + srcs = [":cfg-if-1.0.0.crate"], + crate = "cfg_if", + crate_root = "cfg-if-1.0.0.crate/src/lib.rs", + edition = "2018", + visibility = [], +) + +http_archive( + name = "getrandom-0.2.10.crate", + sha256 = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427", + strip_prefix = "getrandom-0.2.10", + urls = ["https://crates.io/api/v1/crates/getrandom/0.2.10/download"], + visibility = [], +) + +cargo.rust_library( + name = "getrandom-0.2.10", + srcs = [":getrandom-0.2.10.crate"], + crate = "getrandom", + crate_root = "getrandom-0.2.10.crate/src/lib.rs", + edition = "2018", + platform = { + "linux-arm64": dict( + deps = [":libc-0.2.147"], + ), + "linux-x86_64": dict( + deps = [":libc-0.2.147"], + ), + "macos-arm64": dict( + deps = [":libc-0.2.147"], + ), + "macos-x86_64": dict( + deps = [":libc-0.2.147"], + ), + }, + visibility = [], + deps = [":cfg-if-1.0.0"], +) + +http_archive( + name = "libc-0.2.147.crate", + sha256 = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3", + strip_prefix = "libc-0.2.147", + urls = ["https://crates.io/api/v1/crates/libc/0.2.147/download"], + visibility = [], +) + +cargo.rust_library( + name = "libc-0.2.147", + srcs = [":libc-0.2.147.crate"], + crate = "libc", + crate_root = "libc-0.2.147.crate/src/lib.rs", + edition = "2015", + rustc_flags = ["@$(location :libc-0.2.147-build-script-run[rustc_flags])"], + visibility = [], +) + +cargo.rust_binary( + name = "libc-0.2.147-build-script-build", + srcs = [":libc-0.2.147.crate"], + crate = "build_script_build", + crate_root = "libc-0.2.147.crate/build.rs", + edition = "2015", + visibility = [], +) + +buildscript_run( + name = "libc-0.2.147-build-script-run", + package_name = "libc", + buildscript_rule = ":libc-0.2.147-build-script-build", + version = "0.2.147", +) + +http_archive( + name = "once_cell-1.18.0.crate", + sha256 = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d", + strip_prefix = "once_cell-1.18.0", + urls = ["https://crates.io/api/v1/crates/once_cell/1.18.0/download"], + visibility = [], +) + +cargo.rust_library( + name = "once_cell-1.18.0", + srcs = [":once_cell-1.18.0.crate"], + crate = "once_cell", + crate_root = "once_cell-1.18.0.crate/src/lib.rs", + edition = "2021", + features = [ + "alloc", + "race", + ], + visibility = [], +) + +http_archive( + name = "version_check-0.9.4.crate", + sha256 = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f", + strip_prefix = "version_check-0.9.4", + urls = ["https://crates.io/api/v1/crates/version_check/0.9.4/download"], + visibility = [], +) + +cargo.rust_library( + name = "version_check-0.9.4", + srcs = [":version_check-0.9.4.crate"], + crate = "version_check", + crate_root = "version_check-0.9.4.crate/src/lib.rs", + edition = "2015", visibility = [], ) diff --git a/third_party/fixups/ahash/fixups.toml b/third_party/fixups/ahash/fixups.toml new file mode 100644 index 0000000..5e026f7 --- /dev/null +++ b/third_party/fixups/ahash/fixups.toml @@ -0,0 +1,2 @@ +[[buildscript]] +[buildscript.rustc_flags] diff --git a/third_party/fixups/libc/fixups.toml b/third_party/fixups/libc/fixups.toml new file mode 100644 index 0000000..5e026f7 --- /dev/null +++ b/third_party/fixups/libc/fixups.toml @@ -0,0 +1,2 @@ +[[buildscript]] +[buildscript.rustc_flags] diff --git a/third_party/reindeer.toml b/third_party/reindeer.toml new file mode 100644 index 0000000..2c0f39f --- /dev/null +++ b/third_party/reindeer.toml @@ -0,0 +1,21 @@ +# Configuration for Reindeer to generate Buck targets from Cargo.toml +# +# Overview of available options: +# https://github.com/facebookincubator/reindeer/blob/main/example/third-party/reindeer.toml + +vendor = false + +precise_srcs = true + +[buck] +rust_library = "cargo.rust_library" +rust_binary = "cargo.rust_binary" + +generated_file_header = """ +# \u0040generated by `reindeer buckify` +""" + +buckfile_imports = """ +load("@prelude//rust:cargo_buildscript.bzl", "buildscript_run") +load("@prelude//rust:cargo_package.bzl", "cargo") +""" ```
photex commented 1 year ago

Ah OK, thank you for checking it out. Did I miss the information that the reindeer.toml is required to form a complete setup?

I only recalled that I need to run 'vendor' and 'buckify'. Which reminds me to ask, despite trying to run vendor several times I always ended up with a non-vendored setup. I thought I had read that the default was for vendored mode. Is that not the case?

Thanks again!

zertosh commented 1 year ago

Did I miss the information that the reindeer.toml is required to form a complete setup?

Yeah. Without a reindeer.toml reindeer doesn't do anything. @dtolnay, I just tried Reindeer without a reindeer.toml and it only generates rules for top-level crates - not their deps. Is this broken? Or how's this supposed to work?

Which reminds me to ask, despite trying to run vendor several times I always ended up with a non-vendored setup.

For this you do need a reindeer.toml because you need to specify the cargo table values.

I thought I had read that the default was for vendored mode. Is that not the case?

The default is non-vendored mode - but I am going to defer to @dtolnay on this because I am not really sure what the intent was.

photex commented 1 year ago

Great, thanks for the clarification and sharing your time. Maybe we should change the issue title or just close it so it's more clear for any future users who run up against their ignorance like I did? :D