summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJohn Hodge <tpg@ucc.asn.au>2017-08-23 18:00:49 +0800
committerJohn Hodge <tpg@ucc.asn.au>2017-08-23 18:00:49 +0800
commit185959964b6f1e9f1b67d4eb8b2d1932096e2de2 (patch)
tree8c0535a0f8fb6e4779d65b9866525cb91394a689 /tools
parent5d5f01ccf4ca176074af54dc73b8419ccf4d2ae2 (diff)
parent71b1ed79d938a40b7b1c5824674814fe31d78dac (diff)
downloadmrust-185959964b6f1e9f1b67d4eb8b2d1932096e2de2.tar.gz
Merge branch 'master' of https://github.com/thepowersgang/mrustc
Diffstat (limited to 'tools')
-rw-r--r--tools/minicargo/build.cpp114
-rw-r--r--tools/minicargo/main.cpp13
-rw-r--r--tools/minicargo/manifest.cpp17
3 files changed, 128 insertions, 16 deletions
diff --git a/tools/minicargo/build.cpp b/tools/minicargo/build.cpp
index b4e736d2..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<const char*>& 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<bool> 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());
}
@@ -81,6 +111,43 @@ class Builder
}
};
+ struct Timestamp
+ {
+#if _WIN32
+ uint64_t m_val;
+
+ Timestamp(FILETIME ft):
+ m_val( (static_cast<uint64_t>(ft.dwHighDateTime) << 32) | static_cast<uint64_t>(ft.dwLowDateTime) )
+ {
+ }
+#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 {
+ return m_val == x.m_val;
+ }
+ bool operator<(const Timestamp& x) const {
+ return m_val < x.m_val;
+ }
+
+ friend ::std::ostream& operator<<(::std::ostream& os, const Timestamp& x) {
+#if _WIN32
+ os << ::std::hex << x.m_val << ::std::dec;
+#else
+ os << x.m_val;
+#endif
+ return os;
+ }
+ };
+
::helpers::path m_build_script_overrides;
public:
@@ -96,10 +163,16 @@ 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)
+#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;
@@ -113,8 +186,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) )
@@ -181,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:
@@ -191,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 == 0/*Timestamp::infinite_past()*/ ) {
+ 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)
@@ -290,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;
@@ -348,18 +424,32 @@ 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, 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;
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;
diff --git a/tools/minicargo/manifest.cpp b/tools/minicargo/manifest.cpp
index 60594303..4e7ec305 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;
}
@@ -335,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" ) {