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

Unable to build with custom target JSON spec #1501

Closed
yungkneez opened this issue Jan 1, 2021 · 1 comment · Fixed by #1502
Closed

Unable to build with custom target JSON spec #1501

yungkneez opened this issue Jan 1, 2021 · 1 comment · Fixed by #1502

Comments

@yungkneez
Copy link
Contributor

I'm unable to build a project with Rocket when using a custom JSON target spec.

Rocket version

0.4.6

Operating system

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.1 LTS
Release:	20.04
Codename:	focal

What is expected

A successful build.

What actually happens

$ cargo build -Z build-std --target x86_64-custom-linux-gnu.json

...

error[E0107]: wrong number of type arguments: expected 3, found 2
   --> /home/yungkneez/.cargo/registry/src/garden.eu.org-1ecc6299db9ec823/rocket_http-0.4.6/src/header.rs:124:14
    |
124 |     headers: IndexMap<Uncased<'h>, Vec<Cow<'h, str>>>
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 3 type arguments

error: aborting due to previous error

For more information about this error, try `rustc --explain E0107`.
error: could not compile `rocket_http`

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: build failed

Steps to reproduce (with nightly)

  1. cargo new rocket-custom-target && cd rocket-custom-target
  2. rustc -Z unstable-options --print target-spec-json --target x86_64-unknown-linux-gnu > x86_64-custom-linux-gnu.json

Cargo.toml

[package]
name = "rocket-custom-target"
version = "0.1.0"
authors = ["yungkneez"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rocket = "0.4.6"

src/main.rs

#![feature(decl_macro)]

#[macro_use] extern crate rocket;

#[get("/<name>/<age>")]
fn hello(name: String, age: u8) -> String {
    format!("Hello, {} year old named {}!", age, name)
}

fn main() {
	let _r = rocket::ignite().mount("/hello", routes![hello]);
}

  1. cargo build -Z build-std --target x86_64-custom-linux-gnu.json

What is happening

indexmap (a dependency in rocket_http) uses autocfg to determine if std is available. If autocfg cannot find std, S = RandomState is not provided by default. See indexmap-rs/indexmap#145.

To support custom targets for which std is available, we can enable the std feature for indexmap.

@jebrosen
Copy link
Collaborator

jebrosen commented Jan 1, 2021

indexmap (a dependency in rocket_http) uses autocfg to determine if std is available. If autocfg cannot find std, S = RandomState is not provided by default. See indexmap-rs/indexmap#145.

I'm a bit confused by this situation. autocfg's detection checks whether or not extern crate std; compiles. Since you ran cargo build -Z build-std, it seems like that should work and std should be detected? It sounds like there may be a bug or mismatch between what autocfg is detecting and how std is actually looked up that's worth reporting somewhere, but build-std is of course still unstable.

To support custom targets for which std is available, we can enable the std feature for indexmap.

Other issues aside, this approach seems fine since rocket_http does depend on IndexMap only needing two type arguments.

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

Successfully merging a pull request may close this issue.

2 participants