user51
user51

Reputation: 10143

error: failed to select a version for `tree-sitter`. gpui.rs

I'm trying to create simple ui program using gpui.rs.

Below is the Cargo.toml -

[package]
name = "gpui-first-look-duanne-bester"
version = "0.1.0"
edition = "2021"

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

[dependencies]
gpui = { git = "https://github.com/zed-industries/zed" }
assets = { git = "https://github.com/zed-industries/zed" }
theme = { git = "https://github.com/zed-industries/zed" }
settings = { git = "https://github.com/zed-industries/zed" }
ui = { git = "https://github.com/zed-industries/zed" }

Below is my main.rs file -

use gpui::*;
use assets::Assets;
use settings::{default_settings, SettingsStore};
use theme::{ThemeRegistry, ThemeSettings};
use seetings::Settings;

struct HelloWorld {
    text: SharedString,
}

impl Render for HelloWorld {
    fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement {
        div()
            .flex()
            .bg(rgb(0x2e7d32))
            .size_full()
            .justify_center()
            .items_center()
            .text_xl()
            .text_color(rgb(0xffffff))
            .child(format!("Hello, {}!", &self.text))
    }
}

fn main() {
    App::new().run(|cx: &mut AppContext| {

        let theme_name = "One Dark";

        let mut store = SettingsStore::default();
        store.set_default_settings(default_settings().as_ref(), cx)
            .unwrap();
        cx.set_global(store);

        theme::init(themes_to_load: theme::LoadThemes::All(Box::new(Assets)), cx);

        let theme_registry :&ThemeRegistry = cx.global::<ThemeRegistry>();
        let mut theme_settings: ThemeSettings = ThemeSettings::get_global(cx).clone();
        theme_settings.active_theme = theme_registry.get(&theme_name).unwrap();
        ThemeSettings::override_global(theme_settings, cx);

        cx.open_window(WindowOptions::default(), |cx| {
            cx.new_view(|_cx| HelloWorld {
                text: "World".into(),
            })
        });
    });
}

When I do cargo run I get below error -

cargo run Updating git repository https://github.com/zed-industries/zed

Updating crates.io index

Updating git repository https://github.com/zed-industries/font-kit

Updating git repository https://github.com/DioxusLabs/taffy

Updating git repository https://github.com/kvark/blade

Updating git repository https://github.com/zed-industries/bromberg_sl2

error: failed to select a version for tree-sitter.

... required by package settings v0.1.0 (https://github.com/zed-industries/zed#0ce5cdc4)

... which satisfies git dependency settings of package gpui-first-look-duanne-bester v0.1.0 (/Users/rnatarajan/Documents/Coding/others/gpui-first-look-duanne-bester)

versions that meet the requirements ^0.20 are: 0.20.10, 0.20.9, 0.20.8, 0.20.7, 0.20.6, 0.20.5, 0.20.4, 0.20.3, 0.20.2, 0.20.1, 0.20.0

the package settings depends on tree-sitter, with features: wasm but tree-sitter does not have these features.

failed to select a version for tree-sitter which could resolve this conflict

Any idea what is going wrong here? How can I fix this error? My project is in github here.

Upvotes: 0

Views: 204

Answers (1)

Kevin Reid
Kevin Reid

Reputation: 43753

This is an error not in your code. The current contents of the Cargo.toml from https://github.com/zed-industries/zed include:

[workspace.dependencies]
...
tree-sitter = { version = "0.20", features = ["wasm"] }

which is self-contradictory, because the wasm feature wasn't introduced until incompatible version 0.21. This cannot be compiled. So, why doesn't this break everybody? Because the Cargo.toml also contains a patch which overrides this dependency:

[patch.crates-io]
tree-sitter = { git = "https://github.com/tree-sitter/tree-sitter", rev = "4294e59279205f503eb14348dd5128bd5910c8fb" }

Therefore, when building the zed workspace, the tree-sitter source is fetched from that particular Git commit (which does have a wasm feature declared). But patches are ignored when you are merely depending on a library, not building/developing in that specific workspace.

So, the error is in the zed repository, for your purposes. If they wish to support use of their libraries in the way you're attempting, then they should replace the patch with a plain git dependency:

[workspace.dependencies]
...
tree-sitter = { git = "https://github.com/tree-sitter/tree-sitter", rev = "4294e59279205f503eb14348dd5128bd5910c8fb", features = ["wasm"] }

I don't see any explanation of why they don't do this — there is no comment, and the commit which added the patch didn't explain either. So perhaps this is just an oversight and they'd welcome a PR to simplify it — or perhaps there's a non-obvious reason it's necessary.

As a workaround, you could include the [patch.crates-io] that I quoted above in your Cargo.toml.

Upvotes: 4

Related Questions