From 97b12bcf017c43a544d44ddcded5596f9ffdf3c4 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 12 Oct 2019 17:45:40 +0800 Subject: Codegen C - Don't link proc macros into final executable --- src/trans/codegen_c.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src/trans/codegen_c.cpp') diff --git a/src/trans/codegen_c.cpp b/src/trans/codegen_c.cpp index 81a1a68c..1ee74fee 100644 --- a/src/trans/codegen_c.cpp +++ b/src/trans/codegen_c.cpp @@ -824,15 +824,18 @@ namespace { case CodegenOutput::Executable: for( const auto& crate : m_crate.m_ext_crates ) { - // TODO: If this crate is included in a dylib crate, ignore it + auto is_dylib = [](const ::HIR::ExternCrate& c) { + bool rv = false; + // TODO: Better rule than this + rv |= (c.m_path.compare(c.m_path.size() - 3, 3, ".so") == 0); + rv |= (c.m_path.compare(c.m_path.size() - 4, 4, ".dll") == 0); + return rv; + }; + // If this crate is included in a dylib crate, ignore it bool is_in_dylib = false; for( const auto& crate2 : m_crate.m_ext_crates ) { - // TODO: Better rule than this - bool is_dylib = false; - is_dylib |= (crate2.second.m_path.compare(crate2.second.m_path.size() - 3, 3, ".so") == 0); - is_dylib |= (crate2.second.m_path.compare(crate2.second.m_path.size() - 4, 4, ".dll") == 0); - if( is_dylib ) + if( is_dylib(crate2.second) ) { for(const auto& subcrate : crate2.second.m_data->m_ext_crates) { @@ -850,9 +853,12 @@ namespace { else if( crate.second.m_path.compare(crate.second.m_path.size() - 5, 5, ".rlib") == 0 ) { args.push_back(crate.second.m_path + ".o"); } - else { + else if( is_dylib(crate.second) ) { args.push_back(crate.second.m_path); } + else { + // Proc macro. + } } for(const auto& path : link_dirs ) { -- cgit v1.2.3