* [PATCH] Fix rust on *-w64-mingw32 @ 2024-04-25 11:16 LIU Hao 2024-04-25 11:19 ` Jakub Jelinek 2024-04-26 10:47 ` Arthur Cohen 0 siblings, 2 replies; 5+ messages in thread From: LIU Hao @ 2024-04-25 11:16 UTC (permalink / raw) To: gcc-rust@gcc.gnu.org [-- Attachment #1.1.1: Type: text/plain, Size: 270 bytes --] Hello, Attached is a patch for fixing build issues on *-w64-mingw32. Please check and update at your leisure. 'gcc/system.h' contains a macro called `mkdir()` and there is no need to invoke `_mkdir()` within a conditional block. -- Best regards, LIU Hao [-- Attachment #1.1.2: gcc_master_rust.patch --] [-- Type: text/plain, Size: 1870 bytes --] diff --git a/gcc/rust/checks/errors/borrowck/rust-borrow-checker.cc b/gcc/rust/checks/errors/borrowck/rust-borrow-checker.cc index 5daa7eb8ded..aff0c372789 100644 --- a/gcc/rust/checks/errors/borrowck/rust-borrow-checker.cc +++ b/gcc/rust/checks/errors/borrowck/rust-borrow-checker.cc @@ -28,13 +28,7 @@ void mkdir_wrapped (const std::string &dirname) { int ret; -#ifdef _WIN32 - ret = _mkdir (dirname.c_str ()); -#elif unix ret = mkdir (dirname.c_str (), 0775); -#elif __APPLE__ - ret = mkdir (dirname.c_str (), 0775); -#endif (void) ret; } diff --git a/gcc/rust/expand/rust-proc-macro.cc b/gcc/rust/expand/rust-proc-macro.cc index 09680733e98..3518bffaf03 100644 --- a/gcc/rust/expand/rust-proc-macro.cc +++ b/gcc/rust/expand/rust-proc-macro.cc @@ -102,6 +102,7 @@ static_assert ( } // namespace +#ifndef _WIN32 template <typename Symbol, typename Callback> bool register_callback (void *handle, Symbol, std::string symbol_name, @@ -125,6 +126,7 @@ register_callback (void *handle, Symbol, std::string symbol_name, #define REGISTER_CALLBACK(HANDLE, SYMBOL, CALLBACK) \ register_callback (HANDLE, SYMBOL, #SYMBOL, CALLBACK) +#endif // _WIN32 const ProcMacro::ProcmacroArray * load_macros_array (std::string path) diff --git a/gcc/rust/parse/rust-parse.cc b/gcc/rust/parse/rust-parse.cc index 504a409cc4d..b78ac524f61 100644 --- a/gcc/rust/parse/rust-parse.cc +++ b/gcc/rust/parse/rust-parse.cc @@ -89,7 +89,7 @@ extract_module_path (const AST::AttrVec &inner_attrs, // 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; [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 840 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix rust on *-w64-mingw32 2024-04-25 11:16 [PATCH] Fix rust on *-w64-mingw32 LIU Hao @ 2024-04-25 11:19 ` Jakub Jelinek 2024-04-26 10:47 ` Arthur Cohen 1 sibling, 0 replies; 5+ messages in thread From: Jakub Jelinek @ 2024-04-25 11:19 UTC (permalink / raw) To: LIU Hao; +Cc: gcc-rust@gcc.gnu.org On Thu, Apr 25, 2024 at 07:16:31PM +0800, LIU Hao via Gcc wrote: > --- a/gcc/rust/parse/rust-parse.cc > +++ b/gcc/rust/parse/rust-parse.cc > @@ -89,7 +89,7 @@ extract_module_path (const AST::AttrVec &inner_attrs, > // 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(), '/', '\\'); This should be std::replace (path.begin (), path.end (), '/', '\\'); (at least if gcc/rust/ follows normal GCC coding conventions). Jakub ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix rust on *-w64-mingw32 2024-04-25 11:16 [PATCH] Fix rust on *-w64-mingw32 LIU Hao 2024-04-25 11:19 ` Jakub Jelinek @ 2024-04-26 10:47 ` Arthur Cohen 2024-04-26 11:14 ` LIU Hao 1 sibling, 1 reply; 5+ messages in thread From: Arthur Cohen @ 2024-04-26 10:47 UTC (permalink / raw) To: lh_mouse; +Cc: gcc Hello, Thanks a lot for the patch :) I agree with Jakub that we should be using the GNU coding style in our call to std::replace - this is what we try to enforce in the rest of the Rust frontend. Regarding the changes to `mkdir_wrapped`, the function now looks a bit odd: void mkdir_wrapped (const std::string &dirname) { int ret; ret = mkdir (dirname.c_str (), 0775); (void) ret; } could you change it to something simpler like simply ignoring the return value of `mkdir`? since this is what we are already doing (and we should improve error handling here... but one battle at a time). I would suggest the following: void mkdir_wrapped (const std::string &dirname) { mkdir (dirname.c_str (), 0775); } Have you run the testsuite on *-w64-mingw32? I'm wondering if commenting out the `register_callback` function causes any issues there? All in all I'm in favor of this patch, and thanks for submitting it :) Best, Arthur ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix rust on *-w64-mingw32 2024-04-26 10:47 ` Arthur Cohen @ 2024-04-26 11:14 ` LIU Hao 2024-04-27 15:57 ` LIU Hao 0 siblings, 1 reply; 5+ messages in thread From: LIU Hao @ 2024-04-26 11:14 UTC (permalink / raw) To: Arthur Cohen; +Cc: gcc [-- Attachment #1.1: Type: text/plain, Size: 983 bytes --] 在 2024-04-26 18:47, Arthur Cohen 写道: > Hello, > > Thanks a lot for the patch :) > > I agree with Jakub that we should be using the GNU coding style in our call to std::replace - this > is what we try to enforce in the rest of the Rust frontend. Please feel welcome to rewrite the patch as necessary. It was sent only for illustration about the build issues. > could you change it to something simpler like simply ignoring the return value of `mkdir`? since > this is what we are already doing (and we should improve error handling here... but one battle at a > time). I don't know why there is such a function. It might be better to just replace it with direct calls to `mkdir()`. > Have you run the testsuite on *-w64-mingw32? I'm wondering if commenting out the `register_callback` > function causes any issues there? No. I only bootstrapped GCC itself with Rust enabled. I know nothing about Rust. -- Best regards, LIU Hao [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 840 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix rust on *-w64-mingw32 2024-04-26 11:14 ` LIU Hao @ 2024-04-27 15:57 ` LIU Hao 0 siblings, 0 replies; 5+ messages in thread From: LIU Hao @ 2024-04-27 15:57 UTC (permalink / raw) To: Arthur Cohen; +Cc: gcc, gcc-rust [-- Attachment #1.1.1: Type: text/plain, Size: 245 bytes --] Attached is an alternative patch to functionalize `load_macros_array`. It allows GCC to build on x86_64-w64-mingw32. Not tested though, as I know no Rust. As before, please edit the patch at your disposal. -- Best regards, LIU Hao [-- Attachment #1.1.2: 0100-rust-fix.patch --] [-- Type: text/plain, Size: 4122 bytes --] diff --git a/gcc/rust/checks/errors/borrowck/rust-borrow-checker.cc b/gcc/rust/checks/errors/borrowck/rust-borrow-checker.cc index 5daa7eb8ded..9991e4b14f3 100644 --- a/gcc/rust/checks/errors/borrowck/rust-borrow-checker.cc +++ b/gcc/rust/checks/errors/borrowck/rust-borrow-checker.cc @@ -24,20 +24,6 @@ namespace Rust { namespace HIR { -void -mkdir_wrapped (const std::string &dirname) -{ - int ret; -#ifdef _WIN32 - ret = _mkdir (dirname.c_str ()); -#elif unix - ret = mkdir (dirname.c_str (), 0775); -#elif __APPLE__ - ret = mkdir (dirname.c_str (), 0775); -#endif - (void) ret; -} - void dump_function_bir (const std::string &filename, BIR::Function &func, const std::string &name) @@ -61,7 +47,7 @@ BorrowChecker::go (HIR::Crate &crate) if (enable_dump_bir) { - mkdir_wrapped ("bir_dump"); + mkdir ("bir_dump", 0755); auto mappings = Analysis::Mappings::get (); bool ok = mappings->get_crate_name (crate.get_mappings ().get_crate_num (), diff --git a/gcc/rust/expand/rust-proc-macro.cc b/gcc/rust/expand/rust-proc-macro.cc index 09680733e98..d658b4d10db 100644 --- a/gcc/rust/expand/rust-proc-macro.cc +++ b/gcc/rust/expand/rust-proc-macro.cc @@ -22,7 +22,10 @@ #include "rust-token-converter.h" #include "rust-attributes.h" -#ifndef _WIN32 +#ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN +#include <windows.h> +#else #include <dlfcn.h> #endif @@ -102,12 +105,16 @@ static_assert ( } // namespace -template <typename Symbol, typename Callback> +template <typename Handle, typename Symbol, typename Callback> bool -register_callback (void *handle, Symbol, std::string symbol_name, +register_callback (Handle handle, Symbol, std::string symbol_name, Callback callback) { +#ifdef _WIN32 + FARPROC addr = GetProcAddress (handle, symbol_name.c_str ()); +#else void *addr = dlsym (handle, symbol_name.c_str ()); +#endif if (addr == nullptr) { rust_error_at (UNDEF_LOCATION, @@ -129,7 +136,18 @@ register_callback (void *handle, Symbol, std::string symbol_name, const ProcMacro::ProcmacroArray * load_macros_array (std::string path) { -#ifndef _WIN32 +#ifdef _WIN32 + HMODULE handle = LoadLibraryA (path.c_str ()); + // We're leaking the handle since we can't ever unload it + if (!handle) + { + char msg[300]; + FormatMessageA (FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + nullptr, GetLastError (), 0, msg, sizeof msg, nullptr); + rust_debug ("Error whilst opening procedural macro: %s", msg); + return nullptr; + } +#else void *handle = dlopen (path.c_str (), RTLD_LAZY | RTLD_LOCAL); // We're leaking the handle since we can't ever unload it if (!handle) @@ -137,6 +155,7 @@ load_macros_array (std::string path) rust_debug ("Error whilst opening procedural macro: %s", dlerror ()); return nullptr; } +#endif if (!REGISTER_CALLBACK (handle, __gccrs_proc_macro_ts_from_str_, tokenstream_from_string)) @@ -153,12 +172,12 @@ load_macros_array (std::string path) auto symbol_name = generate_proc_macro_decls_symbol (0 /* FIXME */); return *reinterpret_cast<const ProcMacro::ProcmacroArray **> ( - dlsym (handle, symbol_name.c_str ())); +#ifdef _WIN32 + GetProcAddress (handle, symbol_name.c_str ()) #else - rust_sorry_at (UNDEF_LOCATION, - "Procedural macros are not yet supported on windows host"); - rust_unreachable (); + dlsym (handle, symbol_name.c_str ()) #endif + ); } #undef REGISTER_CALLBACK diff --git a/gcc/rust/parse/rust-parse.cc b/gcc/rust/parse/rust-parse.cc index 504a409cc4d..634ad0bf0c8 100644 --- a/gcc/rust/parse/rust-parse.cc +++ b/gcc/rust/parse/rust-parse.cc @@ -89,7 +89,7 @@ extract_module_path (const AST::AttrVec &inner_attrs, // 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; [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 840 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-04-27 15:58 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2024-04-25 11:16 [PATCH] Fix rust on *-w64-mingw32 LIU Hao 2024-04-25 11:19 ` Jakub Jelinek 2024-04-26 10:47 ` Arthur Cohen 2024-04-26 11:14 ` LIU Hao 2024-04-27 15:57 ` LIU Hao
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).