blackjack icon indicating copy to clipboard operation
blackjack copied to clipboard

"environment variable `OUT_DIR` not defined" when building num_bigint

Open dhbaird opened this issue 2 years ago • 2 comments

I'm getting several errors trying to use num_bigint via blackjack, starting with OUT_DIR, which Cargo normally sets (https://doc.rust-lang.org/cargo/reference/environment-variables.html),

error: environment variable `OUT_DIR` not defined
   --> external/crates_io_num_bigint/src/biguint/convert.rs:759:28
    |
759 |         include! { concat!(env!("OUT_DIR"), "/radix_bases.rs") }
    |                            ^^^^^^^^^^^^^^^
    |
    = note: this error originates in the macro `env` (in Nightly builds, run with -Z macro-backtrace for more info)

Files

WORKSPACE

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# =============================================================================
# rules_rust
# =============================================================================
http_archive(
    name = "rules_rust",
    sha256 = "50c250043bcec91d7dcdda0abbedd7a0d21c657b14ae0a4999eca59c14defa49",
    strip_prefix = "rules_rust-b9469a0a22fe36eecf85820fafba7e901662f900",
    urls = [
        # `main` branch as of 2022-03-07
        "https://github.com/bazelbuild/rules_rust/archive/b9469a0a22fe36eecf85820fafba7e901662f900.tar.gz",
    ],
)
load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains")
rules_rust_dependencies()
rust_register_toolchains()

# =============================================================================
# blackjack
# =============================================================================
http_archive(
    name = "blackjack",
    url = "https://github.com/wildarch/blackjack/archive/909b66db4782cf963791aa4a24793244dffdba17.zip",
    strip_prefix = "blackjack-909b66db4782cf963791aa4a24793244dffdba17",
)
load("@blackjack//:workspace.bzl", "blackjack_cargo")
blackjack_cargo()
load("//:cargo_dependencies.bzl", "cargo_dependencies")
cargo_dependencies()

BUILD

load("@blackjack//:blackjack.bzl", "blackjack")
blackjack(name = "blackjack", manifest = "//:Cargo.toml")

Cargo.toml

[workspace]
members = ["myapp"]

myapp/BUILD

package(default_visibility = ["//visibility:public"])
load("@rules_rust//rust:defs.bzl", "rust_binary")
rust_binary(
    name = "myapp",
    srcs = ["src/main.rs"],
    deps = ["@crates_io_num_bigint//:num_bigint"],
)

myapp/Cargo.toml

[package]
name = "myapp"
version = "0.1.0"
edition = "2021"

[dependencies]
rand = "0.8"
num-bigint = { version = "0.4", features = ["rand"] }

myapp/src/main.rs

#![allow(unused_imports)]
use num_bigint::BigInt;
fn main() {
}

dhbaird avatar Mar 08 '22 00:03 dhbaird

Note: I tried with cargo-raze in remote mode, and it works there.

dhbaird avatar Mar 08 '22 01:03 dhbaird

It looks like you may need to enable build scripts for the num-bigint crate. The readme has an example on how to do this, should be something like:

[package.metadata.blackjack.num-bigint]
build_script = true

This should be added to Cargo.toml.

wildarch avatar Mar 11 '22 12:03 wildarch