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

Add support for importing components, data structures, etc. generated from an earlier Slint compiler invocation #7060

Open
tronical opened this issue Dec 11, 2024 · 0 comments
Labels
a:language-c++ C++ API, codegen, CMake build system (mS,mO) a:language-rust Rust API and codegen (mO,mS) enhancement New feature or request

Comments

@tronical
Copy link
Member

This issue originates from #6196.

Example:

  1. Crate A compiles foo.slint, which exports components, globals, data structures, etc. as well as business logic related to foo.slint.
  2. Crate B compiles main.slint, which imports foo.slint (for example as a library) and wants to re-use components, etc. as well as the business logic from crate A, without generating foo.slint's types again.

The objective is to enable this workflow for Rust and C++.

In order to implement this, we need to use the Slint library system as well as the ability to associate a Slint library with a Rust module or a C++ namespace, and in addition we need build system support so that cmake or cargo can locate the user's slint library just from the dependencies.

add_library(MyreusableComponent ...)
// Doesn't generate the typical "app" entry but might generate more library/style reusable code
// This also will set various cmake target properties on MyreusableComponent ...)
slint_library_target_sources(MyreusableComponent NAME MyLibrary mylib.slint)

add_executable(my_app ...)
target_link_libraries(my_app MyreusableComponent)
// this needs to look at my_app's linked targets and locate those that contain Slint libraries, to be able
// to locate the header file, library name, etc.
slint_target_sources(my_app main.slint)

// main.slint can do `import { Foo } from "@MyLibrary"`

my-library's build.rs:

fn main() {
    let config = slint_build::CompilerConfiguration::new().as_library("MyLibrary").rust_module("mymodule");
    slint_build::compile_with_config("mylib.slint", config);
}

my-library''s lib.rs`:

pub mod mymodule {
    slint::include_modules!()
}

App's Cargo.toml:

[dependencies]
my-library = { ... }

App's invocation of the slint compiler would use DEP_MY_LIBRARY_SLINT_XXX to locate the path to the .slint library file, name of the library, etc.

It would be tempting to use the links feature of Cargo for this, but that's a hack. The recommended way would be that my-library also has a my-library-build crate that provides API for App's build.rs, to then invoke the slint compiler accordingly.

@tronical tronical added enhancement New feature or request a:language-c++ C++ API, codegen, CMake build system (mS,mO) a:language-rust Rust API and codegen (mO,mS) labels Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:language-c++ C++ API, codegen, CMake build system (mS,mO) a:language-rust Rust API and codegen (mO,mS) enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant