Skip to content

Commit

Permalink
Merge branch 'fzyzcjy:master' into fixes-cfg-wasm-warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
patmuk authored Sep 29, 2024
2 parents a4c9444 + 0e7071f commit bb37ed7
Show file tree
Hide file tree
Showing 70 changed files with 2,492 additions and 2,069 deletions.
3 changes: 2 additions & 1 deletion .all-contributors-custom.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
- AlienKevin: Add flutter example for macOS. Add doc for Android NDK bug. Improve migration doc.
- alexthe2: Add Option Datetime. Add empty structs. Improve doc. Add `r#`. Fix mirror enum bug.
- Larpoux: Fix async generation. Update web-audio-api binding.
- patmuk: Set MSRV. Fail fast. Improve message. Support relative config. Improve multiple docs.
- banool: Fix pubspec parsing. Fix symbol-stripping doc.
- anlumo: Fix freezed + methods. Non-clone RustOpaque.
- temeddix: Fix broken CI. Custom num workers. Fix MacOS doc steps. Update doc. Make zero-copy defaultable.
Expand All @@ -38,7 +39,7 @@
- OfficialBoyfriend: Fix error display.
- wxitcode: Add org option. Support MacOS log. Fix a typo.
- Tienisto: Add mock init.
- patmuk: Set MSRV. Fail fast. Improve message. Improve multi docs.
- kyrias: Use portable atomic.
- Markus43: Fix folder removal.
- Krysl: Add preamble.
- w-ensink: Improve doc. Fix CI. Refactor. Add tests.
Expand Down
17 changes: 13 additions & 4 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,15 @@
"code"
]
},
{
"login": "patmuk",
"name": "Patrick Mukherjee",
"avatar_url": "https://avatars.githubusercontent.com/u/2045440?v=4",
"profile": "https://patrick.mukherjee.de",
"contributions": [
"code"
]
},
{
"login": "banool",
"name": "Daniel Porteous (dport)",
Expand Down Expand Up @@ -397,10 +406,10 @@
]
},
{
"login": "patmuk",
"name": "Patrick Mukherjee",
"avatar_url": "https://avatars.githubusercontent.com/u/2045440?v=4",
"profile": "https://patrick.mukherjee.de",
"login": "kyrias",
"name": "Johannes Löthberg",
"avatar_url": "https://avatars.githubusercontent.com/u/2285387?v=4",
"profile": "https://remmy.io",
"contributions": [
"code"
]
Expand Down
5 changes: 3 additions & 2 deletions Cargo.lock

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

28 changes: 16 additions & 12 deletions README.md

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions frb_codegen/src/binary/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ pub(crate) struct GenerateCommandArgsPrimary {
/// Dump all internal data. Same as `--dump` with all possible choices chosen.
#[arg(long)]
pub dump_all: bool,

/// List of cargo feature flags to enable when generating
#[arg(long)]
pub rust_features: Option<Vec<String>>,
}

#[derive(Debug, Args)]
Expand Down
1 change: 1 addition & 0 deletions frb_codegen/src/binary/commands_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ fn compute_codegen_config_from_naive_command_args(args: GenerateCommandArgsPrima
stop_on_error: positive_bool_arg(args.stop_on_error),
dump: args.dump,
dump_all: positive_bool_arg(args.dump_all),
rust_features: args.rust_features,
}
}

Expand Down
2 changes: 2 additions & 0 deletions frb_codegen/src/library/codegen/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub struct Config {
pub stop_on_error: Option<bool>,
pub dump: Option<Vec<ConfigDumpContent>>,
pub dump_all: Option<bool>,
pub rust_features: Option<Vec<String>>,
}

#[derive(Debug, Serialize, Deserialize, Default)]
Expand Down Expand Up @@ -93,4 +94,5 @@ generate_merge!(
stop_on_error,
dump,
dump_all,
rust_features,
);
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ mod rust_path_parser;

impl InternalConfig {
pub(crate) fn parse(config: &Config, meta_config: &MetaConfig) -> Result<Self> {
let base_dir = (config.base_dir.as_ref())
.filter(|s| !s.is_empty())
.map(PathBuf::from)
.unwrap_or(std::env::current_dir()?);
let base_dir = match config.base_dir.as_ref().map(std::fs::canonicalize) {
Some(Ok(path)) => path,
None | Some(Err(_)) => std::env::current_dir().expect("failed to get current dir"),
};
debug!("InternalConfig.parse base_dir={base_dir:?}");

let rust_input = (config.rust_input.clone())
Expand Down Expand Up @@ -108,6 +108,7 @@ impl InternalConfig {
rust_crate_dir: rust_crate_dir.clone(),
rust_input_namespace_pack: rust_input_namespace_pack.clone(),
third_party_crate_names,
rust_features: config.rust_features.clone(),
},
mir: ParserMirInternalConfig {
rust_input_namespace_pack: rust_input_namespace_pack.clone(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ pub(crate) struct ParserHirInternalConfig {
pub rust_input_namespace_pack: RustInputNamespacePack,
pub rust_crate_dir: PathBuf,
pub third_party_crate_names: Vec<CrateName>,
pub rust_features: Option<Vec<String>>,
}
1 change: 1 addition & 0 deletions frb_codegen/src/library/codegen/parser/hir/raw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub(crate) fn parse(
&config.rust_crate_dir,
(!crate_name.is_self_crate()).then_some(crate_name),
dumper,
config.rust_features.as_deref(),
)?,
})
})
Expand Down
1 change: 1 addition & 0 deletions frb_codegen/src/library/codegen/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ mod tests {
rust_input_namespace_pack: rust_input_namespace_pack.clone(),
rust_crate_dir: rust_crate_dir.clone(),
third_party_crate_names: vec![],
rust_features: None,
},
mir: ParserMirInternalConfig {
rust_input_namespace_pack: rust_input_namespace_pack.clone(),
Expand Down
3 changes: 2 additions & 1 deletion frb_codegen/src/library/commands/cargo_expand/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ pub(crate) fn run_cargo_expand(
rust_crate_dir: &Path,
interest_crate_name: Option<&CrateName>,
dumper: &Dumper,
features: Option<&[String]>,
) -> Result<syn::File> {
if can_execute_real(rust_crate_dir)? {
real::run(rust_crate_dir, interest_crate_name, dumper)
real::run(rust_crate_dir, interest_crate_name, dumper, features)
} else {
pseudo::run(rust_crate_dir, interest_crate_name)
}
Expand Down
26 changes: 23 additions & 3 deletions frb_codegen/src/library/commands/cargo_expand/real.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,31 @@ use log::{debug, info};
use regex::{Captures, Regex};
use std::borrow::Cow;
use std::env;
use std::path::Path;
use std::path::{Path, PathBuf};
use std::str::FromStr;

pub(super) fn run(
rust_crate_dir: &Path,
interest_crate_name: Option<&CrateName>,
dumper: &Dumper,
features: Option<&[String]>,
) -> Result<syn::File> {
let text = run_with_frb_aware(rust_crate_dir, interest_crate_name)?;
let text = run_with_frb_aware(rust_crate_dir, interest_crate_name, features)?;
(dumper.with_content(ConfigDumpContent::Source)).dump_str("cargo_expand.rs", &text)?;
Ok(syn::parse_file(&text)?)
}

fn run_with_frb_aware(
rust_crate_dir: &Path,
interest_crate_name: Option<&CrateName>,
features: Option<&[String]>,
) -> Result<String> {
Ok(decode_macro_frb_encoded_comments(&run_raw(
rust_crate_dir,
interest_crate_name,
"--cfg frb_expand",
true,
features,
)?)
.into_owned())
}
Expand All @@ -55,6 +59,7 @@ fn run_raw(
interest_crate_name: Option<&CrateName>,
extra_rustflags: &str,
allow_auto_install: bool,
features: Option<&[String]>,
) -> Result<String> {
// let _pb = simple_progress("Run cargo-expand".to_owned(), 1);
debug!("Running cargo expand in '{rust_crate_dir:?}'");
Expand All @@ -65,13 +70,22 @@ fn run_raw(
vec![]
};

let args_features: Vec<PathBuf> = features
.unwrap_or_default()
.iter()
.flat_map(|feature| vec!["--features", feature])
.map(PathBuf::from_str)
.try_collect()?;

let args = command_args!(
"expand",
"--lib",
"--theme=none",
"--ugly",
*args_choosing_crate,
*args_features
);

let extra_env = [(
"RUSTFLAGS".to_owned(),
env::var("RUSTFLAGS").map(|x| x + " ").unwrap_or_default() + extra_rustflags,
Expand All @@ -88,7 +102,13 @@ fn run_raw(
if stderr.contains("no such command: `expand`") && allow_auto_install {
info!("Cargo expand is not installed. Automatically install and re-run.");
install_cargo_expand()?;
return run_raw(rust_crate_dir, interest_crate_name, extra_rustflags, false);
return run_raw(
rust_crate_dir,
interest_crate_name,
extra_rustflags,
false,
features,
);
}
// This will stop the whole generator and tell the users, so we do not care about testing it
// frb-coverage:ignore-start
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
{
"controller": {
"exclude_paths": [
"{the-working-directory}/src/frb_generated.rs"
],
"exclude_paths": ["{the-working-directory}/src/frb_generated.rs"],
"max_count": null,
"watch": false,
"watching_paths": [
"{the-working-directory}/src"
]
"watching_paths": ["{the-working-directory}/src"]
},
"dumper": {
"dump_contents": [],
Expand Down Expand Up @@ -91,12 +87,11 @@
"hir": {
"rust_crate_dir": "{the-working-directory}",
"rust_input_namespace_pack": {
"rust_input_namespace_prefixes": [
"crate::api"
],
"rust_input_namespace_prefixes": ["crate::api"],
"rust_output_path_namespace": "crate::frb_generated"
},
"third_party_crate_names": []
"third_party_crate_names": [],
"rust_features": null
},
"mir": {
"default_dart_async": true,
Expand All @@ -108,9 +103,7 @@
"rust2dart": "Pde"
},
"rust_input_namespace_pack": {
"rust_input_namespace_prefixes": [
"crate::api"
],
"rust_input_namespace_prefixes": ["crate::api"],
"rust_output_path_namespace": "crate::frb_generated"
},
"stop_on_error": false,
Expand All @@ -134,4 +127,4 @@
"deps_check": true,
"needs_ffigen": false
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
{
"controller": {
"exclude_paths": [
"{the-working-directory}/src/frb_generated.rs"
],
"exclude_paths": ["{the-working-directory}/src/frb_generated.rs"],
"max_count": null,
"watch": false,
"watching_paths": [
"{the-working-directory}/src"
]
"watching_paths": ["{the-working-directory}/src"]
},
"dumper": {
"dump_contents": [],
Expand Down Expand Up @@ -91,12 +87,11 @@
"hir": {
"rust_crate_dir": "{the-working-directory}",
"rust_input_namespace_pack": {
"rust_input_namespace_prefixes": [
"crate::api"
],
"rust_input_namespace_prefixes": ["crate::api"],
"rust_output_path_namespace": "crate::frb_generated"
},
"third_party_crate_names": []
"third_party_crate_names": [],
"rust_features": null
},
"mir": {
"default_dart_async": true,
Expand All @@ -108,9 +103,7 @@
"rust2dart": "Pde"
},
"rust_input_namespace_pack": {
"rust_input_namespace_prefixes": [
"crate::api"
],
"rust_input_namespace_prefixes": ["crate::api"],
"rust_output_path_namespace": "crate::frb_generated"
},
"stop_on_error": false,
Expand All @@ -134,4 +127,4 @@
"deps_check": true,
"needs_ffigen": false
}
}
}
25 changes: 14 additions & 11 deletions frb_dart/lib/src/cli/build_web/executor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,20 @@ class BuildWebArgs {
final String? dartCompileJsEntrypoint;

/// {@macro flutter_rust_bridge.cli}
const BuildWebArgs({
required this.output,
required this.release,
required this.verbose,
required this.rustCrateDir,
required this.cargoBuildArgs,
required this.wasmBindgenArgs,
required this.wasmPackRustupToolchain,
required this.wasmPackRustflags,
required this.dartCompileJsEntrypoint,
});
final List<String> features;

/// {@macro flutter_rust_bridge.cli}
const BuildWebArgs(
{required this.output,
required this.release,
required this.verbose,
required this.rustCrateDir,
required this.cargoBuildArgs,
required this.wasmBindgenArgs,
required this.wasmPackRustupToolchain,
required this.wasmPackRustflags,
required this.dartCompileJsEntrypoint,
this.features = const []});
}

extension on BuildWebArgs {
Expand Down
5 changes: 3 additions & 2 deletions frb_example/dart_build_rs/rust/Cargo.lock

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

Loading

0 comments on commit bb37ed7

Please sign in to comment.