My current not-yet-working work-in-progress if anyone is interested in
contributing.
https://codeberg.org/alxsim/local-channel/src/branch/main/typst.scm
Alexis
On 02/11/2023 13:21, Steve George wrote:
Hi Alexis,
I've been doing some Rust packaging recently, so maybe this will help you to
get started. Here's how I would approach it.
Explore the software
====================
The first thing I did was explore whether Typst builds in a current Guix
environment. If we don't have the right version of Rust, for example, there's
little point continuing:
- clone it into an appropriate place
- start a shell:
$ guix shell --container --network rust rust-cargo coreutils openssl
nss-certs gcc-toolchain
We need 'openssl' and 'nss-certs' so that cargo will work.
- build it:
[env]$ env CC=gcc cargo build
Kept failing on ring v0.17.5 which is looking for 'cc'. It builds with 296
crates, so we might have our hands full here! Eventually outputs a
/target/debug/typst command which seems to work.
Import using Guix import
=========================
Normally, we'd be able to use the `crates` importer. But, the Typst crates are
just place-holders with no details.
AFAIK the importer only works with crates-io, we can't feed it Cargo.toml file
directly. We'll need to manually create a package and check for any
dependencies.
Manually create a top-level package
====================================
To manually create the package we have to go through the projects Cargo.toml.
- create an intial typst.scm file in some project directory.
- create a minimal typst package by looking in Cargo.lock at 'typst'
- for each dependency look at what the Cargo.lock used to build it - check
whether we have it in Guix
- in some cases we will have the crate, but not the right version
Import the dependencies
=============================
The first crate that I found which we don't have in the Guix archive is
'comemo' [0]. We can import this with:
$ guix shell --development guix --container --nesting --network nss-certs
[env]$ guix import crate --recursive comemo@0.3.0 > comemo-import.scm
Move these package definitions into your main `typst.scm` file. Check them to
add any missing development dependencies.
The first one in the dependency stack is `rust-comemo-0.3` which we reference
at the bottom of the file. We try and build it as the importer has pulled it in:
$ guix shell --development guix --container --nesting
[env]$ guix build --load-path=./ --file=typst.scm
<successfully builds>
The next one `rust-comemo-macros` which has been set to `skip-build: #t`, we'll
try building it that way initially:
- add rust-comemo-macros-0.3 to the bottom of the typst.scm file
- comment out the rust-comemo-0.3 line
- try and build with: guix build --load-path=./ --file=typst.scm
- If it builds successfully, change the `skip-build: #t` part of the
definition to be #f.
- error[E0433]: failed to resolve: use of undeclared crate or module
`comemo`
- tried adding comemo as a dependency which didn't work
- set it to #:tests? #f - for now
There's some more things that have to be done to 'contribute' these packages,
but for now I would move onto the next dependency. And that's all there is to
this part - finding the dependencies and importing them.
Building a dependent package that's not a crate
===============================================
The cargo-build-system expects to build everything from Crates AFAIK. I believe
it will take some messing around with the phases to add the typst-lib which
seems to be a dependency. It looks like librsvg (in gnome.scm) does a lot of
messing with phases, and greetd (in admin.scm) does some as well - these might
be good examples to look at.
Hopefully this is enough to get you started!
Steve
[0] https://crates.io/crates/comemo