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

Generate docs when using library mode #10

Closed
wants to merge 13 commits into from
Closed
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ xcuserdata
docs/manual/src/internals/api
examples/app/ios/Generated
examples/app/ios/IOSApp.xcodeproj/project.xcworkspace/xcshareddata/
.direnv
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docker/cargo-docker.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

# Key points for these cmd-line args:
# * run a transient image that deletes itself on successful completion
Expand Down
4 changes: 4 additions & 0 deletions uniffi_bindgen/src/bindings/kotlin/templates/ErrorTemplate.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
{%- let canonical_type_name = type_|error_canonical_name %}

{% if e.is_flat() %}
{% let struct = e %}{% include "StructureDocsTemplate.kt" %}
sealed class {{ type_name }}(message: String): Exception(message){% if contains_object_references %}, Disposable {% endif %} {
// Each variant is a nested class
// Flat enums carries a string error message, so no special implementation is necessary.
{% for variant in e.variants() -%}
{% include "EnumVariantDocsTemplate.kt" %}
class {{ variant|error_variant|type_name }}(message: String) : {{ type_name }}(message)
{% endfor %}

Expand All @@ -15,9 +17,11 @@ sealed class {{ type_name }}(message: String): Exception(message){% if contains_
}
}
{%- else %}
{% let struct = e %}{% include "StructureDocsTemplate.kt" %}
sealed class {{ type_name }}: Exception(){% if contains_object_references %}, Disposable {% endif %} {
// Each variant is a nested class
{% for variant in e.variants() -%}
{% include "EnumVariantDocsTemplate.kt" %}
{%- let variant_name = variant|error_variant|type_name %}
class {{ variant_name }}(
{% for field in variant.fields() -%}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{%- let (interface_name, impl_class_name) = obj|object_names %}
{%- let methods = obj.methods() %}

{% let struct = obj %}{% include "StructureDocsTemplate.kt" %}
{% include "Interface.kt" %}

class {{ impl_class_name }}(
Expand Down Expand Up @@ -33,6 +34,8 @@ class {{ impl_class_name }}(
}

{% for meth in obj.methods() -%}
{%- let func = meth -%}
{%- include "FunctionDocsTemplate.kt" -%}
{%- match meth.throws_type() -%}
{%- when Some with (throwable) %}
@Throws({{ throwable|error_type_name }}::class)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% match variant.documentation() -%}
{% when Some with (docs) %}"""
{% when Some with (docs) %}"""
{% for line in docs.lines() %} {{ line }}
{% endfor %} """
{%- when None %}
{%- endmatch %}
{%- when None %}
{%- endmatch %}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ class {{ type_name }}(Exception):

_UniffiTemp{{ type_name }} = {{ type_name }}

class {{ type_name }}: # type: ignore
class {{ type_name }}: # type: ignore{% let struct = e %}{% include "StructureDocsTemplate.py" %}
{%- for variant in e.variants() -%}
{%- let variant_type_name = variant.name()|class_name -%}
{%- if e.is_flat() %}
class {{ variant_type_name }}(_UniffiTemp{{ type_name }}):
{% include "ErrorVariantDocsTemplate.py" %}
def __repr__(self):
return "{{ type_name }}.{{ variant_type_name }}({})".format(repr(str(self)))
{%- else %}
class {{ variant_type_name }}(_UniffiTemp{{ type_name }}):
{% include "ErrorVariantDocsTemplate.py" %}
def __init__(self{% for field in variant.fields() %}, {{ field.name()|var_name }}{% endfor %}):
{%- if variant.has_fields() %}
super().__init__(", ".join([
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% match variant.documentation() -%}
{% when Some with (docs) %}"""
{% for line in docs.lines() %} {{ line }}
{% endfor %} """
{%- when None %}
{%- endmatch %}
6 changes: 6 additions & 0 deletions uniffi_bindgen/src/bindings/python/templates/macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@
{% if meth.is_async() %}

def {{ py_method_name }}(self, {% call arg_list_decl(meth) %}):
{%- let func = meth -%}
{% include "MethodDocsTemplate.py" %}
{%- call setup_args_extra_indent(meth) %}
return _uniffi_rust_call_async(
_UniffiLib.{{ meth.ffi_func().name() }}(
Expand Down Expand Up @@ -131,6 +133,8 @@ def {{ py_method_name }}(self, {% call arg_list_decl(meth) %}):
{%- when Some with (return_type) %}

def {{ py_method_name }}(self, {% call arg_list_decl(meth) %}) -> "{{ return_type|type_name }}":
{%- let func = meth -%}
{% include "MethodDocsTemplate.py" %}
{%- call setup_args_extra_indent(meth) %}
return {{ return_type|lift_fn }}(
{% call to_ffi_call_with_prefix("self._pointer", meth) %}
Expand All @@ -139,6 +143,8 @@ def {{ py_method_name }}(self, {% call arg_list_decl(meth) %}) -> "{{ return_typ
{%- when None %}

def {{ py_method_name }}(self, {% call arg_list_decl(meth) %}):
{%- let func = meth -%}
{% include "MethodDocsTemplate.py" %}
{%- call setup_args_extra_indent(meth) %}
{% call to_ffi_call_with_prefix("self._pointer", meth) %}
{% endmatch %}
Expand Down
3 changes: 3 additions & 0 deletions uniffi_bindgen/src/bindings/ruby/templates/ErrorTemplate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ def to_s
{%- for e in ci.enum_definitions() %}
{% if ci.is_name_used_as_error(e.name()) %}
{% if e.is_flat() %}
{% include "EnumDocsTemplate.rb" -%}
class {{ e.name()|class_name_rb }}
{%- for variant in e.variants() %}
{% include "EnumVariantDocsTemplate.rb" -%}
{{ variant.name()|class_name_rb }} = Class.new StandardError
{%- endfor %}
{% else %}
module {{ e.name()|class_name_rb }}
{%- for variant in e.variants() %}
{% include "EnumVariantDocsTemplate.rb" -%}
class {{ variant.name()|class_name_rb }} < StandardError
def initialize({% for field in variant.fields() %}{{ field.name()|var_name_rb }}{% if !loop.last %}, {% endif %}{% endfor %})
{%- for field in variant.fields() %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{% let struct = e %}{% include "StructureDocsTemplate.swift" %}
public enum {{ type_name }} {

{% if e.is_flat() %}
{% for variant in e.variants() %}
{% include "EnumVariantDocsTemplate.swift" %}
// Simple error enums only carry a message
case {{ variant.name()|class_name }}(message: String)
{% endfor %}

{%- else %}
{% for variant in e.variants() %}
{% include "EnumVariantDocsTemplate.swift" %}
Copy link
Member

Choose a reason for hiding this comment

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

thank you!

case {{ variant.name()|class_name }}{% if variant.fields().len() > 0 %}({% call swift::field_list_decl(variant) %}){% endif -%}
{% endfor %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{%- let (protocol_name, impl_class_name) = obj|object_names %}
{%- let methods = obj.methods() %}

{% let struct = obj %}{% include "StructureDocsTemplate.swift" %}
{% include "Protocol.swift" %}

public class {{ impl_class_name }}: {{ protocol_name }} {
Expand Down Expand Up @@ -41,6 +42,8 @@ public class {{ impl_class_name }}: {{ protocol_name }} {
{% for meth in obj.methods() -%}
{%- if meth.is_async() %}

{%- let func = meth -%}
{%- include "FunctionDocsTemplate.swift" %}
public func {{ meth.name()|fn_name }}({%- call swift::arg_list_decl(meth) -%}) async {% call swift::throws(meth) %}{% match meth.return_type() %}{% when Some with (return_type) %} -> {{ return_type|type_name }}{% when None %}{% endmatch %} {
return {% call swift::try(meth) %} await uniffiRustCallAsync(
rustFutureFunc: {
Expand Down
5 changes: 4 additions & 1 deletion uniffi_bindgen/src/library_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ pub fn generate_external_bindings<T: BindingGenerator>(
}
}

for source in sources.iter() {
for source in &mut sources {
// Assumes a lib.rs for the source package containing bindings
let path = &source.package.manifest_path.with_file_name("src/lib.rs");
source.config.update_documentation(&mut source.ci, path)?;
binding_generator.write_bindings(&source.ci, &source.config, out_dir)?;
}

Expand Down
Loading