diff options
author | John Hodge <tpg@mutabah.net> | 2017-09-23 14:45:30 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2017-09-23 14:45:30 +0800 |
commit | 4d99850792a83b0416459ed930403304f450f8f6 (patch) | |
tree | bbc0178c0ba6ff865c9d9117d63f603c9227b676 | |
parent | cfb45e3564ebfedc4b40adcf53286f9737f8d25e (diff) | |
parent | 69e7babc3bf5e7cfa86295bfa4cb139b79627a8b (diff) | |
download | mrust-4d99850792a83b0416459ed930403304f450f8f6.tar.gz |
Merge branch 'master' of ssh://github.com/thepowersgang/mrustc
-rw-r--r-- | script-overrides/stable-1.19.0/build_rustc_asan.txt | 0 | ||||
-rw-r--r-- | script-overrides/stable-1.19.0/build_rustc_lsan.txt | 0 | ||||
-rw-r--r-- | script-overrides/stable-1.19.0/build_rustc_msan.txt | 0 | ||||
-rw-r--r-- | script-overrides/stable-1.19.0/build_rustc_tsan.txt | 0 | ||||
-rw-r--r-- | src/hir/item_path.hpp | 6 | ||||
-rw-r--r-- | src/hir_typeck/outer.cpp | 2 | ||||
-rw-r--r-- | tools/minicargo/build.cpp | 47 | ||||
-rw-r--r-- | tools/minicargo/build.h | 14 | ||||
-rw-r--r-- | tools/minicargo/debug.h | 12 | ||||
-rw-r--r-- | tools/minicargo/main.cpp | 70 | ||||
-rw-r--r-- | tools/minicargo/manifest.cpp | 25 | ||||
-rw-r--r-- | tools/minicargo/toml.cpp | 1 |
12 files changed, 134 insertions, 43 deletions
diff --git a/script-overrides/stable-1.19.0/build_rustc_asan.txt b/script-overrides/stable-1.19.0/build_rustc_asan.txt new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/script-overrides/stable-1.19.0/build_rustc_asan.txt diff --git a/script-overrides/stable-1.19.0/build_rustc_lsan.txt b/script-overrides/stable-1.19.0/build_rustc_lsan.txt new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/script-overrides/stable-1.19.0/build_rustc_lsan.txt diff --git a/script-overrides/stable-1.19.0/build_rustc_msan.txt b/script-overrides/stable-1.19.0/build_rustc_msan.txt new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/script-overrides/stable-1.19.0/build_rustc_msan.txt diff --git a/script-overrides/stable-1.19.0/build_rustc_tsan.txt b/script-overrides/stable-1.19.0/build_rustc_tsan.txt new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/script-overrides/stable-1.19.0/build_rustc_tsan.txt diff --git a/src/hir/item_path.hpp b/src/hir/item_path.hpp index 9f9949e1..11e3b0f4 100644 --- a/src/hir/item_path.hpp +++ b/src/hir/item_path.hpp @@ -54,13 +54,17 @@ public: assert(parent); assert(name); - if( parent->name ) { + // If the parent has a name, or the parent is the crate root. + if( parent->name || !parent->ty ) { return get_simple_path(); } else if( parent->trait ) { + assert(parent->ty); + assert(parent->trait_params); return ::HIR::Path( parent->ty->clone(), ::HIR::GenericPath(parent->trait->clone(), parent->trait_params->clone()), ::std::string(name) ); } else { + assert(parent->ty); return ::HIR::Path( parent->ty->clone(), ::std::string(name) ); } } diff --git a/src/hir_typeck/outer.cpp b/src/hir_typeck/outer.cpp index 6358e47e..dddb7731 100644 --- a/src/hir_typeck/outer.cpp +++ b/src/hir_typeck/outer.cpp @@ -291,6 +291,8 @@ namespace { // If not, ensure taht we're checking a function return type, and error if not if( ! m_fcn_path ) ERROR(sp, E0000, "Use of an erased type outside of a function return - " << ty); + assert(m_fcn_ptr); + DEBUG(*m_fcn_path << " " << m_fcn_erased_count); ::HIR::PathParams params; for(unsigned int i = 0; i < m_fcn_ptr->m_params.m_types.size(); i ++) diff --git a/tools/minicargo/build.cpp b/tools/minicargo/build.cpp index 62fd48c5..a078e48b 100644 --- a/tools/minicargo/build.cpp +++ b/tools/minicargo/build.cpp @@ -221,11 +221,11 @@ struct Timestamp } }; -bool MiniCargo_Build(const PackageManifest& manifest, ::helpers::path override_path) +bool MiniCargo_Build(const PackageManifest& manifest, BuildOptions opts) { BuildList list; - list.add_dependencies(manifest, 0, !override_path.is_valid()); + list.add_dependencies(manifest, 0, !opts.build_script_overrides.is_valid()); list.sort_list(); // dedup? @@ -235,7 +235,7 @@ bool MiniCargo_Build(const PackageManifest& manifest, ::helpers::path override_p } // Build dependencies - Builder builder { "output", override_path }; + Builder builder { ::std::move(opts) }; for(const auto& p : list.iter()) { if( ! builder.build_library(p) ) @@ -275,6 +275,10 @@ void BuildList::add_dependencies(const PackageManifest& p, unsigned level, bool { for(const auto& dep : p.build_dependencies()) { + if( dep.is_disabled() ) + { + continue ; + } add_package(dep.get_package(), level+1, include_build); } } @@ -316,9 +320,8 @@ void BuildList::sort_list() } } -Builder::Builder(::helpers::path output_dir, ::helpers::path override_dir): - m_output_dir(output_dir), - m_build_script_overrides(override_dir) +Builder::Builder(BuildOptions opts): + m_opts(::std::move(opts)) { #ifdef _WIN32 char buf[1024]; @@ -342,7 +345,7 @@ Builder::Builder(::helpers::path output_dir, ::helpers::path override_dir): bool Builder::build_target(const PackageManifest& manifest, const PackageTarget& target) const { const char* crate_type; - auto outfile = m_output_dir; + auto outfile = m_opts.output_dir; switch(target.m_type) { case PackageTarget::Type::Lib: @@ -401,7 +404,7 @@ bool Builder::build_target(const PackageManifest& manifest, const PackageTarget& args.push_back("-O"); } args.push_back("-o"); args.push_back(outfile); - args.push_back("-L"); args.push_back(m_output_dir.str().c_str()); + args.push_back("-L"); args.push_back(m_opts.output_dir.str().c_str()); for(const auto& dir : manifest.build_script_output().rustc_link_search) { args.push_back("-L"); args.push_back(dir.second.c_str()); } @@ -417,6 +420,11 @@ bool Builder::build_target(const PackageManifest& manifest, const PackageTarget& for(const auto& feat : manifest.active_features()) { args.push_back("--cfg"); args.push_back(::format("feature=", feat)); } + for(const auto& d : m_opts.lib_search_dirs) + { + args.push_back("-L"); + args.push_back(d.str().c_str()); + } // TODO: Environment variables (rustc_env) StringListKV env; @@ -427,14 +435,19 @@ bool Builder::build_target(const PackageManifest& manifest, const PackageTarget& } ::std::string Builder::build_build_script(const PackageManifest& manifest) const { - auto outfile = m_output_dir / manifest.name() + "_build" EXESUF; + auto outfile = m_opts.output_dir / manifest.name() + "_build" EXESUF; StringList args; args.push_back( ::helpers::path(manifest.manifest_path()).parent() / ::helpers::path(manifest.build_script()) ); args.push_back("--crate-name"); args.push_back("build"); args.push_back("--crate-type"); args.push_back("bin"); args.push_back("-o"); args.push_back(outfile); - args.push_back("-L"); args.push_back(m_output_dir.str().c_str()); + args.push_back("-L"); args.push_back(m_opts.output_dir.str().c_str()); + for(const auto& d : m_opts.lib_search_dirs) + { + args.push_back("-L"); + args.push_back(d.str().c_str()); + } StringListKV env; env.push_back("CARGO_MANIFEST_DIR", manifest.directory().to_absolute()); @@ -450,17 +463,17 @@ bool Builder::build_library(const PackageManifest& manifest) const if( manifest.build_script() != "" ) { // Locate a build script override file - if(this->m_build_script_overrides.is_valid()) + if(this->m_opts.build_script_overrides.is_valid()) { - auto override_file = this->m_build_script_overrides / "build_" + manifest.name().c_str() + ".txt"; + auto override_file = this->m_opts.build_script_overrides / "build_" + manifest.name().c_str() + ".txt"; // TODO: Should this test if it exists? or just assume and let it error? - + // > Note, override file can specify a list of commands to run. const_cast<PackageManifest&>(manifest).load_build_script( override_file.str() ); } else { - auto out_file = m_output_dir / "build_" + manifest.name().c_str() + ".txt"; + auto out_file = m_opts.output_dir / "build_" + manifest.name().c_str() + ".txt"; // If the build script output doesn't exist (TODO: Or is older than ...) bool run_build_script = true; auto ts_result = this->get_timestamp(out_file); @@ -486,8 +499,8 @@ bool Builder::build_library(const PackageManifest& manifest) const return false; auto script_exe_abs = ::helpers::path(script_exe).to_absolute(); - auto output_dir_abs = m_output_dir.to_absolute(); - + auto output_dir_abs = m_opts.output_dir.to_absolute(); + // - Run the script and put output in the right dir auto out_file = output_dir_abs / "build_" + manifest.name().c_str() + ".txt"; auto out_dir = output_dir_abs / "build_" + manifest.name().c_str(); @@ -515,7 +528,7 @@ bool Builder::build_library(const PackageManifest& manifest) const env.push_back("OPT_LEVEL", "2"); env.push_back("DEBUG", "0"); env.push_back("PROFILE", "release"); - + #if _WIN32 #else auto fd_cwd = open(".", O_DIRECTORY); diff --git a/tools/minicargo/build.h b/tools/minicargo/build.h index 45ce1679..4bbcd158 100644 --- a/tools/minicargo/build.h +++ b/tools/minicargo/build.h @@ -7,14 +7,20 @@ class StringList; class StringListKV; struct Timestamp; +struct BuildOptions +{ + ::helpers::path output_dir; + ::helpers::path build_script_overrides; + ::std::vector<::helpers::path> lib_search_dirs; +}; + class Builder { - ::helpers::path m_output_dir; - ::helpers::path m_build_script_overrides; + BuildOptions m_opts; ::helpers::path m_compiler_path; public: - Builder(::helpers::path output_dir, ::helpers::path override_dir); + Builder(BuildOptions opts); bool build_target(const PackageManifest& manifest, const PackageTarget& target) const; bool build_library(const PackageManifest& manifest) const; @@ -28,4 +34,4 @@ private: Timestamp get_timestamp(const ::helpers::path& path) const; }; -extern bool MiniCargo_Build(const PackageManifest& manifest, ::helpers::path override_path); +extern bool MiniCargo_Build(const PackageManifest& manifest, BuildOptions opts); diff --git a/tools/minicargo/debug.h b/tools/minicargo/debug.h index 00cd1412..f723d359 100644 --- a/tools/minicargo/debug.h +++ b/tools/minicargo/debug.h @@ -9,9 +9,15 @@ extern void Debug_EnterScope(const char* name, dbg_cb_t ); extern void Debug_LeaveScope(const char* name, dbg_cb_t ); extern void Debug_Print(dbg_cb_t cb); -#define DEBUG(fmt) do { Debug_Print([&](auto& os){ os << "DEBUG: " << fmt; }); } while(0) -#define TODO(fmt) do { Debug_Print([&](auto& os){ os << "TODO: " << fmt; }); abort(); } while(0) -#define TRACE_FUNCTION_F(fmt) DebugFunctionScope trace_function_hdr { __FUNCTION__, [&](auto& os){ os << fmt; } } +#if defined(NOLOG) +# define DEBUG(fmt) do { } while(0) +# define TODO(fmt) do { } while(0) +# define TRACE_FUNCTION_F(fmt) do{}while(0) +#else +# define DEBUG(fmt) do { Debug_Print([&](auto& os){ os << "DEBUG: " << fmt; }); } while(0) +# define TODO(fmt) do { Debug_Print([&](auto& os){ os << "TODO: " << fmt; }); abort(); } while(0) +# define TRACE_FUNCTION_F(fmt) DebugFunctionScope trace_function_hdr { __FUNCTION__, [&](auto& os){ os << fmt; } } +#endif namespace { static inline void format_to_stream(::std::ostream& os) { diff --git a/tools/minicargo/main.cpp b/tools/minicargo/main.cpp index 04fe4fcf..c94f9bc3 100644 --- a/tools/minicargo/main.cpp +++ b/tools/minicargo/main.cpp @@ -15,6 +15,7 @@ struct ProgramOptions { + // Input (package) directory const char* directory = nullptr; // Directory containing build script outputs @@ -23,8 +24,14 @@ struct ProgramOptions // Directory containing "vendored" (packaged) copies of packages const char* vendor_dir = nullptr; + // Output/build directory const char* output_directory = nullptr; + // Library search directories + ::std::vector<const char*> lib_search_dirs; + + bool pause_before_quit = false; + int parse(int argc, const char* argv[]); void usage() const; }; @@ -56,30 +63,36 @@ int main(int argc, const char* argv[]) m.load_dependencies(repo, !bs_override_dir.is_valid()); // 3. Build dependency tree and build program. - if( !MiniCargo_Build(m, bs_override_dir ) ) + BuildOptions build_opts; + build_opts.build_script_overrides = ::std::move(bs_override_dir); + build_opts.output_dir = opts.output_directory ? ::helpers::path(opts.output_directory) : ::helpers::path("output"); + build_opts.lib_search_dirs.reserve(opts.lib_search_dirs.size()); + for(const auto* d : opts.lib_search_dirs) + build_opts.lib_search_dirs.push_back( ::helpers::path(d) ); + if( !MiniCargo_Build(m, ::std::move(build_opts)) ) { ::std::cerr << "BUILD FAILED" << ::std::endl; -#if _WIN32 - ::std::cout << "Press enter to exit..." << ::std::endl; - ::std::cin.get(); -#endif + if(opts.pause_before_quit) { + ::std::cout << "Press enter to exit..." << ::std::endl; + ::std::cin.get(); + } return 1; } } catch(const ::std::exception& e) { ::std::cerr << "EXCEPTION: " << e.what() << ::std::endl; -#if _WIN32 - ::std::cout << "Press enter to exit..." << ::std::endl; - ::std::cin.get(); -#endif + if(opts.pause_before_quit) { + ::std::cout << "Press enter to exit..." << ::std::endl; + ::std::cin.get(); + } return 1; } -#if _WIN32 - ::std::cout << "Press enter to exit..." << ::std::endl; - ::std::cin.get(); -#endif + if(opts.pause_before_quit) { + ::std::cout << "Press enter to exit..." << ::std::endl; + ::std::cin.get(); + } return 0; } @@ -101,8 +114,30 @@ int ProgramOptions::parse(int argc, const char* argv[]) else if( arg[1] != '-' ) { // Short arguments + switch(arg[1]) + { + case 'L': + if(i+1 == argc) { + ::std::cerr << "Flag " << arg << " takes an argument" << ::std::endl; + return 1; + } + this->lib_search_dirs.push_back(argv[++i]); + break; + case 'o': + if(i+1 == argc) { + ::std::cerr << "Flag " << arg << " takes an argument" << ::std::endl; + return 1; + } + this->output_directory = argv[++i]; + break; + case 'h': + break; + default: + ::std::cerr << "Unknown flag -" << arg[1] << ::std::endl; + return 1; + } } - else if( arg[1] == '\0' ) + else if( arg[2] == '\0' ) { all_free = true; } @@ -123,6 +158,13 @@ int ProgramOptions::parse(int argc, const char* argv[]) } this->vendor_dir = argv[++i]; } + else if( ::std::strcmp(arg, "--output-dir") == 0 ) { + if(i+1 == argc) { + ::std::cerr << "Flag " << arg << " takes an argument" << ::std::endl; + return 1; + } + this->output_directory = argv[++i]; + } else { ::std::cerr << "Unknown flag " << arg << ::std::endl; return 1; diff --git a/tools/minicargo/manifest.cpp b/tools/minicargo/manifest.cpp index cfbe7dc9..1e2b8497 100644 --- a/tools/minicargo/manifest.cpp +++ b/tools/minicargo/manifest.cpp @@ -225,6 +225,9 @@ PackageManifest PackageManifest::load_from_toml(const ::std::string& path) else if( cfg == "cfg(all(unix, not(target_os = \"macos\")))" ) { success = CFG_UNIX; } + else if( cfg == "cfg(not(target_os = \"emscripten\"))" ) { + success = true; + } else if( cfg == "cfg(all(unix, not(target_os = \"emscripten\"), not(target_os = \"macos\"), not(target_os = \"ios\")))" ) { success = CFG_UNIX; } @@ -565,10 +568,21 @@ void PackageManifest::set_features(const ::std::vector<::std::string>& features, } } } - auto it2 = ::std::find_if(m_dependencies.begin(), m_dependencies.end(), [&](const auto& x){ return x.m_name == featname; }); - if(it2 != m_dependencies.end()) + + { + auto it2 = ::std::find_if(m_dependencies.begin(), m_dependencies.end(), [&](const auto& x){ return x.m_name == featname; }); + if(it2 != m_dependencies.end()) + { + it2->m_optional_enabled = true; + } + } + { - it2->m_optional_enabled = true; + auto it2 = ::std::find_if(m_build_dependencies.begin(), m_build_dependencies.end(), [&](const auto& x){ return x.m_name == featname; }); + if(it2 != m_build_dependencies.end()) + { + it2->m_optional_enabled = true; + } } } } @@ -593,7 +607,10 @@ void PackageManifest::load_dependencies(Repository& repo, bool include_build) { for(auto& dep : m_build_dependencies) { - assert( !dep.m_optional ); + if( dep.m_optional && !dep.m_optional_enabled ) + { + continue ; + } dep.load_manifest(repo, base_path, true); } } diff --git a/tools/minicargo/toml.cpp b/tools/minicargo/toml.cpp index a33114c6..9fad0ec4 100644 --- a/tools/minicargo/toml.cpp +++ b/tools/minicargo/toml.cpp @@ -1,6 +1,7 @@ /* * A very bad streaming TOML parser */ +#define NOLOG #include "toml.h" #include "debug.h" #include <cassert> |