Re: packaging Typst

2023-11-03 Thread Alexis Simon
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
 

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




Re: packaging Typst

2023-11-03 Thread Steve George
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


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 

Re: packaging Typst?

2023-11-03 Thread Sergio Pastor Pérez
Hi, Alexis.

`typst` seems to use a structure that relies on multiple smaller
crates. There has been some discussions over the IRC on how this could
be packaged using the current cargo build system.

The discussion where I participated revolved around `pathfinder`
(https://github.com/servo/pathfinder).

Unfortunately there has not been any consensus on what could be done to
package this kind of structure.

I'm hoping that someone has some ideas on how to approach the issue.

Thanks.
Sergio.

Alexis Simon  writes:

> Hi,
>
> Is anyone looking into packaging Typst (https://github.com/typst/typst)?
>
> This is a very promising Latex alternative.
>
> If no one is doing that I could try to investigate packaging it but I 
> would need some help on where to start.
> This is a rust app but not available on crates.io.
>
> Thanks!
> Alexis



Re: packaging Typst

2023-11-02 Thread Alexis Simon
Thank you very much Steve for those detailed explanations! This is going 
to be super helpful as a starter.

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
 

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




Re: packaging Typst? [or other rust apps that have several internal crates]

2023-11-01 Thread Alexis Simon

Thank you Sergio

On 01/11/2023 14:04, Sergio Pastor Pérez wrote:

Hi, Alexis.

`typst` seems to use a structure that relies on multiple smaller
crates. There has been some discussions over the IRC on how this could
be packaged using the current cargo build system.


Yes I asked the question there as I figured this was a more general 
approach to trying to figure out how to package this kind of app.


I'll also add what I mentioned on irc, that packaging helix [1] would be 
pretty similar also.


Maybe someone in the rust team would be willing to look at that and/or 
try to mentor me into looking at rust related packaging.




The discussion where I participated revolved around `pathfinder`
(https://github.com/servo/pathfinder).

Unfortunately there has not been any consensus on what could be done to
package this kind of structure.

I'm hoping that someone has some ideas on how to approach the issue.

Thanks.
Sergio.

Alexis Simon  writes:


Hi,

Is anyone looking into packaging Typst (https://github.com/typst/typst)?

This is a very promising Latex alternative.

If no one is doing that I could try to investigate packaging it but I
would need some help on where to start.
This is a rust app but not available on crates.io.

Thanks!
Alexis


One thing I don't really understand right now in the cargo build system 
is how dependencies are managed compared to other build systems.

If anyone has a beginner blog post or tutorial on that please share.

Cheers,
Alexis

[1] https://github.com/helix-editor/helix



packaging Typst?

2023-10-31 Thread Alexis Simon

Hi,

Is anyone looking into packaging Typst (https://github.com/typst/typst)?

This is a very promising Latex alternative.

If no one is doing that I could try to investigate packaging it but I 
would need some help on where to start.

This is a rust app but not available on crates.io.

Thanks!
Alexis