I have a Rust program (originally non-bazel) that uses the
diesel and the
diesel_migrations crate to embed .sql files, for performing database migrations with. Internally, Diesel seems to use the include_str!() macro to do this.
Now, I'm trying to convert my program to use Bazel. I used cargo raze to generate the cargo targets, but there were errors about the sql files not being found:
error: couldn't read external/raze__diesel__1_4_8/src/sqlite/connection/diesel_manage_updated_at.sql: No such file or directory (os error 2)
--> external/raze__diesel__1_4_8/src/sqlite/connection/mod.rs:252:21
|
252 | include_str!("diesel_manage_updated_at.sql"),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `include_str` (in Nightly builds, run with -Z macro-backtrace for more info)
For reference, this is my package Cargo.toml:
[package]
authors = ["Astrid Yu <ast...@astrid.tech>"]
description = "A webmention receiver and processor."
edition = "2018"
homepage = "https://astrid.tech/projects/astrid-tech"
name = "wm-receiver"
resolver = "1"
publish = false
repository = "https://github.com/astralbijection/astrid.tech.git"
version = "0.1.0"
[[bin]]
name = "wm-receiver"
path = "src/main.rs"
[dependencies]
diesel_migrations = "*"
dotenv = "*"
reqwest = "*"
rocket = "0.5.0-rc.1"
rocket_codegen = "0.5.0-rc.1"
sanitize-filename = "*"
scraper = "*"
serde = "*"
serde_json = "*"
sha256 = "*"
url = "*"
[dependencies.chrono]
features = ["serde"]
version = "*"
[dependencies.diesel]
default-features = false
features = ["sqlite", "chrono"]
version = "*"
[dependencies.microformats_parser]
git = "https://gitlab.com/maxburon/microformats-parser.git"
[dependencies.tokio]
features = ["process", "sync"]
version = "*"
[build-dependencies]
diesel = { version = "1.4.7", features = ["chrono", "sqlite"] }
[dev-dependencies]
rstest = "0.11.0"
tempdir = "*"
This is my workspace Cargo.toml file:
[workspace]
members = [
"aay_tw_shortener",
"wm-receiver",
]
[workspace.metadata.raze]
workspace_path = "//cargo"
targets = [
"x86_64-apple-darwin",
"x86_64-pc-windows-msvc",
"x86_64-unknown-linux-gnu",
]
genmode = "Remote"
default_gen_buildrs = true
This is my BUILD file:
load("@rules_rust//rust:rust.bzl", "rust_binary")
load("@rules_rust//rust:rust.bzl", "rust_library")
rust_binary(
name = "wm-receiver",
srcs = ["src/main.rs", "src/db.rs"],
deps = [
"//wm-receiver/cargo:diesel_migrations",
"//wm-receiver/cargo:dotenv",
"//wm-receiver/cargo:reqwest",
"//wm-receiver/cargo:rocket",
"//wm-receiver/cargo:sanitize_filename",
"//wm-receiver/cargo:scraper",
"//wm-receiver/cargo:serde",
"//wm-receiver/cargo:serde_json",
"//wm-receiver/cargo:sha256",
"//wm-receiver/cargo:url",
],
data = [
"migrations"
],
proc_macro_deps = [
"//wm-receiver/cargo:rocket_codegen",
]
)
filegroup(
name = "migrations",
srcs = glob([
"migrations/**/*.sql"
]),
)