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

Cargo.toml files using absolute paths are not correctly parsed #2434

Closed
gbbosak opened this issue Nov 27, 2019 · 6 comments
Closed

Cargo.toml files using absolute paths are not correctly parsed #2434

gbbosak opened this issue Nov 27, 2019 · 6 comments

Comments

@gbbosak
Copy link
Contributor

gbbosak commented Nov 27, 2019

On Fuchsia; we use a gen-cargo script to generate Cargo.toml files from our custom build system that are compatible with RLS. These files use absolute paths to their dependencies, and this seems to break rust-analyzer, but functions just fine with RLS.

Steps to repro:

  • Download Fuchsia (see here): https://fuchsia.dev/fuchsia-src/development/source_code
  • fx set core.x64 --release
  • fx build (this may take several hours, and requires a pretty powerful machine)
  • fx gen-cargo //src/connectivity/bluetooth/profiles/bt-a2dp-sink:bin
  • Open fuchsia/src/connectivity/bluetooth/profiles/bt-a2dp-sink in an editor that supports rust-analyzer (such as VSCode)
  • Observe errors such as this "Unable to open 'channel.rs': Unable to read file (Error: File not found (/mntpnt/fuchsia/src/connectivity/bluetooth/profiles/bt-a2dp-sink/mntpnt/fuchsia/garnet/public/rust/fuchsia-zircon/src/channel.rs))."
    when trying to navigate between files with rust-analyzer.
@edwin0cheng
Copy link
Member

edwin0cheng commented Nov 29, 2019

I did try to replicate your case with a full path deps and but it did works :

# /sandbox/temp/foo/crates/foo.toml

[package]
name = "foo"
version = "0.1.0"
edition = "2018"

[dependencies]
baz = {path="/sandbox/temp/foo/crates/baz"}

Would you mind to just share the post-generated Cargo.toml ?

@matklad
Copy link
Member

matklad commented Nov 29, 2019

Haven't looked into this yet, but an interesting thing for Fuchsia use-case is that we don't require a Cargo.toml. Instead a rust-project.json file can be used, which just specifies the crates directly (ie, it's a lower-level in comparison to .toml). We don't really have any good docs for this functionality (mainly because there are no users I know of), but this tests shows an example:

https://github.com/rust-analyzer/rust-analyzer/blob/8b278b1ab660df0728508e45e88ac769a2e03a58/crates/ra_lsp_server/tests/heavy_tests/main.rs#L281-L354

In theory, producing something like project-json from a custom build system should be easier than faking whole Cargo.tomls

@gbbosak
Copy link
Contributor Author

gbbosak commented Nov 29, 2019

# Copyright 2019 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

[package]
name = "bt_a2dp_sink"
version = "0.1.0"
edition = "2018"
license-file = "LICENSE"
authors = ["rust-fuchsia@fuchsia.com"]
description = "Rust crate for Fuchsia OS"
repository = "https://fuchsia.googlesource.com"

[[bin]]

name = "bt_a2dp_sink"
path = "/mntpnt/fuchsia/src/connectivity/bluetooth/profiles/bt-a2dp-sink/src/main.rs"

[features]
default = []



[dev-dependencies]

[dependencies]
serde_json = "1"
slab = "0.4"
parking_lot = "0.9"
lazy_static = "1"
serde_derive = "1.0.99"
matches = "0.1.8"
failure = "0.1.1"
bitfield = "0.13"

[dependencies.bt_a2dp]
path = "/mntpnt/fuchsia/out/default/gen/src/connectivity/bluetooth/lib/bt-a2dp/bt-a2dp"
version = "0.1.0"

[dependencies.bt_avdtp]
path = "/mntpnt/fuchsia/out/default/gen/src/connectivity/bluetooth/lib/bt-avdtp/bt-avdtp"
version = "0.1.0"

[dependencies.fuchsia_async]
path = "/mntpnt/fuchsia/out/default/gen/garnet/public/rust/fuchsia-async/fuchsia-async"
version = "0.1.0"

[dependencies.fidl_fuchsia_media_playback]
path = "/mntpnt/fuchsia/out/default/gen/sdk/fidl/fuchsia.media.playback/fuchsia.media.playback-rustc"
version = "0.1.0"

[dependencies.fidl_fuchsia_cobalt]
path = "/mntpnt/fuchsia/out/default/gen/zircon/system/fidl/fuchsia-cobalt/fuchsia-cobalt-rustc"
version = "0.1.0"

[dependencies.fuchsia_bluetooth]
path = "/mntpnt/fuchsia/out/default/gen/src/connectivity/bluetooth/lib/fuchsia-bluetooth/fuchsia-bluetooth"
version = "0.1.0"

[dependencies.fuchsia-zircon]
path = "/mntpnt/fuchsia/out/default/gen/garnet/public/rust/fuchsia-zircon/fuchsia-zircon"
version = "0.3.3"

[dependencies.log]
version = "0.4.4"
features = ["std"]

[dependencies.fuchsia-inspect]
path = "/mntpnt/fuchsia/out/default/gen/src/lib/inspect/rust/fuchsia-inspect/fuchsia-inspect"
version = "0.1.0"

[dependencies.fidl]
path = "/mntpnt/fuchsia/out/default/gen/garnet/public/lib/fidl/rust/fidl/fidl"
version = "0.1.0"

[dependencies.fuchsia_cobalt]
path = "/mntpnt/fuchsia/out/default/gen/src/lib/cobalt/rust/fuchsia-cobalt"
version = "0.1.0"

[dependencies.fidl_fuchsia_media]
path = "/mntpnt/fuchsia/out/default/gen/sdk/fidl/fuchsia.media/fuchsia.media-rustc"
version = "0.1.0"

[dependencies.fuchsia_syslog]
path = "/mntpnt/fuchsia/out/default/gen/garnet/public/rust/fuchsia-syslog/fuchsia-syslog"
version = "0.1.0"

[dependencies.fuchsia_inspect_contrib]
path = "/mntpnt/fuchsia/out/default/gen/src/lib/inspect/rust/fuchsia-inspect-contrib/fuchsia-inspect-contrib"
version = "0.1.0"

[dependencies.fidl_fuchsia_bluetooth_bredr]
path = "/mntpnt/fuchsia/out/default/gen/sdk/fidl/fuchsia.bluetooth.bredr/fuchsia.bluetooth.bredr-rustc"
version = "0.1.0"

[dependencies.fidl_fuchsia_bluetooth]
path = "/mntpnt/fuchsia/out/default/gen/sdk/fidl/fuchsia.bluetooth/fuchsia.bluetooth-rustc"
version = "0.1.0"

[dependencies.fdio]
path = "/mntpnt/fuchsia/out/default/gen/garnet/public/rust/fdio/fdio"
version = "0.2.0"

[dependencies.futures]
version = "0.3.1"
features = ["io-compat"]

[dependencies.fidl_fuchsia_mem]
path = "/mntpnt/fuchsia/out/default/gen/zircon/system/fidl/fuchsia-mem/fuchsia-mem-rustc"
version = "0.1.0"

[dependencies.fuchsia-component]
path = "/mntpnt/fuchsia/out/default/gen/garnet/public/rust/fuchsia-component/fuchsia-component"
version = "0.1.0"

[dependencies.bt_a2dp_sink_metrics]
path = "/mntpnt/fuchsia/out/default/gen/src/connectivity/bluetooth/profiles/bt-a2dp-sink/bt_a2dp_sink_metrics_rustlib"
version = "1.0.0"

[dependencies.fidl_fuchsia_bluetooth_avdtp]
path = "/mntpnt/fuchsia/out/default/gen/sdk/fidl/fuchsia.bluetooth.avdtp/fuchsia.bluetooth.avdtp-rustc"
version = "0.1.0"

[patch]

[patch.crates-io]

[patch.crates-io.fuchsia-cprng]
path = "/mntpnt/fuchsia/third_party/rust_crates/../../garnet/public/rust/fuchsia-cprng"

[patch.crates-io.cmake]
path = "/mntpnt/fuchsia/third_party/rust_crates/tiny_mirrors/cmake"

[patch.crates-io.rust-crypto]
path = "/mntpnt/fuchsia/third_party/rust_crates/../rust-mirrors/rust-crypto"

[patch.crates-io.servo-freetype-sys]
path = "/mntpnt/fuchsia/third_party/rust_crates/tiny_mirrors/servo-freetype-sys"

[patch.crates-io.xi-rope]
path = "/mntpnt/fuchsia/third_party/rust_crates/../rust-mirrors/xi-editor/rust/rope"

[patch.crates-io.xi-core-lib]
path = "/mntpnt/fuchsia/third_party/rust_crates/../rust-mirrors/xi-editor/rust/core-lib"

[patch.crates-io.xi-rpc]
path = "/mntpnt/fuchsia/third_party/rust_crates/../rust-mirrors/xi-editor/rust/rpc"

[patch.crates-io.backtrace-sys]
path = "/mntpnt/fuchsia/third_party/rust_crates/tiny_mirrors/backtrace-sys"

[patch.crates-io.xi-trace]
path = "/mntpnt/fuchsia/third_party/rust_crates/..//rust-mirrors/xi-editor/rust/trace"

[patch.crates-io.xi-trace-dump]
path = "/mntpnt/fuchsia/third_party/rust_crates/../rust-mirrors/xi-editor/rust/trace-dump"

[patch.crates-io.winapi-util]
path = "/mntpnt/fuchsia/third_party/rust_crates/tiny_mirrors/winapi-util"

[patch.crates-io.web-sys]
path = "/mntpnt/fuchsia/third_party/rust_crates/tiny_mirrors/web-sys"

[patch.crates-io.winapi]
path = "/mntpnt/fuchsia/third_party/rust_crates/tiny_mirrors/winapi"

[patch.crates-io.xi-unicode]
path = "/mntpnt/fuchsia/third_party/rust_crates/../rust-mirrors/xi-editor/rust/unicode"

[patch.crates-io.pkg-config]
path = "/mntpnt/fuchsia/third_party/rust_crates/tiny_mirrors/pkg-config"

[profile]

[profile.release]
lto = "thin"
panic = "abort"
opt-level = "z"

@edwin0cheng
Copy link
Member

edwin0cheng commented Nov 30, 2019

@gbbosak The following are just my guesses:

Did any Cargo.toml generated in /mntpnt/fuchsia/src ? If I understand correctly, RA use cargo-metadata and It will search through ancestor directory to get relevant workspace information.

Maybe that Cargo.toml in mntpnt/fuhsia/src confuses the actual path data ?

BTW, I would recommend to discuses in RA Zulip Channel.

@gbbosak
Copy link
Contributor Author

gbbosak commented Dec 26, 2019

We're looking into whether or not emitting a rust-project.json file would be feasible. I'll update this when I find out the results of that.

@gbbosak
Copy link
Contributor Author

gbbosak commented May 15, 2020

We've switched to rust-project.json and it works now. Closing this bug.

@gbbosak gbbosak closed this as completed May 15, 2020
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

3 participants