Rust-GCC / gccrs

GCC Front-End for Rust
https://rust-gcc.github.io/
GNU General Public License v2.0
2.31k stars 144 forks source link

Fails to build on MinGW-w64 #2843

Open MehdiChinoune opened 4 months ago

MehdiChinoune commented 4 months ago

I tried to build gcc-14 with rust enabled, but It fails to build. It needs some changes to build

1 -

--- a/gcc/rust/checks/errors/borrowck/rust-borrow-checker.cc
+++ b/gcc/rust/checks/errors/borrowck/rust-borrow-checker.cc
@@ -20,6 +20,11 @@
 #include "rust-function-collector.h"
 #include "rust-bir-builder.h"
 #include "rust-bir-dump.h"
+
+#ifdef _WIN32
+#define NO_OLDNAMES
+#include <direct.h>
+#endif

 namespace Rust {
 namespace HIR {

to recognize _mkdir function

2 -

--- a/gcc/rust/expand/rust-proc-macro.cc
+++ b/gcc/rust/expand/rust-proc-macro.cc
@@ -102,6 +102,7 @@

 } // namespace

+#ifndef _WIN32
 template <typename Symbol, typename Callback>
 bool
 register_callback (void *handle, Symbol, std::string symbol_name,
@@ -125,6 +126,7 @@

 #define REGISTER_CALLBACK(HANDLE, SYMBOL, CALLBACK)                            \
   register_callback (HANDLE, SYMBOL, #SYMBOL, CALLBACK)
+#endif

 const ProcMacro::ProcmacroArray *
 load_macros_array (std::string path)

dlsym is a posix function, so it doesn't exist on Windows.

3 -

--- a/gcc/rust/parse/rust-parse.cc
+++ b/gcc/rust/parse/rust-parse.cc
@@ -89,7 +89,7 @@
   // Source: rustc compiler
   // (https://github.com/rust-lang/rust/blob/9863bf51a52b8e61bcad312f81b5193d53099f9f/compiler/rustc_expand/src/module.rs#L174)
 #if defined(HAVE_DOS_BASED_FILE_SYSTEM)
-  path.replace ('/', '\\');
+  std::replace (path.begin(), path.end(), '/', '\\');
 #endif /* HAVE_DOS_BASED_FILE_SYSTEM */

   return path;

gcc doesn't accept path.replace ('/', '\\')

lhmouse commented 2 months ago

Proposed patch: https://github.com/lhmouse/MINGW-packages/blob/5859d27b2b6101204a08ad9702cb2937f8797be9/mingw-w64-gcc/0100-rust-fix.patch

P-E-P commented 2 months ago

I've been trying to set up a CI in #2979, there is a small problem remaining but when it'll be merged this should'nt happen anymore.