Skip to content
This repository has been archived by the owner on Dec 4, 2023. It is now read-only.

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MeerKatDev committed Oct 26, 2023
1 parent 3116377 commit 0d39d41
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 15 deletions.
3 changes: 3 additions & 0 deletions uniffi_bindgen/src/bindings/kotlin/gen_kotlin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ impl Config {
}
}
}
use crate::Utf8Path;

impl BindingsConfig for Config {
fn update_documentation(&mut self, _ci: &mut ComponentInterface, _udl_file: &Utf8Path) -> Result<()> { Ok(()) }

fn update_from_ci(&mut self, ci: &ComponentInterface) {
self.package_name
.get_or_insert_with(|| format!("uniffi.{}", ci.namespace()));
Expand Down
1 change: 1 addition & 0 deletions uniffi_bindgen/src/bindings/kotlin/templates/Interface.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
public interface {{ interface_name }} {
{% for meth in methods.iter() -%}
{%- let func = meth -%}
{%- include "FunctionDocsTemplate.kt" -%}
{% if meth.is_async() -%}suspend {% endif -%}
fun {{ meth.name()|fn_name }}({% call kt::arg_list_decl(meth) %})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class {{ impl_class_name }}(
{% if !obj.alternate_constructors().is_empty() -%}
companion object {
{% for cons in obj.alternate_constructors() -%}
{%- let func = cons -%}
{%- include "FunctionDocsTemplate.kt" %}
fun {{ cons.name()|fn_name }}({% call kt::arg_list_decl(cons) %}): {{ impl_class_name }} =
{{ impl_class_name }}({% call kt::to_ffi_call(cons) %})
Expand Down
3 changes: 3 additions & 0 deletions uniffi_bindgen/src/bindings/python/gen_python/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,11 @@ impl Config {
}
}
}
use crate::Utf8Path;

impl BindingsConfig for Config {
fn update_documentation(&mut self, _ci: &mut ComponentInterface, _udl_file: &Utf8Path) -> Result<()> { Ok(()) }

fn update_from_ci(&mut self, ci: &ComponentInterface) {
self.cdylib_name
.get_or_insert_with(|| format!("uniffi_{}", ci.namespace()));
Expand Down
4 changes: 4 additions & 0 deletions uniffi_bindgen/src/bindings/ruby/gen_ruby/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ impl Config {
}
}

use crate::Utf8Path;

impl BindingsConfig for Config {
fn update_documentation(&mut self, _ci: &mut ComponentInterface, _udl_file: &Utf8Path) -> Result<()> { Ok(()) }

fn update_from_ci(&mut self, ci: &ComponentInterface) {
self.cdylib_name
.get_or_insert_with(|| format!("uniffi_{}", ci.namespace()));
Expand Down
4 changes: 4 additions & 0 deletions uniffi_bindgen/src/bindings/swift/gen_swift/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,11 @@ impl Config {
}
}

use crate::Utf8Path;

impl BindingsConfig for Config {
fn update_documentation(&mut self, _ci: &mut ComponentInterface, _udl_file: &Utf8Path) -> Result<()> { Ok(()) }

fn update_from_ci(&mut self, ci: &ComponentInterface) {
self.module_name
.get_or_insert_with(|| ci.namespace().into());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class {{ impl_class_name }}: {{ protocol_name }} {
}

{% for cons in obj.alternate_constructors() %}

{%- let func = cons -%}
{%- include "FunctionDocsTemplate.swift" %}
public static func {{ cons.name()|fn_name }}({% call swift::arg_list_decl(cons) %}) {% call swift::throws(cons) %} -> {{ impl_class_name }} {
return {{ impl_class_name }}(unsafeFromRawPointer: {% call swift::to_ffi_call(cons) %})
Expand Down
19 changes: 10 additions & 9 deletions uniffi_bindgen/src/bindings/swift/templates/Protocol.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
public protocol {{ protocol_name }}: AnyObject {
{ % for meth in methods.iter() -% }
{ %- include "FunctionDocsTemplate.swift" % }
func {{ meth.name() | fn_name }}({ % call swift:: arg_list_protocol(meth) % }) { % call swift:: async(meth) -% } { % call swift:: throws (meth) -% }
{ %- match meth.return_type() -% }
{ %- when Some with(return_type) % } -> {{ return_type | type_name - }}
{ %- else -% }
{ %- endmatch % }
{ % endfor % }
public protocol {{ protocol_name }} : AnyObject {
{% for meth in methods.iter() -%}
{%- let func = meth -%}
{%- include "FunctionDocsTemplate.swift" %}
func {{ meth.name()|fn_name }}({% call swift::arg_list_protocol(meth) %}) {% call swift::async(meth) -%}{% call swift::throws(meth) -%}
{%- match meth.return_type() -%}
{%- when Some with (return_type) %} -> {{ return_type|type_name -}}
{%- else -%}
{%- endmatch %}
{% endfor %}
}
19 changes: 14 additions & 5 deletions uniffi_bindgen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ use scaffolding::RustScaffolding;
/// BindingsConfigs are initially loaded from `uniffi.toml` file. Then the trait methods are used
/// to fill in missing values.
pub trait BindingsConfig: DeserializeOwned {
/// attaches documentation if set to do so
fn update_documentation(&mut self, ci: &mut ComponentInterface, udl_file: &Utf8Path) -> Result<()>;

/// Update missing values using the `ComponentInterface`
fn update_from_ci(&mut self, ci: &ComponentInterface);

Expand All @@ -136,6 +139,7 @@ pub trait BindingsConfig: DeserializeOwned {
pub struct EmptyBindingsConfig;

impl BindingsConfig for EmptyBindingsConfig {
fn update_documentation(&mut self, ci: &mut ComponentInterface, udl_file: &Utf8Path) -> Result<()> { Ok(()) }
fn update_from_ci(&mut self, _ci: &ComponentInterface) {}
fn update_from_cdylib_name(&mut self, _cdylib_name: &str) {}
fn update_from_dependency_configs(&mut self, _config_map: HashMap<&str, &Self>) {}
Expand Down Expand Up @@ -241,11 +245,7 @@ pub fn generate_external_bindings<T: BindingGenerator>(
let mut config = load_initial_config::<T::Config>(crate_root, config_file_override)?;
config.update_from_ci(&component);

if config.bindings.doc_comments.unwrap_or_default() {
let path = udl_file.with_file_name("lib.rs");
let documentation = uniffi_docs::extract_documentation_from_path(path)?;
component.attach_documentation(documentation);
};
let _ = config.update_documentation(&mut component, udl_file.as_ref())?;

if let Some(ref library_file) = library_file {
if let Some(cdylib_name) = crate::library_mode::calc_cdylib_name(library_file.as_ref())
Expand Down Expand Up @@ -449,6 +449,15 @@ pub struct Config {
}

impl BindingsConfig for Config {
fn update_documentation(&mut self, ci: &mut ComponentInterface, udl_file: &Utf8Path) -> Result<()> {
if self.bindings.doc_comments.unwrap_or_default() {
let path = udl_file.with_file_name("lib.rs");
let documentation = uniffi_docs::extract_documentation_from_path(path)?;
ci.attach_documentation(documentation);
}
Ok(())
}

fn update_from_ci(&mut self, ci: &ComponentInterface) {
self.bindings.kotlin.update_from_ci(ci);
self.bindings.swift.update_from_ci(ci);
Expand Down

0 comments on commit 0d39d41

Please sign in to comment.