Subject: Re: [bug#38110] [PATCH core-updates v3] gnu: rust: Bootstrap [email-masked] by [email-masked].

From: Marius Bakke <[email-masked]>
Date: Fri, 20 Mar 2020 17:11:55 +0100

Danny Milosavljevic <[email-masked]> writes:

> * gnu/packages/patches/rustc-1.29.0-src.patch: New file.
> * gnu/local.mk (dist_patch_DATA): Add it.
> * gnu/packages/rust.scm (rust-1.19): Delete variable.
> (rust-1.20): Delete variable.
> (rust-1.21): Delete variable.
> (rust-1.22): Delete variable.
> (rust-1.23): Delete variable.
> (rust-1.24): Delete variable.
> (rust-1.25): Delete variable.
> (rust-1.26): Delete variable.
> (rust-1.27): Delete variable.
> (rust-1.28): Delete variable.
> (rust-1.29): Bootstrap from mrustc.
> [source]: Add patch.
> (rust-1.30)[inputs]: Remove llvm 3.  Add llvm 6.
> (mrustc): Update rustc-version to 1.29.0.

Thanks a lot for this work Danny!

I was able to get one step further by hacking the mrustc compiler to
force "group linking" with --start-group and --end-group, based on a
suggestion in #mrustc.  It makes the compiler about 10x slower, but
I suppose that's okay for a one-time job.

Now the build fails when trying to use the built rustc binary, and I'm
struggling to figure out how to proceed.  I think we are pretty close!

I've attached my changes as a diff here.  Some of the changes are purely
cosmetic, feel free to pick-and-choose what you want/need.

Without further ado...

2 files changed, 26 insertions(+), 5 deletions(-)
gnu/packages/patches/mrustc-group-link.patch | 22 ++++++++++++++++++++++
gnu/packages/rust.scm                        |  9 ++++-----

new file   gnu/packages/patches/mrustc-group-link.patch
@@ -0,0 +1,22 @@
+Surround the libraries with --start-group and --end-group to work
+around <https://github.com/thepowersgang/mrustc/issues/138>.
+
+diff --git a/src/trans/codegen_c.cpp b/src/trans/codegen_c.cpp
+--- a/src/trans/codegen_c.cpp
++++ b/src/trans/codegen_c.cpp
+@@ -960,6 +960,7 @@ namespace {
+                     {
+                         args.push_back("-L"); args.push_back(path);
+                     }
++                    args.push_back("-Wl,--start-group");
+                     for(const auto& lib : m_crate.m_ext_libs) {
+                         ASSERT_BUG(Span(), lib.name != "", "");
+                         args.push_back("-l"); args.push_back(lib.name.c_str());
+@@ -975,6 +976,7 @@ namespace {
+                     {
+                         args.push_back("-l"); args.push_back(path.c_str());
+                     }
++                    args.push_back("-Wl,--end-group");
+                     for( const auto& a : Target_GetCurSpec().m_backend_c.m_linker_opts )
+                     {
+                         args.push_back( a.c_str() );
modified   gnu/packages/rust.scm
@@ -98,6 +98,7 @@
                       (url "https://github.com/thepowersgang/mrustc.git")
                       (commit (string-append "v" version))))
                 (file-name (git-file-name name version))
+                (patches (search-patches "mrustc-group-link.patch"))
                 (sha256
                  (base32
                   "194ny7vsks5ygiw7d8yxjmp1qwigd71ilchis6xjl6bb2sj97rd2"))))
@@ -128,10 +129,8 @@
            (add-after 'patch-date 'unpack-target-compiler
              (lambda* (#:key inputs outputs #:allow-other-keys)
                (invoke "tar" "xf" (assoc-ref inputs "rustc"))
-               (chdir ,(string-append "rustc-" rustc-version "-src"))
-               (invoke "patch" "-p0" ,(string-append "../rustc-" rustc-version
+               (invoke "patch" "-p1" ,(string-append "rustc-" rustc-version
                                                      "-src.patch"))
-               (chdir "..")
                (setenv "RUSTC_VERSION" ,rustc-version)
                (setenv "MRUSTC_TARGET_VER"
                 ,(version-major+minor rustc-version))
@@ -274,7 +273,7 @@ safety and thread safety guarantees.")
              #t))
          ;; This phase is overridden by newer versions.
          (replace 'configure
-           (lambda* (#:key inputs outputs #:allow-other-keys)
+           (lambda _
              (setenv "CXX" "g++")
              (setenv "HOST_CXX" "g++")
              #t))
@@ -326,7 +325,7 @@ safety and thread safety guarantees.")
                             (write name)
                             (newline)
                             (apply invoke
-                                   "output/rustc-build/rustc"
+                                   "output/rustc-build/rustc_binary"
                                    "-C" (string-append "linker="
                                                        (getenv "CC"))
                                    ;; Required for libterm.

[back]