Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Use library path and clear most of the UDL file #749

Merged
merged 4 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bindings/wysiwyg-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ default = []
assert-invariants = ["wysiwyg/assert-invariants"]

[lib]
crate-type = ["cdylib", "staticlib"]
# lib crate-type shouldn't be required anymore when https://github.com/mozilla/uniffi-rs/pull/1671 lands
crate-type = ["cdylib", "staticlib", "lib"]

[dependencies]
# Keep the uniffi version here in sync with the installed version of
Expand Down
4 changes: 3 additions & 1 deletion bindings/wysiwyg-ffi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ lipo -create \

```bash
cargo uniffi-bindgen \
generate src/wysiwyg_composer.udl \
--library ../../target/aarch64-apple-ios/release/libuniffi_wysiwyg_composer.a \
--language swift \
--config uniffi.toml \
--out-dir MY_OUTPUT_DIR
Expand All @@ -134,6 +134,8 @@ mv *.modulemap headers/module.modulemap
mv *.swift Sources/
```

The used library file is arbitrary the ARM64 one, but any could be used.

Note: The project should always have a single Swift modulemap file, and it
should be named `module.modulemap` otherwise the generated framework will not
expose symbols properly to Swift.
Expand Down
2 changes: 1 addition & 1 deletion bindings/wysiwyg-ffi/src/ffi_action_state.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, uniffi::Enum)]
pub enum ActionState {
Enabled,
Reversed,
Expand Down
2 changes: 1 addition & 1 deletion bindings/wysiwyg-ffi/src/ffi_composer_action.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, uniffi::Enum)]
pub enum ComposerAction {
Bold,
Italic,
Expand Down
13 changes: 6 additions & 7 deletions bindings/wysiwyg-ffi/src/ffi_composer_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::ffi_link_actions::LinkAction;
use crate::into_ffi::IntoFfi;
use crate::{ActionState, ComposerAction, SuggestionPattern};

#[derive(Default)]
#[derive(Default, uniffi::Object)]
pub struct ComposerModel {
inner: Mutex<wysiwyg::ComposerModel<Utf16String>>,
}
Expand All @@ -22,7 +22,10 @@ impl ComposerModel {
inner: Mutex::new(wysiwyg::ComposerModel::new()),
}
}
}

#[uniffi::export]
impl ComposerModel {
pub fn set_content_from_html(
self: &Arc<Self>,
html: String,
Expand Down Expand Up @@ -367,18 +370,14 @@ impl ComposerModel {
self.inner.lock().unwrap().get_link_action().into()
}

#[cfg(not(debug_assertions))]
pub fn debug_panic(self: &Arc<Self>) {
// No-op
}

/// Force a panic for test purposes
#[cfg(debug_assertions)]
pub fn debug_panic(self: &Arc<Self>) {
#[cfg(debug_assertions)]
panic!("This should only happen in tests.");
}
}

#[derive(uniffi::Record)]
pub struct Attribute {
pub key: String,
pub value: String,
Expand Down
1 change: 1 addition & 0 deletions bindings/wysiwyg-ffi/src/ffi_composer_state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use widestring::Utf16String;
use wysiwyg::ToHtml;

#[derive(uniffi::Record)]
pub struct ComposerState {
pub html: Vec<u16>,
pub start: u32,
Expand Down
4 changes: 4 additions & 0 deletions bindings/wysiwyg-ffi/src/ffi_composer_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::ffi_menu_state::MenuState;
use crate::ffi_text_update::TextUpdate;
use crate::MenuAction;

#[derive(uniffi::Object)]
pub struct ComposerUpdate {
inner: wysiwyg::ComposerUpdate<Utf16String>,
}
Expand All @@ -12,7 +13,10 @@ impl ComposerUpdate {
pub fn from(inner: wysiwyg::ComposerUpdate<Utf16String>) -> Self {
Self { inner }
}
}

#[uniffi::export]
impl ComposerUpdate {
pub fn text_update(&self) -> TextUpdate {
TextUpdate::from(self.inner.text_update.clone())
}
Expand Down
2 changes: 1 addition & 1 deletion bindings/wysiwyg-ffi/src/ffi_dom_creation_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use std::fmt::Display;

#[derive(Debug)]
#[derive(Debug, uniffi::Error)]
pub enum DomCreationError {
HtmlParseError,
MarkdownParseError,
Expand Down
1 change: 1 addition & 0 deletions bindings/wysiwyg-ffi/src/ffi_link_actions.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use widestring::Utf16String;

#[derive(uniffi::Enum)]
pub enum LinkAction {
CreateWithText,
Create,
Expand Down
2 changes: 1 addition & 1 deletion bindings/wysiwyg-ffi/src/ffi_menu_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use crate::SuggestionPattern;

#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, uniffi::Enum)]
pub enum MenuAction {
Keep,
None,
Expand Down
2 changes: 1 addition & 1 deletion bindings/wysiwyg-ffi/src/ffi_menu_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::collections::HashMap;
use crate::into_ffi::IntoFfi;
use crate::{ActionState, ComposerAction};

#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, uniffi::Enum)]
pub enum MenuState {
Keep,
Update {
Expand Down
2 changes: 1 addition & 1 deletion bindings/wysiwyg-ffi/src/ffi_pattern_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, uniffi::Enum)]
pub enum PatternKey {
At,
Hash,
Expand Down
2 changes: 1 addition & 1 deletion bindings/wysiwyg-ffi/src/ffi_suggestion_pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use crate::PatternKey;

#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, uniffi::Record)]
pub struct SuggestionPattern {
pub key: PatternKey,
pub text: String,
Expand Down
1 change: 1 addition & 0 deletions bindings/wysiwyg-ffi/src/ffi_text_update.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use widestring::Utf16String;

#[derive(uniffi::Enum)]
pub enum TextUpdate {
Keep,
ReplaceAll {
Expand Down
1 change: 1 addition & 0 deletions bindings/wysiwyg-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub use crate::ffi_pattern_key::PatternKey;
pub use crate::ffi_suggestion_pattern::SuggestionPattern;
pub use crate::ffi_text_update::TextUpdate;

#[uniffi::export]
pub fn new_composer_model() -> Arc<ComposerModel> {
Arc::new(ComposerModel::new())
}
153 changes: 1 addition & 152 deletions bindings/wysiwyg-ffi/src/wysiwyg_composer.udl
Original file line number Diff line number Diff line change
Expand Up @@ -12,155 +12,4 @@
// See the License for the specific language governing permissions and
// limitations under the License.

namespace wysiwyg_composer {
ComposerModel new_composer_model();
};

interface ComposerModel {
[Throws=DomCreationError]
ComposerUpdate set_content_from_html(string html);
[Throws=DomCreationError]
ComposerUpdate set_content_from_markdown(string markdown);
string get_content_as_html();
string get_content_as_message_html();
string get_content_as_markdown();
string get_content_as_message_markdown();
string get_content_as_plain_text();
ComposerUpdate clear();
ComposerUpdate select(u32 start_utf16_codeunit, u32 end_utf16_codeunit);
ComposerUpdate replace_text(string new_text);
ComposerUpdate replace_text_in(string new_text, u32 start, u32 end);
ComposerUpdate replace_text_suggestion(string new_text, SuggestionPattern suggestion);
ComposerUpdate backspace();
ComposerUpdate delete();
ComposerUpdate delete_in(u32 start, u32 end);
ComposerUpdate enter();
ComposerUpdate bold();
ComposerUpdate italic();
ComposerUpdate strike_through();
ComposerUpdate underline();
ComposerUpdate inline_code();
ComposerUpdate ordered_list();
ComposerUpdate unordered_list();
ComposerUpdate undo();
ComposerUpdate redo();
ComposerUpdate indent();
ComposerUpdate unindent();
ComposerUpdate set_link(string url, sequence<Attribute> attributes);
ComposerUpdate set_link_with_text(string url, string text, sequence<Attribute> attributes);
ComposerUpdate remove_links();
ComposerUpdate insert_at_room_mention();
ComposerUpdate insert_mention(string url, string text, sequence<Attribute> attributes);
ComposerUpdate insert_at_room_mention_at_suggestion(SuggestionPattern suggestion);
ComposerUpdate insert_mention_at_suggestion(string url, string text, SuggestionPattern suggestion, sequence<Attribute> attributes);
ComposerUpdate code_block();
ComposerUpdate quote();
void debug_panic();
string to_tree();
string to_example_format();
ComposerState get_current_dom_state();
record<ComposerAction, ActionState> action_states();
LinkAction get_link_action();
};

dictionary Attribute {
string key;
string value;
};

interface ComposerUpdate {
TextUpdate text_update();
MenuState menu_state();
MenuAction menu_action();
};

dictionary ComposerState {
sequence<u16> html;
u32 start;
u32 end;
};

[Enum]
interface TextUpdate {
Keep();
ReplaceAll(
sequence<u16> replacement_html,
u32 start_utf16_codeunit,
u32 end_utf16_codeunit
);
Select(
u32 start_utf16_codeunit,
u32 end_utf16_codeunit
);
};

enum ComposerAction {
"Bold",
"Italic",
"StrikeThrough",
"Underline",
"InlineCode",
"Link",
"Undo",
"Redo",
"OrderedList",
"UnorderedList",
"Indent",
"Unindent",
"CodeBlock",
"Quote",
};

enum ActionState {
"Enabled",
"Reversed",
"Disabled",
};

[Enum]
interface MenuState {
Keep();
Update(
record<ComposerAction, ActionState> action_states
);
};

[Enum]
interface MenuAction {
Keep();
None();
Suggestion(
SuggestionPattern suggestion_pattern
);
};

dictionary SuggestionPattern {
PatternKey key;
string text;
u32 start;
u32 end;
};

enum PatternKey {
"At",
"Hash",
"Slash",
};

[Enum]
interface LinkAction {
CreateWithText();
Create();
Edit(
string url
);
Disabled();
};

[Error]
enum DomCreationError {
"MarkdownParseError",
"HtmlParseError",
};


namespace wysiwyg_composer {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

3 changes: 1 addition & 2 deletions build_xcframework.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

GENERATION_PATH=.generated/ios

UDL_FILE_PATH=bindings/wysiwyg-ffi/src/wysiwyg_composer.udl
UNIFFI_CONFIG_FILE_PATH=bindings/wysiwyg-ffi/uniffi.toml

ARM64_LIB_PATH=target/aarch64-apple-ios/release/libuniffi_wysiwyg_composer.a
Expand Down Expand Up @@ -42,7 +41,7 @@ rm -rf $GENERATION_PATH

# Generate headers & Swift bindings
mkdir -p $GENERATION_PATH
cargo uniffi-bindgen generate $UDL_FILE_PATH -l swift --config $UNIFFI_CONFIG_FILE_PATH --out-dir $GENERATION_PATH
cargo uniffi-bindgen generate --library $ARM64_LIB_PATH -l swift --out-dir $GENERATION_PATH

# Move Swift file to expected location
#
Expand Down
4 changes: 3 additions & 1 deletion platforms/android/library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ dependencies {
android.libraryVariants.all { variant ->
def generateBindingTasks = tasks.register("generate${variant.name.capitalize()}UniFFIBindings", Exec) {
workingDir "${project.projectDir}"
commandLine 'cargo', 'uniffi-bindgen', 'generate', '../../../bindings/wysiwyg-ffi/src/wysiwyg_composer.udl', '--language', 'kotlin', '--out-dir', "${buildDir}/generated/source/uniffi/${variant.name}/java"
// Note: arbitrary using the first target directory, but any of the dylib could be used.
def targetDir = project.tasks.withType(com.nishtahir.CargoBuildTask).first().toolchain.folder
commandLine 'cargo', 'uniffi-bindgen', 'generate', '--library', "${buildDir}/rustJniLibs/${targetDir}/libuniffi_wysiwyg_composer.so", '--language', 'kotlin', '--out-dir', "${buildDir}/generated/source/uniffi/${variant.name}/java"
dependsOn("cargoBuild")
}
tasks.preBuild.dependsOn(generateBindingTasks)
Expand Down
Loading