summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2018-01-28 19:19:30 +0800
committerJohn Hodge <tpg@mutabah.net>2018-01-28 19:19:30 +0800
commitc4d7dfa0b6bb64924368f2eb73e12a2962183c22 (patch)
tree766c0e77a5296bef7b1fb10fd9486a28a337d148
parent976944f05ff7053fdcf7a9db055e0588dc5a1dd8 (diff)
downloadmrust-c4d7dfa0b6bb64924368f2eb73e12a2962183c22.tar.gz
All - mingw32 compilation changes
-rw-r--r--Makefile17
-rw-r--r--src/trans/target.cpp6
-rw-r--r--tools/minicargo/Makefile6
-rw-r--r--tools/minicargo/build.cpp42
-rw-r--r--tools/minicargo/debug.cpp11
5 files changed, 67 insertions, 15 deletions
diff --git a/Makefile b/Makefile
index 0cd36b1e..b1d484d8 100644
--- a/Makefile
+++ b/Makefile
@@ -10,7 +10,9 @@
# DEPENDENCIES
# - zlib (-dev)
# - curl (bin, for downloading libstd source)
-
+ifeq ($(OS),Windows_NT)
+ EXESUF ?= .exe
+endif
EXESUF ?=
CXX ?= g++
V ?= @
@@ -115,7 +117,7 @@ OBJ += mir/check_full.o
OBJ += hir/serialise.o hir/deserialise.o hir/serialise_lowlevel.o
OBJ += trans/trans_list.o trans/mangling.o
OBJ += trans/enumerate.o trans/monomorphise.o trans/codegen.o
-OBJ += trans/codegen_c.o trans/codegen_c_structured.o
+OBJ += trans/codegen_c.o trans/codegen_c_structured.o trans/codegen_mmir.o
OBJ += trans/target.o trans/allocator.o
PCHS := ast/ast.hpp
@@ -147,7 +149,7 @@ RUSTC_SRC_DL := $(RUSTCSRC)/dl-version
MAKE_MINICARGO = $(MAKE) -f minicargo.mk RUSTC_VERSION=$(shell cat $(RUSTC_SRC_DES)) RUSTC_CHANNEL=$(RUSTC_SRC_TY)
-output/libstd.hir: $(BIN) $(RUSTC_SRC_DL)
+output/libstd.hir: $(BIN)
$(MAKE_MINICARGO) $@
output/libtest.hir output/libpanic_unwind.hir output/libproc_macro.hir: output/libstd.hir
$(MAKE_MINICARGO) $@
@@ -245,14 +247,14 @@ 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
-output/lib%-test: $(RUSTCSRC)src/lib%/lib.rs $(RUSTC_SRC_DL) $(TEST_DEPS)
+output/lib%-test: $(RUSTCSRC)src/lib%/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%/src/lib.rs $(RUSTC_SRC_DL) $(TEST_DEPS)
+output/lib%-test: $(RUSTCSRC)src/lib%/src/lib.rs $(TEST_DEPS)
@echo "--- [MRUSTC] $@"
@mkdir -p output/
@rm -f $@
@@ -278,7 +280,7 @@ output/rust/test_run-pass_hello_out.txt: output/rust/test_run-pass_hello
#
# TEST: Rust standard library and the "hello, world" run-pass test
#
-test: $(RUSTC_SRC_DL) output/libstd.hir output/rust/test_run-pass_hello_out.txt $(BIN)
+test: output/libstd.hir output/rust/test_run-pass_hello_out.txt $(BIN)
#
# TEST: Attempt to compile rust_os (Tifflin) from ../rust_os
@@ -305,9 +307,12 @@ $(BIN): $(OBJ)
@mkdir -p $(dir $@)
@echo [CXX] -o $@
$V$(CXX) -o $@ $(LINKFLAGS) $(OBJ) $(LIBS)
+ifeq ($(OS),Windows_NT)
+else
objcopy --only-keep-debug $(BIN) $(BIN).debug
objcopy --add-gnu-debuglink=$(BIN).debug $(BIN)
strip $(BIN)
+endif
$(OBJDIR)%.o: src/%.cpp
@mkdir -p $(dir $@)
diff --git a/src/trans/target.cpp b/src/trans/target.cpp
index 28d874e5..b67bc0ea 100644
--- a/src/trans/target.cpp
+++ b/src/trans/target.cpp
@@ -616,12 +616,12 @@ namespace {
}
}
} break;
- TU_ARM(ty.m_data, Borrow, te) {
+ TU_ARM(ty.m_data, Borrow, _te) { (void)_te;
out_path.sub_fields.push_back(0);
Target_GetSizeOf(sp, resolve, ty, out_path.size);
return true;
} break;
- TU_ARM(ty.m_data, Function, _te)
+ TU_ARM(ty.m_data, Function, _te) (void)_te;
out_path.sub_fields.push_back(0);
Target_GetSizeOf(sp, resolve, ty, out_path.size);
return true;
@@ -800,7 +800,7 @@ namespace {
{
vals.push_back(v.val);
}
- rv.variants = TypeRepr::VariantMode::make_Values({ 0, rv.size, ::std::move(vals) });
+ rv.variants = TypeRepr::VariantMode::make_Values({ { 0, static_cast<uint8_t>(rv.size), {} }, ::std::move(vals) });
}
} break;
}
diff --git a/tools/minicargo/Makefile b/tools/minicargo/Makefile
index 336b2410..71e266b0 100644
--- a/tools/minicargo/Makefile
+++ b/tools/minicargo/Makefile
@@ -3,12 +3,16 @@
# - Interprets Cargo.toml files and emits makefiles
# - Supports overriding build script output
#
+ifeq ($(OS),Windows_NT)
+ EXESUF ?= .exe
+endif
+EXESUF ?=
V ?= @
OBJDIR := .obj/
-BIN := ../bin/minicargo
+BIN := ../bin/minicargo$(EXESUF)
OBJS := main.o build.o manifest.o repository.o
OBJS += toml.o path.o debug.o
diff --git a/tools/minicargo/build.cpp b/tools/minicargo/build.cpp
index 143b4ebd..d7a8143e 100644
--- a/tools/minicargo/build.cpp
+++ b/tools/minicargo/build.cpp
@@ -5,9 +5,18 @@
* build.cpp
* - Logic related to invoking the compiler
*/
-#ifdef _WIN32
+#ifdef _MSC_VER
# define _CRT_SECURE_NO_WARNINGS // Allows use of getenv (this program doesn't set env vars)
#endif
+
+#if defined(__MINGW32__)
+# define DISABLE_MULTITHREAD // Mingw32 doesn't have c++11 threads
+// Mingw doesn't define putenv()
+extern "C" {
+extern int _putenv_s(const char*, const char*);
+}
+#endif
+
#include "manifest.h"
#include "build.h"
#include "debug.h"
@@ -16,9 +25,11 @@
#include <algorithm>
#include <sstream> // stringstream
#include <cstdlib> // setenv
-#include <thread>
-#include <mutex>
-#include <condition_variable>
+#ifndef DISABLE_MULTITHREAD
+# include <thread>
+# include <mutex>
+# include <condition_variable>
+#endif
#include <climits>
#include <cassert>
#ifdef _WIN32
@@ -34,7 +45,12 @@
#ifdef _WIN32
# define EXESUF ".exe"
-# define HOST_TARGET "x86_64-windows-msvc"
+# ifdef _MSC_VER
+# define HOST_TARGET "x86_64-windows-msvc"
+# elif defined(__MINGW32__)
+# define HOST_TARGET "x86_64-windows-gnu"
+# else
+# endif
#else
# define EXESUF ""
# define HOST_TARGET "x86_64-unknown-linux-gnu"
@@ -314,6 +330,7 @@ bool BuildList::build(BuildOptions opts, unsigned num_jobs)
// Actually do the build
if( num_jobs > 1 )
{
+#ifndef DISABLE_MULTITHREAD
class Semaphore
{
::std::mutex mutex;
@@ -446,7 +463,18 @@ bool BuildList::build(BuildOptions opts, unsigned num_jobs)
{
return false;
}
+#else
+ while( !state.build_queue.empty() )
+ {
+ auto cur = state.get_next();
+ if( ! builder.build_library(*m_list[cur].package, m_list[cur].is_host) )
+ {
+ return false;
+ }
+ state.complete_package(cur, m_list);
+ }
+#endif
}
else if( num_jobs == 1 )
{
@@ -514,7 +542,11 @@ Builder::Builder(BuildOptions opts):
::helpers::path minicargo_path { buf };
minicargo_path.pop_component();
+#ifdef __MINGW32__
+ m_compiler_path = (minicargo_path / "..\\..\\bin\\mrustc.exe").normalise();
+#else
m_compiler_path = minicargo_path / "mrustc.exe";
+#endif
#else
char buf[1024];
size_t s = readlink("/proc/self/exe", buf, sizeof(buf)-1);
diff --git a/tools/minicargo/debug.cpp b/tools/minicargo/debug.cpp
index f6fca62e..a3fb9956 100644
--- a/tools/minicargo/debug.cpp
+++ b/tools/minicargo/debug.cpp
@@ -5,6 +5,9 @@
* debug.cpp
* - Debugging helpers
*/
+#if defined(__MINGW32__)
+# define DISABLE_MULTITHREAD // Mingw32 doesn't have c++11 threads
+#endif
#include <set>
#include <iostream>
#include "debug.h"
@@ -13,7 +16,9 @@
static int giIndentLevel = 0;
static const char* gsDebugPhase = "";
static ::std::set<::std::string> gmDisabledDebug;
+#ifndef DISABLE_MULTITHREAD
static ::std::mutex gDebugLock;
+#endif
void Debug_SetPhase(const char* phase_name)
{
@@ -33,7 +38,9 @@ void Debug_Print(::std::function<void(::std::ostream& os)> cb)
{
if( !Debug_IsEnabled() )
return ;
+#ifndef DISABLE_MULTITHREAD
::std::unique_lock<::std::mutex> _lh { gDebugLock };
+#endif
::std::cout << gsDebugPhase << "- ";
for(auto i = giIndentLevel; i --; )
@@ -45,7 +52,9 @@ void Debug_EnterScope(const char* name, dbg_cb_t cb)
{
if( !Debug_IsEnabled() )
return ;
+#ifndef DISABLE_MULTITHREAD
::std::unique_lock<::std::mutex> _lh { gDebugLock };
+#endif
::std::cout << gsDebugPhase << "- ";
for(auto i = giIndentLevel; i --; )
@@ -59,7 +68,9 @@ void Debug_LeaveScope(const char* name, dbg_cb_t cb)
{
if( !Debug_IsEnabled() )
return ;
+#ifndef DISABLE_MULTITHREAD
::std::unique_lock<::std::mutex> _lh { gDebugLock };
+#endif
::std::cout << gsDebugPhase << "- ";
giIndentLevel --;