From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Le Bihan Subject: Re: Rust Date: Sat, 30 Jul 2016 13:01:03 +0200 Message-ID: <20160730130103.3859e4ed@itchy> References: <20160325184540.4e02cb2d@scratchpost.org> <87k2kq6wma.fsf@grrlz.net> <87oa8mt8lh.fsf@gmail.com> <87eg9gzgqb.fsf@libertad.pw> <87popyp3od.fsf@we.make.ritual.n0.is> <20160728203144.7df4bb8c@itchy> <87mvl0a302.fsf_-_@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:46415) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bTS17-0005ms-NU for guix-devel@gnu.org; Sat, 30 Jul 2016 07:01:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bTS13-0003kN-H9 for guix-devel@gnu.org; Sat, 30 Jul 2016 07:01:16 -0400 In-Reply-To: <87mvl0a302.fsf_-_@gnu.org> List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: Ludovic =?UTF-8?B?Q291cnTDqHM=?= Cc: guix-devel@gnu.org Le Fri, 29 Jul 2016 17:16:29 +0200, ludo@gnu.org (Ludovic Court=C3=A8s) a =C3=A9crit : > Eric Le Bihan skribis: >=20 > > It happens that I tried to package Rust, as an introduction to Guix. > > Here is my version, inspired by the Haskell package, where Rust > > 1.10.0 is built, bootstrapped by a binary version of rustc 1.9.0. > > It uses the "cc" wrapper trick previously presented. =20 >=20 > As you might have seen from previous discussions, we try hard to > reduce the number of binary blobs needed to bootstrap packages, such > that we have a full source-to-binary path that everyone can audit. > Unfortunately, this usually hard to achieve for self-hosted compilers. >=20 > Do you know what=E2=80=99s Rust=E2=80=99s bootstrapping story is? Can we= reasonably > expect to bootstrap it from source, using a series of previous Rust > versions, or using an alternative implementation? As explained by others, starting with version 1.10.0, Rust version N will be guaranteed to bootstrap with version N-1. > > Some questions, though: > > > > 1. I can compile a sample program in a guix environment created > > using `guix environment gcc glibc binutils rust`, but the program > > generated fails to run because libgcc_s.so.1 can not be found. How > > can it be added to the environment? =20 >=20 > As Andreas notes, =E2=80=98gcc-toolchain=E2=80=99, which includes =E2=80= =98ld-wrapper=E2=80=99, should > fix this. Yes. It solved my problem. =20 > Does Rust use GCC, or just ld? It only uses the linker, i.e. ld on GNU/Linux. > > 2. Having a Rust compiler is cool, but having Cargo, the Rust > > package manager, would be even better. Cargo is also bootstrapped, > > and it is also built using zillions of crates (Rust packages) > > downloaded from the Internet. How could this case be handled in > > Guix? =20 >=20 > Assuming Cargo itself is just a regular Rust program, it should be > possible to make a Guix package of Cargo. Then, Guix users can > install it and use it the normal way; we won=E2=80=99t be able to use Car= go > in package recipes though, because our package build environments > purposefully lacks network access. >=20 > Besides, I would encourage you or anyone interested to write a crate > importer, like we do for most other language packages: >=20 > https://www.gnu.org/software/guix/manual/html_node/Invoking-guix-import= .html >=20 > Having crates available as normal Guix packages is the best option for > Guix users: uniform interface, the ability to use =E2=80=98guix environme= nt=E2=80=99 > and all the tools, transactional upgrade and rollback, etc. IIUC, to provide a Guix package for Cargo, the following should be done: 1. write a crate importer. 2. list all the crates needed by Cargo to build itself. 3. package each crate with the importer. 4. add a Cargo package which depends on the newly-imported crates and uses a binary version of Cargo to bootstrap itself (though this is not the best option in terms of auditing/reproducibility). Unlike Rust, Cargo still uses an "anonymous" binary version of itself for bootstrapping. I hope this may change soon. > > From fb1fbc92cd68331b3dea94c238274f8a01b98afa Mon Sep 17 00:00:00 > > 2001 From: Eric Le Bihan > > Date: Thu, 28 Jul 2016 20:09:01 +0200 > > Subject: [PATCH 1/1] gnu: Add rust > > > > * gnu/packages/rust.scm(rust): New variable. > > > > Signed-off-by: Eric Le Bihan =20 >=20 > Apart from the bootstrapping thing discussed above, this looks good to > me (and a great first package!). >=20 > > + ;; Tell where to find libgcc_s.so > > + (setenv "LD_LIBRARY_PATH" (string-append gcc-lib > > "/lib")) =20 >=20 > =E2=80=9CLIBRARY_PATH=E2=80=9D may be enough. OK. =20 > > + ;; Remove reference to "/lib64/ld-linux-x86-64.so.2" > > from binary > > + (zero? (system* > > + "patchelf" > > + "--set-interpreter" ld-so > > + (string-append (getcwd) "/rustc/bin/rustc"))) =20 >=20 > =E2=80=9Crustc/bin/rustc=E2=80=9D is enough here. OK. >=20 > > + (add-before 'build 'pre-build > > + (lambda _ > > + (let* ((bindir (string-append (getcwd) > > "/bin")) > > + (cc (string-append bindir "/cc"))) > > + (mkdir bindir) > > + (call-with-output-file cc > > + (lambda (port) > > + (format port > > + "#!~a\n\nexec gcc > > \"$@\"\n" (which "sh")))) > > + (chmod cc #o755)))) =20 >=20 > Can we avoid this trick using a configure flag > (--with-compiler=3D/path/to/gcc) or a configure or environment variable > (CC=3Dgcc)? If not, that=E2=80=99s fine. To build the Rust standard library, only the linker is needed. The default value is "cc". I thought this could be overridden using the "--default-linker=3D" of the ./configure script, but it looks like it is not properly handled. Hence the need for the wrapper.=20 I haven't checked too deeply to know if it is a bug or a feature. On the Rust issue tracker, an entry [1] relates to this problem, but only in terms of documentation. I'll bump the topic upstream. > > + (replace 'build > > + (lambda* (#:key outputs #:allow-other-keys) > > + (setenv "PATH" > > + (string-append (getcwd) "/bin:" (getenv > > "PATH"))) > > + (mkdir (assoc-ref outputs "out")) > > + (zero? (system* "make"))))) =20 >=20 > Rather do: >=20 > (add-before 'build 'change-PATH > (lambda _ > (setenv =E2=80=A6) > #t)) >=20 > so we can reuse the normal =E2=80=98build=E2=80=99 phase, which passes -j= X to =E2=80=98make=E2=80=99. OK. >=20 > > + #:tests? #f)) =20 >=20 > We normally run test suites, unless we have a good reason not to do > so. :-) Any ideas why =E2=80=9Cmake check=E2=80=9D fails? Out of laziness, I skipped the tests. I'll give it a look. [1] https://github.com/rust-lang/rust/issues/32208 Best regards, --=20 ELB