From ded405bcbc497595e10ccbb620c6132c4a2277ea Mon Sep 17 00:00:00 2001 From: John Hodge Date: Tue, 22 Aug 2017 17:48:04 +0800 Subject: minicargo - MSVC timestamps, argument for build script override dir --- script-overrides/stable-1.19.0/build_libc.txt | 2 ++ tools/minicargo/build.cpp | 51 ++++++++++++++++++++++----- tools/minicargo/main.cpp | 13 +++++-- 3 files changed, 55 insertions(+), 11 deletions(-) create mode 100644 script-overrides/stable-1.19.0/build_libc.txt diff --git a/script-overrides/stable-1.19.0/build_libc.txt b/script-overrides/stable-1.19.0/build_libc.txt new file mode 100644 index 00000000..aa2eb983 --- /dev/null +++ b/script-overrides/stable-1.19.0/build_libc.txt @@ -0,0 +1,2 @@ +cargo:rustc-cfg=stdbuild +cargo:rerun-if-changed=build.rs \ No newline at end of file diff --git a/tools/minicargo/build.cpp b/tools/minicargo/build.cpp index b4e736d2..c44c0601 100644 --- a/tools/minicargo/build.cpp +++ b/tools/minicargo/build.cpp @@ -81,6 +81,37 @@ class Builder } }; + struct Timestamp + { +#if _WIN32 + FILETIME m_val; +#else + time_t m_val; +#endif + static Timestamp infinite_past() { +#if _WIN32 + return Timestamp { FILETIME { 0, 0 } }; +#else + return Timestamp { 0 } +#endif + } + + bool operator==(const Timestamp& x) const { +#if _WIN32 + return m_val.dwHighDateTime == x.m_val.dwHighDateTime && m_val.dwLowDateTime == x.m_val.dwLowDateTime; +#else + return m_val == x.m_val; +#endif + } + bool operator<(const Timestamp& x) const { +#if _WIN32 + return m_val.dwHighDateTime == x.m_val.dwHighDateTime ? m_val.dwLowDateTime < x.m_val.dwLowDateTime : m_val.dwHighDateTime < x.m_val.dwHighDateTime; +#else + return m_val < x.m_val; +#endif + } + }; + ::helpers::path m_build_script_overrides; public: @@ -96,10 +127,10 @@ private: bool spawn_process(const StringList& args, const ::helpers::path& logfile) const; - time_t get_timestamp(const ::helpers::path& path) const; + Timestamp get_timestamp(const ::helpers::path& path) const; }; -void MiniCargo_Build(const PackageManifest& manifest) +void MiniCargo_Build(const PackageManifest& manifest, ::helpers::path override_path) { BuildList list; @@ -113,8 +144,7 @@ void MiniCargo_Build(const PackageManifest& manifest) } // Build dependencies - // TODO: Take this path as input. (XXX HACK) - Builder builder { "overrides/nightly-2017-07-08" }; + Builder builder { override_path }; for(const auto& p : list.iter()) { if( ! builder.build_library(p) ) @@ -192,7 +222,7 @@ bool Builder::build_target(const PackageManifest& manifest, const PackageTarget& auto ts_result = this->get_timestamp(outfile); if( force_rebuild ) { } - else if( ts_result == 0/*Timestamp::infinite_past()*/ ) { + else if( ts_result == Timestamp::infinite_past() ) { // Rebuild (missing) } //else if( ts_result < this->get_timestamp("../bin/mrustc") || ts_result < this->get_timestamp("bin/minicargo") ) { @@ -348,18 +378,23 @@ bool Builder::spawn_process(const StringList& args, const ::helpers::path& logfi return true; } -time_t Builder::get_timestamp(const ::helpers::path& path) const +Builder::Timestamp Builder::get_timestamp(const ::helpers::path& path) const { #if _WIN32 + FILETIME out; + auto handle = CreateFile(path.str().c_str(), GENERIC_READ, 0, nullptr, 0, 0, NULL); + if(handle == NULL) return Timestamp::infinite_past(); + GetFileTime(handle, nullptr, nullptr, &out); + return Timestamp { out }; #else struct stat s; if( stat(path.str().c_str(), &s) == 0 ) { - return s.st_mtime; + return Timestamp { s.st_mtime }; } else { - return 0; + return Timestamp::infinite_past(); } #endif } diff --git a/tools/minicargo/main.cpp b/tools/minicargo/main.cpp index 236b9d77..decedd6a 100644 --- a/tools/minicargo/main.cpp +++ b/tools/minicargo/main.cpp @@ -12,7 +12,7 @@ #include "helpers.h" #include "repository.h" -extern void MiniCargo_Build(const PackageManifest& manifest); +extern void MiniCargo_Build(const PackageManifest& manifest, ::helpers::path override_path); struct ProgramOptions { @@ -54,7 +54,7 @@ int main(int argc, const char* argv[]) m.load_dependencies(repo); // 3. Build dependency tree - MiniCargo_Build(m); + MiniCargo_Build(m, opts.override_directory ? ::helpers::path(opts.override_directory) : ::helpers::path() ); } catch(const ::std::exception& e) { @@ -100,7 +100,14 @@ int ProgramOptions::parse(int argc, const char* argv[]) ::std::cerr << "Flag " << arg << " takes an argument" << ::std::endl; return 1; } - //this->build_script_override_dir = argv[++i]; + this->override_directory = argv[++i]; + } + else if( ::std::strcmp(arg, "--vendor-dir") == 0 ) { + if(i+1 == argc) { + ::std::cerr << "Flag " << arg << " takes an argument" << ::std::endl; + return 1; + } + this->vendor_dir = argv[++i]; } else { ::std::cerr << "Unknown flag " << arg << ::std::endl; -- cgit v1.2.3 From f62e4179bd7a4a893bf62686ef82f0a93b1cd970 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Tue, 22 Aug 2017 19:46:12 +0800 Subject: minicargo - Timestamp checking fixes, target default name --- .../stable-1.19.0/build_compiler_builtins.txt | 1 + tools/minicargo/build.cpp | 83 ++++++++++++++++++---- tools/minicargo/manifest.cpp | 8 +++ 3 files changed, 78 insertions(+), 14 deletions(-) create mode 100644 script-overrides/stable-1.19.0/build_compiler_builtins.txt diff --git a/script-overrides/stable-1.19.0/build_compiler_builtins.txt b/script-overrides/stable-1.19.0/build_compiler_builtins.txt new file mode 100644 index 00000000..06ae3dbf --- /dev/null +++ b/script-overrides/stable-1.19.0/build_compiler_builtins.txt @@ -0,0 +1 @@ +# NOTE: mrustc doesn't need this built fully \ No newline at end of file diff --git a/tools/minicargo/build.cpp b/tools/minicargo/build.cpp index c44c0601..fd141395 100644 --- a/tools/minicargo/build.cpp +++ b/tools/minicargo/build.cpp @@ -56,6 +56,8 @@ struct BuildList class Builder { + static const char* const MRUSTC_PATH; + class StringList { ::std::vector<::std::string> m_cached; @@ -64,6 +66,7 @@ class Builder StringList() { } + StringList(const StringList&) = delete; const ::std::vector& get_vec() const { @@ -72,6 +75,33 @@ class Builder void push_back(::std::string s) { +#if _WIN32 + // NOTE: MSVC's STL changes the pointer on move it seems + if(m_cached.capacity() == m_cached.size()) + { + ::std::vector b; + b.reserve(m_strings.size()); + size_t j = 0; + for(const auto* s : m_strings) + { + if(j == m_cached.size()) + break; + if(s == m_cached[j].c_str()) + b.push_back(true); + else + b.push_back(false); + } + + m_cached.push_back(::std::move(s)); + j = 0; + for(size_t i = 0; i < b.size(); i ++) + { + if(b[i]) + m_strings[i] = m_cached[j++].c_str(); + } + } + else +#endif m_cached.push_back(::std::move(s)); m_strings.push_back(m_cached.back().c_str()); } @@ -84,7 +114,12 @@ class Builder struct Timestamp { #if _WIN32 - FILETIME m_val; + uint64_t m_val; + + Timestamp(FILETIME ft): + m_val( (static_cast(ft.dwHighDateTime) << 32) | static_cast(ft.dwLowDateTime) ) + { + } #else time_t m_val; #endif @@ -97,18 +132,19 @@ class Builder } bool operator==(const Timestamp& x) const { -#if _WIN32 - return m_val.dwHighDateTime == x.m_val.dwHighDateTime && m_val.dwLowDateTime == x.m_val.dwLowDateTime; -#else return m_val == x.m_val; -#endif } bool operator<(const Timestamp& x) const { + return m_val < x.m_val; + } + + friend ::std::ostream& operator<<(::std::ostream& os, const Timestamp& x) { #if _WIN32 - return m_val.dwHighDateTime == x.m_val.dwHighDateTime ? m_val.dwLowDateTime < x.m_val.dwLowDateTime : m_val.dwHighDateTime < x.m_val.dwHighDateTime; + os << ::std::hex << x.m_val << ::std::dec; #else - return m_val < x.m_val; + os << x.m_val; #endif + return os; } }; @@ -130,6 +166,12 @@ private: Timestamp get_timestamp(const ::helpers::path& path) const; }; +#if _WIN32 +const char* const Builder::MRUSTC_PATH = "x64\\Release\\mrustc.exe"; +#else +const char* const Builder::MRUSTC_PATH = "../bin/mrustc"; +#endif + void MiniCargo_Build(const PackageManifest& manifest, ::helpers::path override_path) { BuildList list; @@ -211,6 +253,7 @@ bool Builder::build_target(const PackageManifest& manifest, const PackageTarget& { auto outdir = ::helpers::path("output"); auto outfile = outdir / ::format("lib", target.m_name, ".hir"); + //DEBUG("Building " << manifest.name() << ":" << target.m_name << " as " << outfile); // TODO: Determine if it needs re-running // Rerun if: @@ -221,13 +264,16 @@ bool Builder::build_target(const PackageManifest& manifest, const PackageTarget& bool force_rebuild = false; auto ts_result = this->get_timestamp(outfile); if( force_rebuild ) { + DEBUG("Building " << outfile << " - Force"); } else if( ts_result == Timestamp::infinite_past() ) { // Rebuild (missing) + DEBUG("Building " << outfile << " - Missing"); + } + else if( ts_result < this->get_timestamp(MRUSTC_PATH) /*|| ts_result < this->get_timestamp("bin/minicargo")*/ ) { + // Rebuild (older than mrustc/minicargo) + DEBUG("Building " << outfile << " - Older than mrustc ( " << ts_result << " < " << this->get_timestamp(MRUSTC_PATH) << ")"); } - //else if( ts_result < this->get_timestamp("../bin/mrustc") || ts_result < this->get_timestamp("bin/minicargo") ) { - // // Rebuild (older than mrustc/minicargo) - //} else { // TODO: Check dependencies. (from depfile) // Don't rebuild (no need to) @@ -320,7 +366,7 @@ bool Builder::spawn_process(const StringList& args, const ::helpers::path& logfi char env[] = "MRUSTC_DEBUG=""\0" ; - CreateProcessA("x64\\Release\\mrustc.exe", (LPSTR)cmdline_str.c_str(), NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi); + CreateProcessA(MRUSTC_PATH, (LPSTR)cmdline_str.c_str(), NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi); CloseHandle(si.hStdOutput); WaitForSingleObject(pi.hProcess, INFINITE); DWORD status = 1; @@ -382,9 +428,18 @@ Builder::Timestamp Builder::get_timestamp(const ::helpers::path& path) const { #if _WIN32 FILETIME out; - auto handle = CreateFile(path.str().c_str(), GENERIC_READ, 0, nullptr, 0, 0, NULL); - if(handle == NULL) return Timestamp::infinite_past(); - GetFileTime(handle, nullptr, nullptr, &out); + auto handle = CreateFile(path.str().c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); + if(handle == INVALID_HANDLE_VALUE) { + //DEBUG("Can't find " << path); + return Timestamp::infinite_past(); + } + if( GetFileTime(handle, NULL, NULL, &out) == FALSE ) { + //DEBUG("Can't GetFileTime on " << path); + CloseHandle(handle); + return Timestamp::infinite_past(); + } + CloseHandle(handle); + //DEBUG(Timestamp{out} << " " << path); return Timestamp { out }; #else struct stat s; diff --git a/tools/minicargo/manifest.cpp b/tools/minicargo/manifest.cpp index 60594303..aab0adac 100644 --- a/tools/minicargo/manifest.cpp +++ b/tools/minicargo/manifest.cpp @@ -214,6 +214,14 @@ PackageManifest PackageManifest::load_from_toml(const ::std::string& path) } } + for(auto& tgt : rv.m_targets) + { + if(tgt.m_name == "") + { + tgt.m_name = rv.m_name; + } + } + return rv; } -- cgit v1.2.3 From 1fbd12d2954f22b96f8da0ae9bc3e0b091d9a838 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Tue, 22 Aug 2017 19:46:41 +0800 Subject: Expand - allow #![no_std] or #![no_core] to be repeated --- src/expand/std_prelude.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/expand/std_prelude.cpp b/src/expand/std_prelude.cpp index 16c4ce90..e12a441c 100644 --- a/src/expand/std_prelude.cpp +++ b/src/expand/std_prelude.cpp @@ -8,9 +8,9 @@ class Decorator_NoStd: { public: AttrStage stage() const override { return AttrStage::Pre; } - + void handle(const Span& sp, const AST::MetaItem& mi, AST::Crate& crate) const override { - if( crate.m_load_std != AST::Crate::LOAD_STD ) { + if( crate.m_load_std != AST::Crate::LOAD_STD && crate.m_load_std != AST::Crate::LOAD_CORE ) { ERROR(sp, E0000, "Invalid use of #![no_std] with itself or #![no_core]"); } crate.m_load_std = AST::Crate::LOAD_CORE; @@ -23,7 +23,7 @@ public: AttrStage stage() const override { return AttrStage::Pre; } void handle(const Span& sp, const AST::MetaItem& mi, AST::Crate& crate) const override { - if( crate.m_load_std != AST::Crate::LOAD_STD ) { + if( crate.m_load_std != AST::Crate::LOAD_STD && crate.m_load_std != AST::Crate::LOAD_NONE ) { ERROR(sp, E0000, "Invalid use of #![no_core] with itself or #![no_std]"); } crate.m_load_std = AST::Crate::LOAD_NONE; -- cgit v1.2.3 From ae2c2e15bea28bd03efd70060fcb4c49e43477f6 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Tue, 22 Aug 2017 21:21:16 +0800 Subject: Expand - Handle windows paths in `include!` --- src/expand/include.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/expand/include.cpp b/src/expand/include.cpp index a6eb9fe1..22b7d1a9 100644 --- a/src/expand/include.cpp +++ b/src/expand/include.cpp @@ -30,18 +30,19 @@ namespace { ::std::string get_path_relative_to(const ::std::string& base_path, ::std::string path) { - if( path[0] == '/' ) { + DEBUG(base_path << ", " << path); + if( path[0] == '/' || path[0] == '\\' ) { return path; } else if( base_path.size() == 0 ) { return path; } - else if( base_path[base_path.size()-1] == '/' ) { + else if( base_path.back() == '/' || base_path.back() == '\\' ) { return base_path + path; } else { - auto slash = base_path.find_last_of('/'); + auto slash = ::std::min( base_path.find_last_of('/'), base_path.find_last_of('\\') ); if( slash == ::std::string::npos ) { return path; @@ -75,7 +76,13 @@ class CIncludeExpander: ::std::string file_path = get_path_relative_to(mod.m_file_info.path, mv$(path)); - return box$( Lexer(file_path) ); + try { + return box$( Lexer(file_path) ); + } + catch(::std::runtime_error& e) + { + ERROR(sp, E0000, e.what()); + } } }; -- cgit v1.2.3 From 251e49aef76e46af5005978ac25650aab4f94313 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Tue, 22 Aug 2017 21:21:44 +0800 Subject: Resolve Use - (minor) Diagnostics fix when module cannot be found --- src/resolve/use.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/resolve/use.cpp b/src/resolve/use.cpp index 5e1fce6d..9c27711d 100644 --- a/src/resolve/use.cpp +++ b/src/resolve/use.cpp @@ -688,7 +688,10 @@ namespace { auto b = Resolve_Use_GetBinding_Mod(span, crate, *mod, nodes[i].name(), parent_modules, Lookup::Type); TU_MATCH_DEF(::AST::PathBinding, (b), (e), ( - ERROR(span, E0000, "Unexpected item type in import"); + ERROR(span, E0000, "Unexpected item type " << b.tag_str() << " in import of " << path); + ), + (Unbound, + ERROR(span, E0000, "Cannot find component " << i << " of " << path); ), (Crate, // TODO: Mangle the original path (or return a new path somehow) -- cgit v1.2.3 From 0eb50366561cd91bed78b3e721e6ea94dbecded1 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Tue, 22 Aug 2017 21:22:09 +0800 Subject: Typecheck/MIR - Some missing EAT invocations --- src/hir_typeck/expr_check.cpp | 12 ++++++++++-- src/mir/helpers.cpp | 7 +++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/hir_typeck/expr_check.cpp b/src/hir_typeck/expr_check.cpp index a5d34186..14cc488c 100644 --- a/src/hir_typeck/expr_check.cpp +++ b/src/hir_typeck/expr_check.cpp @@ -965,8 +965,16 @@ namespace { (Constant, auto cb = monomorphise_type_get_cb(sp, &*e.type, &e.trait.m_params, nullptr); ::HIR::TypeRef tmp; - const auto& ty = ( monomorphise_type_needed(ie.m_type) ? tmp = monomorphise_type_with(sp, ie.m_type, cb) : ie.m_type ); - check_types_equal(sp, node.m_res_type, ty); + const ::HIR::TypeRef* typ; + if(monomorphise_type_needed(ie.m_type)) { + tmp = monomorphise_type_with(sp, ie.m_type, cb); + m_resolve.expand_associated_types(sp, tmp); + typ = &tmp; + } + else { + typ = &ie.m_type; + } + check_types_equal(sp, node.m_res_type, *typ); ), (Static, TODO(sp, "Monomorpise associated static type - " << ie.m_type); diff --git a/src/mir/helpers.cpp b/src/mir/helpers.cpp index b90f3cf6..10c9c780 100644 --- a/src/mir/helpers.cpp +++ b/src/mir/helpers.cpp @@ -287,8 +287,11 @@ const ::HIR::TypeRef& MIR::TypeResolve::get_param_type(::HIR::TypeRef& tmp, cons auto v = m_resolve.get_value(this->sp, e.p, p, /*signature_only=*/true); if( const auto* ve = v.opt_Constant() ) { const auto& ty = (*ve)->m_type; - if( monomorphise_type_needed(ty) ) - MIR_TODO(*this, "get_const_type - Monomorphise type " << ty); + if( monomorphise_type_needed(ty) ) { + auto rv = p.monomorph(this->sp, ty); + m_resolve.expand_associated_types(this->sp, rv); + return rv; + } else return ty.clone(); } -- cgit v1.2.3 From 71b1ed79d938a40b7b1c5824674814fe31d78dac Mon Sep 17 00:00:00 2001 From: John Hodge Date: Tue, 22 Aug 2017 21:22:41 +0800 Subject: minicargo - Handle libraries in build script, add libstd/libunwind script files --- script-overrides/stable-1.19.0/build_std.txt | 5 +++++ script-overrides/stable-1.19.0/build_unwind.txt | 1 + tools/minicargo/manifest.cpp | 9 ++++++++- 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 script-overrides/stable-1.19.0/build_std.txt create mode 100644 script-overrides/stable-1.19.0/build_unwind.txt diff --git a/script-overrides/stable-1.19.0/build_std.txt b/script-overrides/stable-1.19.0/build_std.txt new file mode 100644 index 00000000..062afd95 --- /dev/null +++ b/script-overrides/stable-1.19.0/build_std.txt @@ -0,0 +1,5 @@ +# TODO: THis is the windows set +cargo:rustc-link-lib=advapi32 +cargo:rustc-link-lib=ws2_32 +cargo:rustc-link-lib=userenv +cargo:rustc-link-lib=shell32 \ No newline at end of file diff --git a/script-overrides/stable-1.19.0/build_unwind.txt b/script-overrides/stable-1.19.0/build_unwind.txt new file mode 100644 index 00000000..aba1574a --- /dev/null +++ b/script-overrides/stable-1.19.0/build_unwind.txt @@ -0,0 +1 @@ +# On both windows (MSVC) and linux (glibc), nothing is needed \ No newline at end of file diff --git a/tools/minicargo/manifest.cpp b/tools/minicargo/manifest.cpp index aab0adac..4e7ec305 100644 --- a/tools/minicargo/manifest.cpp +++ b/tools/minicargo/manifest.cpp @@ -343,7 +343,14 @@ void PackageManifest::load_build_script(const ::std::string& path) // cargo:rustc-link-lib=mysql else if( key == "rustc-link-lib" ) { // TODO: Check for an = (otherwise default to dynamic) - throw ::std::runtime_error("TODO: rustc-link-lib"); + ::std::string lazy = value; + auto pos = lazy.find_first_of('='); + if(pos == ::std::string::npos) { + rv.rustc_link_lib.push_back(::std::make_pair("static", lazy)); + } + else { + throw ::std::runtime_error("TODO: rustc-link-lib"); + } } // cargo:rustc-cfg=foo else if( key == "rustc-cfg" ) { -- cgit v1.2.3