Cargo update problem

Hi,

I am trying to update the version of a big project.
It uses 1.82.0 rust version to compile and some Cargo.toml with 2018 edition.

In a second time :
I create a project aside to test just this lib with the minimal example : GitHub - Relacibo/typst-as-lib: Easily use typst from rust.

It uses to works (rust version 1.86.0, edition 2024).

But today, I try to follow this command to update my project : Transitioning an existing project to a new edition - The Rust Edition Guide

After using cargo updateon my big project, I get some error that I use to not have before using typst-as-lib. So I go on my project aside with just the minimal sample of typst-as-lib. I type cargo update to see... And now, it not works anymore.

So I have some question :

  • How can we revert cargo update ? (I try to clean target and delete Cargo.lock, but seems not to be that).
  • How we update a project ? I was thinking I need to use recent version of rust like 1.86.0 to compile some new lib in my project. So I updated all the crate in their latest version. It was working using a 0.13.1 version of typst-as-lib and the edition 2018 with 1.82.0 for rust version of compilation.
    Now I try to get the lastest version of typst-as-lib with edition 2024. I try to change also edition for all cargo.toml and I need to use 1.85.0 version of rust (minimum).

Am I wrong in my comprehension for a update ? And why, with no code change, the cargo update makes now my little project with only the main sample of typst-as-lib not working... ?

After reading other post, I was thinking we can mix package with different edition but we can only use one version of rust for the compilation...

A lot of text here, but I am confused a little...

cargo update edits Cargo.lock. Therefore, you revert cargo update by reverting Cargo.lock to its previous contents.

In order to help you further, we’ll need to see the actual text of the error(s) you are getting, so we can identify what kind of problem it is.

Hi kpreid,

In fact, I analyse a lot and I think my problem comes from typst-as-lib crate that I use.

I explain what is happening, and I would like to understand how to manage the edition and the rust version in a second step if you understand my incomprehension.

So to reproduce my problem : I try to run a sample just to test typst-as-lib.

Cargo.toml that makes the sample works
I take a old version(0.13.0) of typst-as-lib and I use 2018 edition. I compile with rust 1.82.0 version.

[package]
name = "Test" # the name of the package
version = "0.0.1" 
edition = "2018"

[dependencies]
derive_typst_intoval = "0.3.0"
typst = "0.13.1"
typst-as-lib = "0.13.0"
typst-pdf = "0.13.1"

But if I use this version of Cargo.toml, it does not works because a problem occurs in typst lib that is used in typst-as-lib.

Cargo.toml that makes the sample NOT working
I take the lastest version(0.14.4) of typst-as-lib and I use 2024 edition. I compile with rust 1.86.0 version.

[package]
name = "Test" # the name of the package
version = "0.0.1" 
edition = "2024"

[dependencies]
derive_typst_intoval = "0.3.0"
typst = "0.13.1"
typst-as-lib = "0.14.4"
typst-pdf = "0.13.1"

The others files of my test :

src>main.rs The example in typst-as-lib without image, just to test quickly.

use derive_typst_intoval::{IntoDict, IntoValue};
use std::fs;
use typst::foundations::{Bytes, Dict, IntoValue};
use typst_as_lib::TypstEngine;

static TEMPLATE_FILE: &str = include_str!("./templates/template.typ");
static FONT: &[u8] = include_bytes!("./fonts/texgyrecursor-regular.otf");
static OUTPUT: &str = "./output.pdf";

fn main() {
    // Read in fonts and the main source file.
    // We can use this template more than once, if needed (Possibly
    // with different input each time).
    let template = TypstEngine::builder()
        .main_file(TEMPLATE_FILE)
        .fonts([FONT])
        .build();

    // Run it
    let doc = template
        .compile_with_input(dummy_data())
        .output
        .expect("typst::compile() returned an error!");

    // Create pdf
    let options = Default::default();
    let pdf = typst_pdf::pdf(&doc, &options).expect("Could not generate pdf.");
    fs::write(OUTPUT, pdf).expect("Could not write pdf.");
}

// Some dummy content. We use `derive_typst_intoval` to easily
// create `Dict`s from structs by deriving `IntoDict`;
fn dummy_data() -> Content {
    Content {
        v: vec![
            ContentElement {
                heading: "Foo".to_owned(),
                text: Some("Hello World!".to_owned()),
                num1: 1,
                num2: Some(42),
                image: None,
            },
            ContentElement {
                heading: "Bar".to_owned(),
                num1: 2,
                ..Default::default()
            },
        ],
    }
}

#[derive(Debug, Clone, IntoValue, IntoDict)]
struct Content {
    v: Vec<ContentElement>,
}

// Implement Into<Dict> manually, so we can just pass the struct
// to the compile function.
impl From<Content> for Dict {
    fn from(value: Content) -> Self {
        value.into_dict()
    }
}

#[derive(Debug, Clone, Default, IntoValue, IntoDict)]
struct ContentElement {
    heading: String,
    text: Option<String>,
    num1: i32,
    num2: Option<i32>,
    image: Option<Bytes>,
}

src>templates>template.typ

#import sys: inputs

#set page(paper: "a4")
#set text(font: "TeX Gyre Cursor", 11pt)

#let content = inputs.v
#let last_index = content.len() - 1

#for (i, elem) in content.enumerate() [
  == #elem.heading
  Text: #elem.text \
  Num1: #elem.num1 \
  Num2: #elem.num2 \
  #if i < last_index [
    #pagebreak()
  ]
]

src>fonts>texgyrecursor-regular.otf
This file -> typst-as-lib/examples/fonts/texgyrecursor-regular.otf at main · Relacibo/typst-as-lib · GitHub

The error lets me thinking that the typst crate has a error compilation too now (It used to works but I get the code of typst-as-lib and try to run a sample just now and it does not works too...):

 cargo run
    Blocking waiting for file lock on build directory
   Compiling typst-library v0.13.1
   Compiling typst v0.12.0
error[E0412]: cannot find type `HashMap` in this scope
  --> ....cargo\registry\src\index.crates.io-1949cf8c6b5b557f\typst-0.12.0\src\foundations\value.rs:94:13
   |
94 |     HashMap(HashMap<K, V>),
   |             ^^^^^^^ not found in this scope
   |
help: consider importing this struct
   |
1  + use std::collections::HashMap;
...

So, if I used a old version of rust to compile, I need to use the previous edition 2018 and so a old version of typst-of-lib (0.13.0 for example).

But if I want to make my big project updated, I will need to use latest version of crate, and so latest edition in future...

And now this crate typst-of-lib needs a crate named typst that not compil in 1.86.0 version... with 2024 edition...
But my incomprehension comes that I used a example with 2024 edition before using this crate one month ago. I try my sample yesterday, It works. I just use command cargo update and now, nothing works anymore. I delete Cargo.lock, clean target... And try the original code from the typst-as-lib, and nothing run.

???

Did you try upgrading typst to 0.13?

I only used that for typst since the begining.

typst = "0.13.1"

No change since march typst - Rust ?

If you get the code on this repo for typst-as-lib GitHub - Relacibo/typst-as-lib: Easily use typst from rust.

And use this command as mentioned in README :

cargo r --example=small_example

Errors occurs too now...

This error indicates that it is picking up typst version 0.12.0, and that is where the error is occurring. Looking through your dependencies, it appears derive_typst_intoval depends on the 0.12 version, so it might be worth considering whether you need that dependency (I don't know much about typst, but it appears to already include its own proc macros).

If I use the version of cargo that works. But that I try to compil with 1.86.0 version of rust. I have the same error...

Is it a problem of edition ? So ? But if a crate use a old version... all need to use the same ? I confused...

This crate typst-as-lib used to works very well and now... Have you the same problem to run the sample ?

Ok, but this error does not occurs when I tested the lib one month ago. I am confused, why this not works now... To test with 2024 edition, I needed to run with older version of rust.
Then to include this lib in my big project, I decide to use previous version of typst-as-lib to compile with 1.82.0 version of rust.

This means that maybe the extern crate has error in futur version (edition) and should be updated too ?

Ok. I think the problem is already reported to the creator of the crate... Update dependencies by matveyson · Pull Request #2 · KillTheMule/derive_typst_intoval · GitHub

So, if we use external crate that are not updated, we can be blocked to update our project two... It is what I undestand about update version project... ^^

Ha, thanks for notifying me, I kinda forgot about that PR :blush: I merged it, but can't cut a new crates.io release now, hope I do remember it tonight when I get home.

2 Likes

Thank you very much. As soon as it is ok, I will ask to the creator for typst-as-lib update too ^^

Note that this error is occurring in the source code of a library downloaded from crates.io — not in your project’s code. This typically should not happen. When it does, there are a few possibilities:

  • The library has a bug, was uploaded without verification, and can never work for anyone.
  • The library has a bug under a certain combination of features.
  • The library cannot compile on your platform in particular.
  • The library’s source code has been edited.

I think that last case has happened here. This is because if we consult the source code of version 0.12.0, you can see that line 94 does not contain HashMap(HashMap<K, V>), and in fact is right after the end of the enum. Perhaps you accidentally edited the file while viewing it via go-to-definition.

In this case, it is very important that you fix this problem (even if you decide to upgrade to using a different version of typst) because the problem will linger and break any programs using typst v0.12.0. In order to fix it, delete the directory .cargo\registry\src\index.crates.io-1949cf8c6b5b557f\typst-0.12.0\. Cargo will automatically download it again the next time it is needed. (You can also delete all of .cargo/registry if you like to be thorough.)

2 Likes

I just updated on crates.io. Note: As usual, I borked releasing and so the new version is 0.5.0.

1 Like

Thank you very much to all of you for your time and reactivity.
I will test all of that and tell you when it is ok in my side :wink:

I delete my .cargo/registry/ content and use the cargo.toml that not work anymore this morning. And now its works as before :wink:

[package]
name = "Test"
version = "0.0.1" 
edition = "2024"

[dependencies]
derive_typst_intoval = "0.3.0"
typst = "0.13.1"
typst-as-lib = "0.14.4"
typst-pdf = "0.13.1"

I don't really understand what the problem was. I had a "cached" version of typst 0.12 in the registry that worked before. However, published crates are not supposed to be changed in the future. How could this have been changed?

Yes, a published version of a package on crates.io cannot be changed — only, at most, deleted.

How could this have been changed?

As I said, the most likely cause is that you (or at least software on your computer) edited the file.

Very strange. I will keep that in mind.
Thank you !!!