[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Compiling rust things without cargo (super WIP POC)
From: |
Maxime Devos |
Subject: |
Compiling rust things without cargo (super WIP POC) |
Date: |
Thu, 31 Mar 2022 22:06:10 +0200 |
User-agent: |
Evolution 3.38.3-1 |
Hartmut Goebel schreef op do 31-03-2022 om 21:47 [+0200]:
since rust does not support anything like static or dynamic libraries,
building (intermediate) crates is useless like a hole in my head. Any
output on any intermediate crate will just be thrown away.
In my experiments, it looks like the rust compiler actually _does_
support static libraries, though perhaps cargo doesn't.
I invite you to take a look at
<https://notabug.org/maximed/cargoless-rust-experiments>.
It contains a minimal rust library (libhello) and a minimal 'hello
world'-style application that uses 'libhello'.
To simulate how Guix compiles C software (but here applied to Rust),
the Makefile does the following:
* Run 'rustc --crate-type=lib libhello/hello.rs -o
out/libhello/lib/libhello.rlib',
to compile the library and install it in 'out/libhello/lib/libhello.rlib'
(cf. /gnu/store/...-libhello.../lib/hello.so).
* Run 'rustc -Lout/libhello/lib hello-app/main.rs -o
out/hello-oxygen/bin/hello'
to compile the application. By default, rustc will fail because it cannot
find
the library. However, if -Lout/libhello/lib is passed, then it does find
it!
(cf. LIBRARY_PATH=/gnu/store/.../lib & gcc -L/gnu/store/.../lib)
This is a rather basic example (no transitive dependencies, no test
dependencies,
no macros ...), but it seems like there are some possibilities here ...
As a next step, maybe I could try writing a Guix package definition for libhello
and hello-oxygen, gradually making things more complicated (macros, transitive
dependencies, some non-toy Rust dependencies, a Guix build system ...)?
Greetings,
Maxime.
signature.asc
Description: This is a digitally signed message part