rules_rust doesn't work with Diesel because of include_str!()

232 views
Skip to first unread message

Astrid Yu

unread,
Sep 23, 2021, 8:16:23 PM9/23/21
to bazel-discuss
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"
    ]),
)


Daniel Wagner-Hall

unread,
Sep 24, 2021, 7:14:13 PM9/24/21
to Astrid Yu, bazel-discuss
There is some discussion of this on this issue: https://github.com/bazelbuild/rules_rust/issues/947

If you could contribute your example there, it'd help us to make sure that we solve the problem completely :)

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/577e191e-2a5c-468e-be2f-aa9d0db87998n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages