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
Allow specifying paths for @library
imports
#3651
Conversation
84bde6a
to
e2c6438
Compare
This comment was marked as outdated.
This comment was marked as outdated.
e2c6438
to
7e03865
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks overall good to me! I think the error handling could be tweaked a little, but otherwise I love it.
Two other missing things I can think of:
- An entry in the ChangeLog
- Documentation in
modules.md
(could be done separately though)
internal/compiler/typeloader.rs
Outdated
), | ||
if file_to_import.starts_with('@') { | ||
format!( | ||
"Cannot find requested library \"{file_to_import}\" in the library search path", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, but if the import is @some-library/some_file.slint
the error message is going to call the entire string a library, when there are in fact two error cases:
some-library
could not be found (missing in library search path)- Within
some-library
the filesome_file.slint
could not be found.
7f56c4e
to
af7a682
Compare
Current status:
The second and third could be better. |
Looks good to me. This makes a clear distinction at least between the library search path and regular includes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is the way to go. This is a very good incremental step to me, and there's time for docs. I'd love to hear what the others are thinking, but IMO this is good to go.
(please rebase once to get rid of the merge commit and the conflicts - we normally do rebases instead of merge, so no worries there :) |
87bd9e5
to
03fd428
Compare
I didn't include the docs from #3523 because they were so centered around the Cargo and NPM integration, which was left out of this PR. :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could be merged as is, but still feel it is lacking a bunch of things:
Documentation: there seems to be almost nothing, but the concept of @library should be explained in the docs with help on how to pass these library path.
The slint-viewer also need a way to set the library path through command line argument. Currently there is -I
for the include path, but it should also support something like -I library=/path/to/library
or some other --lib library=/path/to/library
And this should be documented in the viewer docs
Same for slint-compiler (so it can be exposed in C++)
Maybe the documention of rust can make an example where a crate is taken as a build_dependency and do
pub fn slint_path() -> &str { env!("CARGO_MANIFEST_PATH/index.slint") }
I've added an example to |
/// let manifest_dir = std::path::PathBuf::from(std::env::var_os("CARGO_MANIFEST_DIR").unwrap()); | ||
/// let library_paths = std::collections::HashMap::from([( | ||
/// "example".to_string(), | ||
/// manifest_dir.join("third_party/example/ui/lib.slint"), | ||
/// )]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not really what i had in mind.
I was thinking that the code that use CARGO_MANIFEST_DIR would be in a build-dependency (eg, coop_widget uploaded to crates.io)
but that work too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have somewhat mixed feelings about teaching users to wire up Cargo dependencies manually if the end goal is to make it automatic once the issues with compiling libraries have been sorted out. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, i understand. Just leave it like this then.
I like it. At least seems reasonable and can't think of anything better. |
d0d64e6
to
1d9c880
Compare
Rebased and squashed the fixup commits |
1d9c880
to
4f916bc
Compare
@jpnurmi this is the branch where I make usage of the |
4f916bc
to
7cf87e5
Compare
Cool, thanks for giving it a try! A helper function for the import paths is quite nice to avoid an awkward empty |
Thank you for implementing it ;-) . I definitely a good progress for the lib imports :-). I like it. |
This PR is a revised version of #3523 that drops everything related to Cargo and NPM, and instead allows manually specifying library paths in the compiler config:
Import types from the libraries: