@@ -440,9 +440,9 @@ async fn generate_rust_bindings(root_dir: &Path, cargo_toml: &Path, _component_i
440440 let dep_module_name = crate :: language:: rust:: identifier_safe ( package_name) ;
441441
442442 // step 1: create a module with the generate! macro
443- let imps = interfaces. iter ( ) . map ( |i| format ! ( r#" import {i};"# ) ) . collect :: < Vec < _ > > ( ) ;
443+ let imps = interfaces. iter ( ) . filter ( |itf| ! crate :: language :: rust :: is_stdlib_known ( itf ) ) . map ( |i| format ! ( r#" import {i};"# ) ) . collect :: < Vec < _ > > ( ) ;
444444 let imps = imps. join ( "\n " ) ;
445- let gens = interfaces. iter ( ) . map ( |i| format ! ( r#" "{i}": generate,"# ) ) . collect :: < Vec < _ > > ( ) ;
445+ let gens = interfaces. iter ( ) . filter ( |itf| ! crate :: language :: rust :: is_stdlib_known ( itf ) ) . map ( |i| format ! ( r#" "{i}": generate,"# ) ) . collect :: < Vec < _ > > ( ) ;
446446 let gens = gens. join ( "\n " ) ;
447447 let gen_name = format ! ( "{}-{}" , package_name. namespace, package_name. name) ;
448448
@@ -503,87 +503,4 @@ async fn generate_rust_bindings(root_dir: &Path, cargo_toml: &Path, _component_i
503503 }
504504
505505 Ok ( ( ) )
506-
507- // let lib_file = root_dir.join("src/lib.rs");
508- // if !lib_file.is_file() {
509- // bail!("src/lib.rs is not a file");
510- // }
511- // let lib_text = std::fs::read_to_string(&lib_file)?;
512-
513- // // ALL RIGHT HERE WE GO
514-
515- // // If we already have a `mod deps`...
516- // if let Some(mod_deps_index) = lib_text.lines().position(|l| l.trim().starts_with("mod deps {")) {
517- // // oh no we gotta do some flippin parsing
518- // // TODO: can syn help us? It seemed a bit agonising and not terribly supportive
519- // let mut lines: Vec<_> = lib_text.lines().map(|s| s.to_owned()).collect();
520- // let mut index = mod_deps_index;
521- // let mut in_imports = false;
522- // let mut in_with = false;
523- // let mut unseen_imports: Vec<_> = interfaces.iter().map(|i| format!("import {i};")).collect();
524- // let mut unseen_withs: Vec<_> = interfaces.iter().map(|i| format!("\"{i}\": generate,")).collect();
525- // loop {
526- // index += 1;
527- // let current = &lines[index];
528- // if current.trim().starts_with("world imports {") {
529- // in_imports = true;
530- // continue;
531- // }
532- // if in_imports {
533- // if current.trim().starts_with("}") {
534- // // insert those not yet seen and BUMP INDEX PAST THEM
535- // in_imports = false;
536- // for import in &unseen_imports {
537- // lines.insert(index - 1, format!(" {import}"));
538- // index += 1;
539- // }
540- // continue;;
541- // }
542- // if current.trim().starts_with("import ") {
543- // // if this was one we were planning to insert, remove it from the plan!
544- // unseen_imports.retain(|imp| imp != current.trim());
545- // continue;
546- // }
547- // }
548- // if current.trim().starts_with("with: {") {
549- // in_with = true;
550- // continue;
551- // }
552- // if in_with {
553- // if current.trim().ends_with(": generate,") {
554- // // if this was one we were planning to insert, remove it from the plan!
555- // unseen_withs.retain(|w| w != current.trim());
556- // continue;
557- // }
558-
559- // }
560- // }
561-
562- // } else {
563- // // We will create a `mod deps` with SCIENCE in it
564- // let imps = interfaces.iter().map(|i| format!(r#" import {i};"#)).collect::<Vec<_>>();
565- // let imps = imps.join("\n");
566- // let gens = interfaces.iter().map(|i| format!(r#" "{i}": generate,"#)).collect::<Vec<_>>();
567- // let gens = gens.join("\n");
568- // let deps_text = format!(r###"
569- // mod deps {{
570- // wit_bindgen::generate!({{
571- // inline: r#"
572- // package root:component;
573- // world imports {{
574- // {imps}
575- // }}
576- // "#,
577- // with: {{
578- // {gens}
579- // }},
580- // path: ".wit/components/{component_id}",
581- // }});
582- // }}
583- // "###);
584-
585- // // TODO: insert this into the file in a SCIENTIFICALLY DETERMINED place
586- // }
587-
588- // todo!()
589506}
0 commit comments