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
(define-module (typst)
    #:use-module ((guix licenses) #:prefix license:)
    #:use-module (guix packages)
    #:use-module (guix gexp)
    #:use-module (guix download)
    #:use-module (guix git-download)
    #:use-module (guix utils)
    #:use-module (guix build-system gnu)
    #:use-module (guix build-system cargo)
    #:use-module (gnu packages crates-io))

;; guix shell --development guix --container --nesting 
;; guix build --load-path=./ --file=typst.scm


; librsvg in gnome.scm mixes build systems
; greetd in admin.scm does some minor changes

(define-public rust-comemo-0.3
  (package
    (name "rust-comemo")
    (version "0.3.0")
    (source
     (origin
       (method url-fetch)
       (uri (crate-uri "comemo" version))
       (file-name (string-append name "-" version ".tar.gz"))
       (sha256
        (base32 "14ng6gqklsy8m9wn6radragn8pazsmn5759mywxb1ddf8bqrg818"))))
    (build-system cargo-build-system)
    (arguments
     `(#:cargo-inputs (("rust-comemo-macros" ,rust-comemo-macros-0.3)
                       ("rust-siphasher" ,rust-siphasher-0.3))))
    (home-page "https://github.com/typst/comemo";)
    (synopsis "Incremental computation through constrained memoization.")
    (description "Incremental computation through constrained memoization.")
    (license (list license:expat license:asl2.0))))

(define-public rust-comemo-macros-0.3
  (package
    (name "rust-comemo-macros")
    (version "0.3.0")
    (source
     (origin
       (method url-fetch)
       (uri (crate-uri "comemo-macros" version))
       (file-name (string-append name "-" version ".tar.gz"))
       (sha256
        (base32 "0h1967l3w815iwscryb0iiv0m8j1np8ndlbfryj1987n2ycw130n"))))
    (build-system cargo-build-system)
    (arguments
     `(#:skip-build? #f
       #:tests? #f
       #:cargo-inputs (("rust-proc-macro2" ,rust-proc-macro2-1)
                       ("rust-quote" ,rust-quote-1)
                       ("rust-syn" ,rust-syn-1)
                       )))
    (home-page "https://github.com/typst/comemo";)
    (synopsis "Procedural macros for comemo.")
    (description "Procedural macros for comemo.")
    (license (list license:expat license:asl2.0))))



(define-public typst
    (package
      (name "typst")
      (version "0.9.0")
      (source
        (origin
          (method git-fetch)
          (uri (git-reference
                 (url "https://github.com/typst/typst";)
                 (commit (string-append "v" version))))
          (sha256
            (base32 "04aq2v1ima87sap6yjb7jrm1ss63ax7v5kg7rpkj44887kfybkvv"))))
      (build-system cargo-build-system)
      (arguments
        `(#:cargo-inputs
            (("rust-chrono" ,rust-chrono-0.4) ;Cargo.lock: 0.4.31 - Guix: 0.4.24
             ("rust-clap" ,rust-clap-4) ;Cargo.lock: 4.4.7 - Guix: 4.3.19 - hmm
             ("rust-clap-complete" ,rust-clap-complete-4) ;Cargo.lock: 4.47 - 
Guix: 4.3.2
             ("rust-codespan-reporting" ,rust-codespan-reporting-0.11) 
;Cargo.lock: 0.11.1 - Guix: 0.11.1
             ("rust-comemo" ,rust-comemo-xx) ;Cargo.lock: 0.3.0a Guix: nope - 
new package
             ("rust-dirs" ,rust-dirs-xx)
             ("rust-ecow" ,rust-ecow-xx)
             ("rust-env-proxy" ,rust-env-proxy-xx)
             ("rust-filetime" ,rust-filetime-xx)
             ("rust-flate2" ,rust-flate2-xx)
             ("rust-fontdb" ,rust-fontdb-xx)
             ("rust-inferno" ,rust-inferno-xx)
             ("rust-notify" ,rust-notify-xx)
             ("rust-once-cell" ,rust-once-cell-xx)
             ("rust-open" ,rust-open-xx)
             ("rust-pathdiff" ,rust-pathdiff-xx)
             ("rust-rustls" ,rust-rustls-xx)
             ("rustls-pemfile" ,rust-pemfile-xx)
             ("rust-same-file" ,rust-same-file-xx)
             ("rust-self-replace" ,rust-self-replace-xx)
             ("rust-semver" ,rust-semver-xx)
             ("rust-serde" ,rust-serde-xx)
             ("rust-serde-json" ,rust-serde-json-xx)
             ("rust-serde-yaml" ,rust-serde-yaml-0.9) ; =0.9.27?
             ("rust-siphasher" ,rust-siphasher-xx) ;Cargo.lock: 0.3.11 - Guix: 
0.3.2 - update existing package
             ("rust-tar" ,rust-tar-xx) ; Cargo.lock: 0.4.40 - Guix: 0.4.38
             ("rust-tempfile" ,rust-tempfile-xx) ;Cargo.lock: 3.8.1 - Guix 3.8.0
             ("rust-tracing" ,rust-tracing-xx) ;Cargo.lock: 0.1.40 - Guix: 
0.1.38 - update existing package
             ("rust-tracing-error" ,rust-tracing-error-xx) ; Cargo.lock: 0.2.0 
- Guix: n/a - new package
             ("rust-tracing-flame" ,rust-tracing-flame-xx) ;Cargo.lock: 0.2.0 - 
Guix: n/a - new package
             ("rust-tracing-subscriber" ,rust-tracing-subscriber-xx) 
;Cargo.lock: 0.3.17 Guix: 0.3.17
             ("rust-typst" ,rust-typst-xx)
             ("rust-typst-library" ,rust-typst-library-xx) ;=0.9.0 - new package
             ("rust-ureq" ,rust-ureq-xx) ;Cargo.lock: 2.8.0 - Guix: 2.6.2 - new 
version required?
             ("rust-xz2" ,rust-xz2-xx) ;Cargo.lock: 0.1.7 - Guix: 0.1.6 - 
update existing package
             ("rust-zip" ,rust-zip-xx) ;Cargo.lock: 0.6.6 - Guix: 0.6.4
            )))
      (home-page "tbd")
      (synopsis "tbd")
      (description "tbd")
      (license license:asl2.0)))


;typst
rust-comemo-macros-0.3
;rust-comemo-0.3

Reply via email to