Skip to content

Commit

Permalink
Merge branch 'master' into feat/11899
Browse files Browse the repository at this point in the history
  • Loading branch information
fzyzcjy authored Mar 7, 2024
2 parents f4e068a + 9d95041 commit 18554f2
Show file tree
Hide file tree
Showing 109 changed files with 3,591 additions and 452 deletions.
40 changes: 20 additions & 20 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ on:
push:
branches:
- master
pull_request: {}
workflow_dispatch: {}
pull_request: { }
workflow_dispatch: { }

env:
CARGO_TERM_COLOR: always
FRB_MAIN_RUST_VERSION: 1.74.0
FRB_MAIN_DART_VERSION: 3.2.0
FRB_MAIN_FLUTTER_VERSION: 3.16.0
FRB_MAIN_DART_VERSION: 3.3.0
FRB_MAIN_FLUTTER_VERSION: 3.19.2

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
Expand Down Expand Up @@ -147,7 +147,7 @@ jobs:
# we avoid a ci dependency to cargo-msrv.
# However, the code is left commented here in case this decission changes.
# msrv:
# name: 'Test :: FRB Codegen :: MSRV'
# name: 'Test :: FRB Codegen :: MSRV'
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
Expand Down Expand Up @@ -187,10 +187,10 @@ jobs:
- frb_example--flutter_via_create
- frb_example--flutter_via_integrate
exclude:
- {image: windows-2019, package: frb_example--deliberate_bad}
- {image: macos-11, package: frb_example--deliberate_bad}
- {image: windows-2019, package: frb_example--flutter_via_integrate}
- {image: macos-11, package: frb_example--flutter_via_integrate}
- { image: windows-2019, package: frb_example--deliberate_bad }
- { image: macos-11, package: frb_example--deliberate_bad }
- { image: windows-2019, package: frb_example--flutter_via_integrate }
- { image: macos-11, package: frb_example--flutter_via_integrate }

steps:
# setup
Expand All @@ -210,7 +210,7 @@ jobs:
flutter-version: ${{ env.FRB_MAIN_FLUTTER_VERSION }}
architecture: x64
- uses: taiki-e/install-action@cargo-llvm-cov

# execute
- run: ./frb_internal generate-run-frb-codegen-command-generate --set-exit-if-changed --package ${{ matrix.package }} --coverage

Expand Down Expand Up @@ -530,7 +530,7 @@ jobs:
# tests the MSRV
# run on all rust packages, though only needed for frb_rust and frb_codegen
- image: ubuntu-latest
# update this, if a later MSRV is needed
# update this, if a later MSRV is needed
version: 1.74.0

steps:
Expand Down Expand Up @@ -559,8 +559,8 @@ jobs:
- uses: actions/upload-artifact@v4
with:
name: ${{ github.job }}--${{ matrix.info.image }}--${{ matrix.info.version }}--coverage
path: target/coverage
path: target/coverage

test_dart_native:
name: 'Test :: Dart :: Native'
runs-on: ${{ matrix.image }}
Expand All @@ -581,12 +581,12 @@ jobs:
- frb_example--dart_build_rs
- frb_example--deliberate_bad
exclude:
- {image: windows-2019, package: frb_utils}
- {image: macos-11, package: frb_utils}
- {image: windows-2019, package: tools--frb_internal}
- {image: macos-11, package: tools--frb_internal}
- {image: windows-2019, package: frb_example--deliberate_bad}
- {image: macos-11, package: frb_example--deliberate_bad}
- { image: windows-2019, package: frb_utils }
- { image: macos-11, package: frb_utils }
- { image: windows-2019, package: tools--frb_internal }
- { image: macos-11, package: tools--frb_internal }
- { image: windows-2019, package: frb_example--deliberate_bad }
- { image: macos-11, package: frb_example--deliberate_bad }

steps:
# setup
Expand Down Expand Up @@ -756,7 +756,7 @@ jobs:
device:
- "pixel"
- "Nexus 6"
api-level: [29]
api-level: [ 29 ]

steps:
# setup
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/post_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
name: Post-Release

on:
workflow_dispatch: {}
workflow_dispatch: { }
schedule:
- cron: "0,30 * * * *"

env:
CARGO_TERM_COLOR: always
FRB_MAIN_RUST_VERSION: 1.74.0
FRB_MAIN_DART_VERSION: 3.2.0
FRB_MAIN_FLUTTER_VERSION: 3.16.0
FRB_MAIN_DART_VERSION: 3.3.0
FRB_MAIN_FLUTTER_VERSION: 3.19.2

jobs:
test_mimic_quickstart:
Expand All @@ -33,10 +33,10 @@ jobs:
# - scoop # TODO enable after 2.0.0 stable release
# - homebrew # TODO enable after 2.0.0 stable release
exclude:
- {image: windows-2019, codegen_install_mode: homebrew}
- {image: macos-11, codegen_install_mode: scoop}
- {image: ubuntu-20.04, codegen_install_mode: homebrew}
- {image: ubuntu-20.04, codegen_install_mode: scoop}
- { image: windows-2019, codegen_install_mode: homebrew }
- { image: macos-11, codegen_install_mode: scoop }
- { image: ubuntu-20.04, codegen_install_mode: homebrew }
- { image: ubuntu-20.04, codegen_install_mode: scoop }

steps:
# setup
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
* Please refer to https://fzyzcjy.github.io/flutter_rust_bridge/guides/miscellaneous/whats-new for what's changed in V2.
* Allow specifying pubspec.yaml location in build.rs #1797 (thanks @HalidOdat)
* Hint how to only run build.rs if api directory changes #1794 (thanks @HalidOdat)
* Improve procedure macros #1800 #1676 (thanks @Desdaemon)
* Add support for ffigen upgrades #1799 #1757 (thanks @aran)
* Improve hints when structs are in lib.rs #1802 #1579 (thanks @h3x4d3c1m4l)
* Improve scenarios when opaque-by-default is more natural #1805
* Improve behavior of constructor #1804
* Fix when using non-opaque struct + option + opaque inner type #1803

## 2.0.0-dev.25

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version: 0.0.1
publish_to: none

environment:
sdk: '>=3.2.0 <4.0.0'
sdk: '>=3.3.0 <4.0.0'
flutter: '>=3.3.0'

dependencies:
Expand All @@ -14,7 +14,7 @@ dependencies:

dev_dependencies:
ffi: ^2.0.2
ffigen: ^9.0.0
ffigen: ^11.0.0
flutter_test:
sdk: flutter
flutter_lints: ^2.0.0
Expand Down
6 changes: 5 additions & 1 deletion frb_codegen/src/library/codegen/dumper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ use crate::codegen::generator::misc::target::TargetOrCommon;
use crate::codegen::generator::misc::PathTexts;
use crate::utils::file_utils::create_dir_all_and_write;
use crate::utils::path_utils::path_to_string;
use anyhow::Context;
use convert_case::{Case, Casing};
use log::debug;
use pathdiff::diff_paths;
use serde::Serialize;
use std::path::Path;
use strum::IntoEnumIterator;
Expand Down Expand Up @@ -44,7 +46,9 @@ impl Dumper<'_> {
content,
&format!(
"{partial_name}/{}",
path_to_string(path_text.path.strip_prefix(base_dir)?)?
path_to_string(
&diff_paths(&path_text.path, base_dir).context("cannot diff path")?
)?
),
&path_text.text,
)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ fn generate_signature(
&ApiDartGenerator::new(func.output.clone(), context).dart_api_type(),
);
let method_name = if default_constructor_mode.is_some() {
format!("newInstance")
"newInstance".to_owned()
} else {
method_info.actual_method_name.to_case(Case::Camel)
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,14 @@ impl<'a> ApiDartGeneratorClassTrait for StructRefApiDartGenerator<'a> {
Some(ApiDartGeneratedClass {
namespace: src.name.namespace.clone(),
code: if src.using_freezed() {
self.generate_mode_freezed(
src,
&comments,
&metadata,
&methods,
&constructor_postfix,
)
self.generate_mode_freezed(src, &comments, &metadata, &methods, constructor_postfix)
} else {
self.generate_mode_non_freezed(
src,
&comments,
&metadata,
&methods,
&constructor_postfix,
constructor_postfix,
)
},
needs_freezed: src.using_freezed(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::codegen::generator::api_dart::spec_generator::{
use crate::codegen::generator::misc::{generate_code_header, PathText, PathTexts};
use crate::codegen::ir::namespace::Namespace;
use crate::utils::basic_code::DartBasicHeaderCode;
use anyhow::ensure;
use itertools::Itertools;
use std::path::{Path, PathBuf};

Expand All @@ -23,10 +24,10 @@ pub(super) fn generate(
.map(|(namespace, item)| {
let dart_output_path =
compute_path_from_namespace(&config.dart_decl_base_output_path, namespace);
let text = generate_end_api_text(namespace, &dart_output_path, item);
PathText::new(dart_output_path, text)
let text = generate_end_api_text(namespace, &dart_output_path, item)?;
Ok(PathText::new(dart_output_path, text))
})
.collect_vec(),
.collect::<anyhow::Result<Vec<_>>>()?,
);

Ok(ApiDartOutputText {
Expand All @@ -38,7 +39,7 @@ fn generate_end_api_text(
namespace: &Namespace,
dart_output_path: &Path,
item: &ApiDartOutputSpecItem,
) -> String {
) -> anyhow::Result<String> {
let funcs = item
.funcs
.iter()
Expand All @@ -47,8 +48,16 @@ fn generate_end_api_text(
.join("\n\n");
let classes = item.classes.iter().map(|c| c.code.clone()).join("\n\n");

let path_chunks_len = namespace.path().len();
ensure!(
path_chunks_len >= 2,
// This will stop the whole generator and tell the users, so we do not care about testing it
// frb-coverage:ignore-start
"Please do not put structs in `lib.rs`",
// frb-coverage:ignore-end
);
// TODO use relative path calculation
let path_frb_generated = "../".repeat(namespace.path().len() - 2) + "frb_generated.dart";
let path_frb_generated = "../".repeat(path_chunks_len - 2) + "frb_generated.dart";

let mut header = DartBasicHeaderCode {
file_top: generate_code_header()
Expand Down Expand Up @@ -94,7 +103,7 @@ fn generate_end_api_text(
})
.join("");

format!(
Ok(format!(
"
{header}
Expand All @@ -104,7 +113,7 @@ fn generate_end_api_text(
{classes}
",
)
))
}

fn generate_function(func: &ApiDartGeneratedFunction) -> String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl<'a> WireDartCodecCstGeneratorEncoderTrait for BoxedWireDartCodecCstGenerato
if self.ir.inner.is_primitive()
|| matches!(
*self.ir.inner,
IrType::RustOpaque(_) | IrType::DartOpaque(_)
IrType::RustOpaque(_) | IrType::RustAutoOpaque(_) | IrType::DartOpaque(_)
)
{
format!(
Expand Down Expand Up @@ -52,7 +52,7 @@ impl<'a> WireDartCodecCstGeneratorEncoderTrait for BoxedWireDartCodecCstGenerato
} else if !self.ir.inner.is_primitive()
&& !matches!(
*self.ir.inner,
IrType::RustOpaque(_) | IrType::DartOpaque(_)
IrType::RustOpaque(_) | IrType::RustAutoOpaque(_) | IrType::DartOpaque(_)
)
&& !is_empty_struct(self)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ impl<'a> WireDartCodecDcoGeneratorDecoderTrait for BoxedWireDartCodecDcoGenerato
StructRef(_)
| DartOpaque(_)
| RustOpaque(_)
| RustAutoOpaque(_)
| EnumRef(_)
| Primitive(IrTypePrimitive::I64 | IrTypePrimitive::U64 | IrTypePrimitive::Usize)
| Delegate(IrTypeDelegate::Array(_) | IrTypeDelegate::PrimitiveEnum { .. }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl<'a> WireRustCodecCstGeneratorDecoderTrait for BoxedWireRustCodecCstGenerato
if self.ir.inner.is_primitive()
|| matches!(
*self.ir.inner,
IrType::RustOpaque(_) | IrType::DartOpaque(_)
IrType::RustOpaque(_) | IrType::RustAutoOpaque(_) | IrType::DartOpaque(_)
)
{
Acc {
Expand Down
6 changes: 6 additions & 0 deletions frb_codegen/src/library/codegen/ir/ty/rust_auto_opaque.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use super::rust_opaque::RUST_OPAQUE_AS_PRIMITIVE;
use crate::codegen::ir::namespace::Namespace;
use crate::codegen::ir::ty::primitive::IrTypePrimitive;
use crate::codegen::ir::ty::rust_opaque::{IrTypeRustOpaque, NameComponent};
use crate::codegen::ir::ty::{IrContext, IrType, IrTypeTrait};
use serde::Serialize;
Expand Down Expand Up @@ -51,6 +53,10 @@ impl IrTypeTrait for IrTypeRustAutoOpaque {
fn self_namespace(&self) -> Option<Namespace> {
Some(self.inner.namespace.clone())
}

fn as_primitive(&self) -> Option<&IrTypePrimitive> {
Some(&RUST_OPAQUE_AS_PRIMITIVE)
}
}

impl IrTypeRustAutoOpaque {
Expand Down
4 changes: 3 additions & 1 deletion frb_codegen/src/library/codegen/ir/ty/rust_opaque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,12 @@ impl IrTypeTrait for IrTypeRustOpaque {

// Because we are using usize on the wirre
fn as_primitive(&self) -> Option<&IrTypePrimitive> {
Some(&IrTypePrimitive::Usize)
Some(&RUST_OPAQUE_AS_PRIMITIVE)
}
}

pub(super) const RUST_OPAQUE_AS_PRIMITIVE: IrTypePrimitive = IrTypePrimitive::Usize;

impl IrRustOpaqueInner {
pub(crate) fn safe_ident(&self) -> String {
lazy_static! {
Expand Down
3 changes: 1 addition & 2 deletions frb_codegen/src/library/commands/ensure_tools_available.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use std::path::Path;
use std::str::FromStr;

lazy_static! {
pub(crate) static ref FFIGEN_REQUIREMENT: VersionReq =
VersionReq::parse(">= 8.0.0, < 10.0.0").unwrap();
pub(crate) static ref FFIGEN_REQUIREMENT: VersionReq = VersionReq::parse(">= 8.0.0").unwrap();
}

pub fn ensure_tools_available(
Expand Down
5 changes: 5 additions & 0 deletions frb_codegen/src/library/commands/ffigen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ fn parse_config(args: &FfigenToFileArgs) -> FfigenCommandConfig {
functions: FfigenCommandConfigFunctions {
rename: args.function_rename.cloned(),
},
// Otherwise, e.g. on MacOS, we see a ton of warnings like:
// `/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/stdlib.h:239:6: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [Nullability Issue]`
// Indeed, we have our own sanity checks to detect errors.
ignore_source_errors: true,
}
}

Expand All @@ -185,6 +189,7 @@ pub(crate) struct FfigenCommandConfig {
pub llvm_path: Vec<PathBuf>,
pub compiler_opts: Vec<String>,
pub functions: FfigenCommandConfigFunctions,
pub ignore_source_errors: bool,
}

#[derive(Default, Clone, Serialize, Deserialize)]
Expand Down
2 changes: 2 additions & 0 deletions frb_codegen/src/library/internal/frb_dart_source_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ fn ffigen(repo_base_dir: &Path) -> anyhow::Result<()> {
format!("-I{}", &path_to_string(&dir_dart_api)?),
format!("-I{}", &path_to_string(&dir_intermediate)?),
],
// same reason as is discussed in ffigen.rs
ignore_source_errors: true,
..Default::default()
},
&repo_base_dir.join("frb_dart"),
Expand Down
Loading

0 comments on commit 18554f2

Please sign in to comment.