summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2019-02-23 12:33:35 +0800
committerJohn Hodge <tpg@mutabah.net>2019-02-23 12:33:35 +0800
commit0158e0e303cf2b9ba38a8e482df9bacb4fd4c779 (patch)
treec7cf3d8d0c7492b425bf94fd9b4d8eefecea9794
parent80c2add7b04e6e202d9a4f3b3c25ec498e3b5893 (diff)
parent7d728e447d70d79e93c01a7c51efbd61be09d68f (diff)
downloadmrust-0158e0e303cf2b9ba38a8e482df9bacb4fd4c779.tar.gz
Merge branch 'master' of ssh://github.com/thepowersgang/mrustc
-rw-r--r--Makefile8
-rw-r--r--README.md3
-rw-r--r--appveyor.yml19
-rw-r--r--src/expand/proc_macro.cpp2
-rw-r--r--src/hir/hir.cpp4
-rw-r--r--src/trans/codegen_mmir.cpp24
-rw-r--r--src/trans/target.cpp16
-rw-r--r--tools/common/path.h7
-rw-r--r--tools/common/target_detect.h9
-rw-r--r--tools/minicargo/build.cpp48
-rw-r--r--tools/minicargo/manifest.cpp14
11 files changed, 122 insertions, 32 deletions
diff --git a/Makefile b/Makefile
index 23c799d2..2ef88f9e 100644
--- a/Makefile
+++ b/Makefile
@@ -236,6 +236,7 @@ LIB_TESTS := collections #std
rust_tests-libs: $(patsubst %,output/lib%-test_out.txt, $(LIB_TESTS))
RUNTIME_ARGS_output/libcollections-test := --test-threads 1
+#RUNTIME_ARGS_output/libcore-test := --test-threads 1
RUNTIME_ARGS_output/libstd-test := --test-threads 1
RUNTIME_ARGS_output/libstd-test += --skip ::collections::hash::map::test_map::test_index_nonexistent
RUNTIME_ARGS_output/libstd-test += --skip ::collections::hash::map::test_map::test_drops
@@ -243,6 +244,13 @@ RUNTIME_ARGS_output/libstd-test += --skip ::collections::hash::map::test_map::te
RUNTIME_ARGS_output/libstd-test += --skip ::collections::hash::map::test_map::test_placement_panic
RUNTIME_ARGS_output/libstd-test += --skip ::io::stdio::tests::panic_doesnt_poison # Unbounded execution
+output/libcore-test: $(RUSTCSRC)src/libcore/tests/lib.rs $(TEST_DEPS)
+ @echo "--- [MRUSTC] --test -o $@"
+ @mkdir -p output/
+ @rm -f $@
+ $(DBG) $(ENV_$@) $(BIN) --test $< -o $@ $(RUST_FLAGS) $(ARGS_$@) $(PIPECMD)
+# # HACK: Work around gdb returning success even if the program crashed
+ @test -e $@
output/lib%-test: $(RUSTCSRC)src/lib%/lib.rs $(TEST_DEPS)
@echo "--- [MRUSTC] --test -o $@"
@mkdir -p output/
diff --git a/README.md b/README.md
index bbc34fb6..d17ef42b 100644
--- a/README.md
+++ b/README.md
@@ -2,6 +2,9 @@ Mutabah's Rust Compiler
_In-progress_ alternative rust compiler. Capable of building a fully-working copy of rustc, but not yet suitable for everyday use.
+[![Build Status: windows](https://ci.appveyor.com/api/projects/status/96y4ui20pl8xjm2h/branch/master?svg=true)](https://ci.appveyor.com/project/thepowersgang/mrustc/branch/master)
+[![Build Status: Linux/OSX](https://travis-ci.org/thepowersgang/mrustc.svg?branch=master)](https://travis-ci.org/thepowersgang/mrustc)
+
Intro
===
This project is an attempt at creating a simple rust compiler in C++, with the ultimate goal of being a separate re-implementation.
diff --git a/appveyor.yml b/appveyor.yml
new file mode 100644
index 00000000..3f3f52f0
--- /dev/null
+++ b/appveyor.yml
@@ -0,0 +1,19 @@
+version: 1.0.{build}
+
+configuration: Release
+platform: x64
+
+before_build:
+- cmd: nuget restore vsproject/mrustc.sln
+
+build:
+ project: vsproject/mrustc.sln
+ verbosity: minimal
+
+test_script:
+# - Download/extract rust 1.19.0
+- appveyor DownloadFile https://static.rust-lang.org/dist/rustc-1.19.0-src.tar.gz
+- tar xzf rustc-1.19.0-src.tar.gz
+- cmd: cd vsproject
+- cmd: call build_std.cmd
+- cmd: call run_hello.cmd
diff --git a/src/expand/proc_macro.cpp b/src/expand/proc_macro.cpp
index 3f26c648..b61851b3 100644
--- a/src/expand/proc_macro.cpp
+++ b/src/expand/proc_macro.cpp
@@ -977,7 +977,7 @@ uint64_t ProcMacroInv::recv_v128u()
for(;;)
{
auto b = recv_u8();
- v |= static_cast<uint64_t>(b) << ofs;
+ v |= static_cast<uint64_t>(b & 0x7F) << ofs;
if( (b & 0x80) == 0 )
break;
ofs += 7;
diff --git a/src/hir/hir.cpp b/src/hir/hir.cpp
index 9f9bc1c3..5d67ac5f 100644
--- a/src/hir/hir.cpp
+++ b/src/hir/hir.cpp
@@ -450,7 +450,9 @@ namespace {
),
(Function,
TU_IFLET(::HIR::TypeRef::Data, right.m_data, Function, re,
- TODO(sp, "Function");
+ if( left == right )
+ return ::OrdEqual;
+ TODO(sp, "Function - " << left << " and " << right);
//return typelist_ord_specific(sp, le.arg_types, re.arg_types);
)
else {
diff --git a/src/trans/codegen_mmir.cpp b/src/trans/codegen_mmir.cpp
index b2c5282a..73de19d3 100644
--- a/src/trans/codegen_mmir.cpp
+++ b/src/trans/codegen_mmir.cpp
@@ -18,6 +18,14 @@
namespace
{
+ size_t Target_GetSizeOf_Required(const Span& sp, const StaticTraitResolve& resolve, const ::HIR::TypeRef& ty)
+ {
+ size_t size;
+ bool type_has_size = Target_GetSizeOf(sp, resolve, ty, size);
+ ASSERT_BUG(sp, type_has_size, "Attempting to get the size of a unsized type");
+ return size;
+ }
+
template<typename T>
struct Fmt
{
@@ -324,7 +332,7 @@ namespace
else if( t.m_data.is_Slice() ) {
return ::HIR::CoreType::Usize;
}
- else if( t.m_data.is_TraitObject() ) {
+ else if( t.m_data.is_TraitObject() ) {
const auto& te = t.m_data.as_TraitObject();
//auto vtp = t.m_data.as_TraitObject().m_trait.m_path;
@@ -381,7 +389,7 @@ namespace
{
m_of << "fn " << drop_glue_path << "(&move " << ty << ") {\n";
m_of << "\tlet unit: ();\n";
-
+
if( const auto* ity = m_resolve.is_type_owned_box(ty) )
{
m_of << "\t0: {\n";
@@ -779,8 +787,7 @@ namespace
cur_ofs ++;
}
emit_literal_as_bytes(le[i], repr->fields[i].ty, out_relocations, base_ofs + cur_ofs);
- size_t size;
- assert(Target_GetSizeOf(sp, m_resolve, repr->fields[i].ty, size));
+ size_t size = Target_GetSizeOf_Required(sp, m_resolve, repr->fields[i].ty);
cur_ofs += size;
}
while(cur_ofs < repr->size)
@@ -803,8 +810,7 @@ namespace
emit_literal_as_bytes(*le.val, repr->fields[le.idx].ty, out_relocations, base_ofs + cur_ofs);
- size_t size;
- assert(Target_GetSizeOf(sp, m_resolve, repr->fields[le.idx].ty, size));
+ size_t size = Target_GetSizeOf_Required(sp, m_resolve, repr->fields[le.idx].ty);
cur_ofs += size;
}
@@ -819,8 +825,7 @@ namespace
auto v = ::HIR::Literal::make_Integer(le.idx);
emit_literal_as_bytes(v, repr->fields[ve->field.index].ty, out_relocations, base_ofs + cur_ofs);
- size_t size;
- assert(Target_GetSizeOf(sp, m_resolve, repr->fields[ve->field.index].ty, size));
+ size_t size = Target_GetSizeOf_Required(sp, m_resolve, repr->fields[ve->field.index].ty);
cur_ofs += size;
}
// TODO: Nonzero?
@@ -888,8 +893,7 @@ namespace
for(const auto& v : lit.as_List())
{
emit_literal_as_bytes(v, *te.inner, out_relocations, base_ofs);
- size_t size;
- assert(Target_GetSizeOf(sp, m_resolve, *te.inner, size));
+ size_t size = Target_GetSizeOf(sp, m_resolve, *te.inner, size);
base_ofs += size;
}
} break;
diff --git a/src/trans/target.cpp b/src/trans/target.cpp
index 53d84030..70996fb0 100644
--- a/src/trans/target.cpp
+++ b/src/trans/target.cpp
@@ -42,7 +42,7 @@ const TargetArch ARCH_M68K = {
"m68k",
32, true,
{ /*atomic(u8)=*/true, false, true, false, true },
- TargetArch::Alignments(2, 4, 8, 16, 4, 8, 4) // TODO: Does m68k have lower alignments?
+ TargetArch::Alignments(2, 2, 2, 2, 2, 2, 2)
};
TargetSpec g_target;
@@ -511,6 +511,20 @@ namespace
ARCH_X86_64
};
}
+ else if(target_name == "arm-unknown-haiku")
+ {
+ return TargetSpec {
+ "unix", "haiku", "gnu", {CodegenMode::Gnu11, true, "arm-unknown-haiku", {}, {}},
+ ARCH_ARM32
+ };
+ }
+ else if(target_name == "x86_64-unknown-haiku")
+ {
+ return TargetSpec {
+ "unix", "haiku", "gnu", {CodegenMode::Gnu11, false, "x86_64-unknown-haiku", {}, {}},
+ ARCH_X86_64
+ };
+ }
else
{
::std::cerr << "Unknown target name '" << target_name << "'" << ::std::endl;
diff --git a/tools/common/path.h b/tools/common/path.h
index eae4951f..1ad6f506 100644
--- a/tools/common/path.h
+++ b/tools/common/path.h
@@ -38,6 +38,13 @@ public:
return m_str != "";
}
+ bool operator==(const path& p) const {
+ return m_str == p.m_str;
+ }
+ bool operator!=(const path& p) const {
+ return m_str != p.m_str;
+ }
+
path& operator/=(const path& p)
{
if(!p.is_valid())
diff --git a/tools/common/target_detect.h b/tools/common/target_detect.h
index 0812c363..1bfc7dd9 100644
--- a/tools/common/target_detect.h
+++ b/tools/common/target_detect.h
@@ -75,6 +75,15 @@
// - Apple devices
#elif defined(__APPLE__)
# define DEFAULT_TARGET_NAME "x86_64-apple-macosx"
+// - Haiku
+#elif defined(__HAIKU__)
+# if defined(__x86_64__)
+# define DEFAULT_TARGET_NAME "x86_64-unknown-haiku"
+# elif defined(__arm__)
+# define DEFAULT_TARGET_NAME "arm-unknown-haiku"
+# else
+# warning "Unable to detect a suitable default target (Haiku)"
+# endif
// - Unknown
#else
# warning "Unable to detect a suitable default target"
diff --git a/tools/minicargo/build.cpp b/tools/minicargo/build.cpp
index 6d586893..d074525c 100644
--- a/tools/minicargo/build.cpp
+++ b/tools/minicargo/build.cpp
@@ -63,6 +63,9 @@ class Builder
{
BuildOptions m_opts;
::helpers::path m_compiler_path;
+#ifndef _WIN32
+ mutable ::std::mutex chdir_mutex;
+#endif
public:
Builder(BuildOptions opts);
@@ -74,7 +77,7 @@ public:
private:
::helpers::path get_crate_path(const PackageManifest& manifest, const PackageTarget& target, bool is_for_host, const char** crate_type, ::std::string* out_crate_suffix) const;
bool spawn_process_mrustc(const StringList& args, StringListKV env, const ::helpers::path& logfile) const;
- bool spawn_process(const char* exe_name, const StringList& args, const StringListKV& env, const ::helpers::path& logfile) const;
+ bool spawn_process(const char* exe_name, const StringList& args, const StringListKV& env, const ::helpers::path& logfile, const ::helpers::path& working_directory={}) const;
::helpers::path build_and_run_script(const PackageManifest& manifest, bool is_for_host) const;
@@ -538,6 +541,11 @@ bool BuildList::build(BuildOptions opts, unsigned num_jobs)
Builder::Builder(BuildOptions opts):
m_opts(::std::move(opts))
{
+ if( const char* override_path = getenv("MRUSTC_PATH") ) {
+ m_compiler_path = override_path;
+ return ;
+ }
+ // TODO: Clean this stuff up
#ifdef _WIN32
char buf[1024];
size_t s = GetModuleFileName(NULL, buf, sizeof(buf)-1);
@@ -883,12 +891,7 @@ bool Builder::build_target(const PackageManifest& manifest, const PackageTarget&
}
//auto _ = ScopedChdir { manifest.directory() };
- #if _WIN32
- #else
- auto fd_cwd = open(".", O_DIRECTORY);
- chdir(manifest.directory().str().c_str());
- #endif
- if( !this->spawn_process(script_exe_abs.str().c_str(), {}, env, out_file) )
+ if( !this->spawn_process(script_exe_abs.str().c_str(), {}, env, out_file, /*working_directory=*/manifest.directory()) )
{
::std::cerr << "Calling " << script_exe_abs << " failed" << ::std::endl;
{
@@ -909,12 +912,8 @@ bool Builder::build_target(const PackageManifest& manifest, const PackageTarget&
// Build failed, return an invalid path
return ::helpers::path();
}
- #if _WIN32
- #else
- fchdir(fd_cwd);
- #endif
}
-
+
return out_file;
}
bool Builder::build_library(const PackageManifest& manifest, bool is_for_host) const
@@ -950,7 +949,7 @@ bool Builder::spawn_process_mrustc(const StringList& args, StringListKV env, con
//env.push_back("MRUSTC_DEBUG", "");
return spawn_process(m_compiler_path.str().c_str(), args, env, logfile);
}
-bool Builder::spawn_process(const char* exe_name, const StringList& args, const StringListKV& env, const ::helpers::path& logfile) const
+bool Builder::spawn_process(const char* exe_name, const StringList& args, const StringListKV& env, const ::helpers::path& logfile, const ::helpers::path& working_directory/*={}*/) const
{
#ifdef _WIN32
::std::stringstream cmdline;
@@ -1002,7 +1001,7 @@ bool Builder::spawn_process(const char* exe_name, const StringList& args, const
WriteFile(si.hStdOutput, "\n", 1, &tmp, NULL);
}
PROCESS_INFORMATION pi = { 0 };
- CreateProcessA(exe_name, (LPSTR)cmdline_str.c_str(), NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi);
+ CreateProcessA(exe_name, (LPSTR)cmdline_str.c_str(), NULL, NULL, TRUE, 0, NULL, (working_directory != ::helpers::path() ? working_directory.str().c_str() : NULL), &si, &pi);
CloseHandle(si.hStdOutput);
WaitForSingleObject(pi.hProcess, INFINITE);
DWORD status = 1;
@@ -1066,12 +1065,23 @@ bool Builder::spawn_process(const char* exe_name, const StringList& args, const
// });
envp.push_back(nullptr);
- if( posix_spawn(&pid, exe_name, &fa, /*attr=*/nullptr, (char* const*)argv.data(), (char* const*)envp.get_vec().data()) != 0 )
+ // TODO: Acquire a lock
{
- ::std::cerr << "Unable to run process '" << exe_name << "' - " << strerror(errno) << ::std::endl;
- DEBUG("Unable to spawn executable");
- posix_spawn_file_actions_destroy(&fa);
- return false;
+ ::std::lock_guard<::std::mutex> lh { this->chdir_mutex };
+ auto fd_cwd = open(".", O_DIRECTORY);
+ if( working_directory != ::helpers::path() ) {
+ chdir(working_directory.str().c_str());
+ }
+ if( posix_spawn(&pid, exe_name, &fa, /*attr=*/nullptr, (char* const*)argv.data(), (char* const*)envp.get_vec().data()) != 0 )
+ {
+ ::std::cerr << "Unable to run process '" << exe_name << "' - " << strerror(errno) << ::std::endl;
+ DEBUG("Unable to spawn executable");
+ posix_spawn_file_actions_destroy(&fa);
+ return false;
+ }
+ if( working_directory != ::helpers::path() ) {
+ fchdir(fd_cwd);
+ }
}
posix_spawn_file_actions_destroy(&fa);
int status = -1;
diff --git a/tools/minicargo/manifest.cpp b/tools/minicargo/manifest.cpp
index bbaa24f6..e47da1bc 100644
--- a/tools/minicargo/manifest.cpp
+++ b/tools/minicargo/manifest.cpp
@@ -484,6 +484,20 @@ PackageManifest PackageManifest::load_from_toml(const ::std::string& path)
rv.m_targets.push_back(PackageTarget { PackageTarget::Type::Lib });
}
}
+ // - If there's no binary section, but src/main.rs exists, add as a binary
+ if( ! ::std::any_of(rv.m_targets.begin(), rv.m_targets.end(), [](const auto& x){ return x.m_type == PackageTarget::Type::Bin; }) )
+ {
+ // No library, add one pointing to lib.rs
+ if( ::std::ifstream(package_dir / "src" / "main.rs").good() )
+ {
+ DEBUG("- Implicit binary");
+ rv.m_targets.push_back(PackageTarget { PackageTarget::Type::Bin });
+ }
+ }
+ if( rv.m_targets.empty() )
+ {
+ throw ::std::runtime_error(format("Manifest file ", path, " didn't specify any targets (and src/{main,lib}.rs doesn't exist)"));
+ }
// Default target names
for(auto& tgt : rv.m_targets)