Skip to content
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

Indexmap Dep Not properly Compiled #114

Closed
gluax opened this issue Oct 26, 2019 · 4 comments
Closed

Indexmap Dep Not properly Compiled #114

gluax opened this issue Oct 26, 2019 · 4 comments

Comments

@gluax
Copy link

gluax commented Oct 26, 2019

Hey when trying to compile with Bazel I get the following error for the Indexmap version-1.3.0 dependency.
image

The following is the BUILD file generated for said dep.

cargo-raze crate build file.

DO NOT EDIT! Replaced on runs of cargo-raze
"""
package(default_visibility = [
  # Public for visibility by "@raze__crate__version//" targets.
  #
  # Prefer access through "//cargo", which limits external
  # visibility to explicit Cargo.toml dependencies.
  "//visibility:public",
])

licenses([
  "notice", # "Apache-2.0,MIT"
])

load(
    "@io_bazel_rules_rust//rust:rust.bzl",
    "rust_library",
    "rust_binary",
    "rust_test",
)


# Unsupported target "bench" with type "bench" omitted
# Unsupported target "build-script-build" with type "custom-build" omitted
# Unsupported target "equivalent_trait" with type "test" omitted
# Unsupported target "faststring" with type "bench" omitted

rust_library(
    name = "indexmap",
    crate_root = "src/lib.rs",
    crate_type = "lib",
    edition = "2015",
    srcs = glob(["**/*.rs"]),
    deps = [
        "//cargo/vendor/serde-1.0.101:serde",
    ],
    rustc_flags = [
        "--cap-lints=allow",
    ],
    version = "1.3.0",
    crate_features = [
        "serde",
        "serde-1",
    ],
)

# Unsupported target "macros_full_path" with type "test" omitted
# Unsupported target "quick" with type "test" omitted
# Unsupported target "serde" with type "test" omitted
# Unsupported target "tests" with type "test" omitted

My rust version is 1.38 and alloc should compile and if not the package build.rs should add the std lib.
Is there a way I can help fix this or anything?

@acmcarther
Copy link
Member

acmcarther commented Oct 28, 2019

Here's the relevant snippet of indexmap-1.30.0
https://github.com/bluss/indexmap/blob/c8204515dc1f5bc74c89ca440ecbaa470f30520d/src/lib.rs#L55-L57

#[cfg(not(has_std))]
#[macro_use(vec)]
extern crate alloc;

It looks like has_std is populated by build.rs via the autocfg crate
https://github.com/bluss/indexmap/blob/c8204515dc1f5bc74c89ca440ecbaa470f30520d/build.rs#L4-L6

    let ac = autocfg::new();
    ac.emit_sysroot_crate("std");
    autocfg::rerun_path(file!());

From the documentation of autocfg::emit_sysroot_crate, the function "Emits a config value has_CRATE if probe_sysroot_crate returns true."
https://github.com/cuviper/autocfg/blob/15ea2ca3b6bcdc2af7dab514b571e55fd9370957/src/lib.rs#L265-L270

    /// Emits a config value `has_CRATE` if `probe_sysroot_crate` returns true.
    pub fn emit_sysroot_crate(&self, name: &str) {
        if self.probe_sysroot_crate(name) {
            emit(&format!("has_{}", mangle(name)));
        }
    }

(Nitty gritty aside: It seem the way this works is the autocfg library tries to run rustc over a file containing the single "extern $some_crate", and identifies whether or not that compiles)

TL;DR: indexmap depends on --cfg has_std, which is populated by the build.rs when the std crate is available.*

I don't think this build.rs file can work in the context of Bazel. Your best bet is probably to include the config value manually in an "additional_flags" [raze] parameter. An example:

[raze.crates.proc-macro2.'0.4.28']
additional_flags = [
"--cfg=use_proc_macro",
]

@gluax
Copy link
Author

gluax commented Oct 28, 2019

Ahh great that helped a bunch thanks for clearing that up!

Just one more quick question if you could help with that it would be great.
If I am using something lisqlite3_sys with bazel and cargo raze would I need to do something similar to what you all did for openssl?

@acmcarther
Copy link
Member

acmcarther commented Oct 29, 2019

Yeah, I think you'd need to do something similar.

I actually did this work once before for bringing in libsqlite3-sys for rusqlite, and it looks like I decided to totally overwrite the libsqlite3-sys dependency. I can't remember why... Here's the settings for rusqlite:
https://github.com/acmcarther/void/blob/590be5e8df498dc791e10ba0f35083e5493adcd0/third_party/cargo/Cargo.toml#L43-L49

[raze.crates.rusqlite.'0.14.0']
skipped_deps = [
  "libsqlite3-sys-0.9.3"
]
additional_deps = [
  "@//third_party/cargo/overrides/libsqlite3-sys:libsqlite3_sys"
]

And the libsqlite override library:
https://github.com/acmcarther/void/tree/master/third_party/cargo/overrides/libsqlite3-sys

I think the significant changes were:

  • Update the cargo-raze generated BUILD file to use my workspace's bindgen brought in by cargo-raze
  • Update the cargo-raze generated BUILD file to depend on my workspace's sqlite3 package. It looks like I hand wrote that BUILD file... I'm not sure if that's still the "easiest" way to do this.

https://github.com/acmcarther/void/tree/master/third_party/sqlite3

I feel like these Cargo crate transformations should be captured somewhere so we can pool our efforts. I'll think about the best way to accomplish this. Ideas very welcome of course!

@gluax
Copy link
Author

gluax commented Nov 4, 2019

Hey thanks for all the help and sorry for late reply. That was super helpful.

We can capture these transformation in a separate repo that just has a folder for the different cargo packages(when needed). Then just link that to the main page here, as one idea. Although I suppose that could be a nightmare with the different cargo package versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants