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/zedUpdating crates.io index
Updating git repository
https://github.com/zed-industries/font-kitUpdating git repository
https://github.com/DioxusLabs/taffyUpdating git repository
https://github.com/kvark/bladeUpdating git repository
https://github.com/zed-industries/bromberg_sl2error: 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
settingsof packagegpui-first-look-duanne-bester v0.1.0 (/Users/rnatarajan/Documents/Coding/others/gpui-first-look-duanne-bester)versions that meet the requirements
^0.20are: 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.0the package
settingsdepends ontree-sitter, with features:wasmbuttree-sitterdoes not have these features.failed to select a version for
tree-sitterwhich could resolve this conflict
Any idea what is going wrong here? How can I fix this error? My project is in github here.
This is an error not in your code. The current contents of the
Cargo.tomlfrom https://github.com/zed-industries/zed include:which is self-contradictory, because the
wasmfeature wasn't introduced until incompatible version 0.21. This cannot be compiled. So, why doesn't this break everybody? Because theCargo.tomlalso contains a patch which overrides this dependency:Therefore, when building the
zedworkspace, thetree-sittersource is fetched from that particular Git commit (which does have awasmfeature 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
zedrepository, for your purposes. If they wish to support use of their libraries in the way you're attempting, then they should replace thepatchwith a plaingitdependency: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 yourCargo.toml.