-
Notifications
You must be signed in to change notification settings - Fork 424
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
Diesel Migration Panics #2802
Comments
Seems like this can be solved by overwriting the CARGO_MANIFEST_DIR environment variable It is unclear to me why I have to overwrite CARGO_MANIFEST_DIR but it's definitely needed otherwise the macro panics. The config below works, though. load("@bazel_skylib//rules:copy_directory.bzl", "copy_directory")
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
load("@rules_rust//rust:defs.bzl", "rust_doc", "rust_doc_test", "rust_library")
filegroup(
name = "diesel_toml",
srcs = glob([
"diesel.toml",
]),
)
copy_directory(
name = "copy_migrations",
src = "migrations",
out = "migrations",
)
rust_library(
name = "services",
srcs = glob([ "src/**"]),
crate_root = "src/lib.rs",
compile_data = [
":diesel_toml",
":copy_migrations",
],
rustc_env = {
"CARGO_MANIFEST_DIR": "/absolute/path/to/bazel-diesel-postgres",
},
deps = [
# External crates
"@crates//:diesel",
"@crates//:diesel_migrations",
],
visibility = ["//visibility:public"],
) |
Closing this because the CARGO_MANIFEST_DIR env variable can be generated with a genfile. |
Bazel: 7.3.0
rules_rust: 0.49.1
rust: 1.80.1
I have a crate that uses the diesel and the diesel_migrations crate to embed .sql files,
but no matter what I try, the macro panics during build and reports t the sql files not being found.
The error:
The same crate builds fine with Cargo.
Full reproduction of the issue: https://github.com/marvin-hansen/bazel-diesel-postgres
Note, the crate was recently donated as code example to the Diesel project, so just ignore the fluff about custom Postgres types.
I did some research and found a few hints:
Expanding on the last point, the macro constructs the path to the migration folder as following:
Here, the CARGO_MANIFEST_DIR is set, I have verified that.
The migrations_path can be set either in the Diesel.toml config or as an optional argument to the macro.
I did both, defined in the Diesel config file and set the same folder name as an argument to the macro.
And then the resolve_migrations_directorym that to throw the error, joins the two together as the path to find the migration folder.
In the repro, the final relative path should be something like:
/bazel-diesel-postgres/migrations
And both, the folder and the Diesel.toml config are copied into the Bazel sandbox.
And yet, somehow the macro keeps panicking.
The text was updated successfully, but these errors were encountered: