Repository: mitsuhiko/minijinja (language: rust)

Issue:
v0.30.3 doesn't compile on some 32-bit platforms
## Description

```
error[E0432]: unresolved import `std::sync::atomic::AtomicU64`
   --> /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/minijinja-0.30.3/src/value/mod.rs:111:43
    |
111 | use std::sync::atomic::{self, AtomicBool, AtomicU64};
    |                                           ^^^^^^^^^
    |                                           |
    |                                           no `AtomicU64` in `sync::atomic`
    |                                           help: a similar name exists in the module: `AtomicU8`
```

## Reproduction steps

```bash
rustup target add armv5te-unknown-linux-gnueabi
cargo check --target armv5te-unknown-linux-gnueabi
```

Additional helpful information:

- Version of minijinja: 0.30.3
- Version of rustc: 1.67.1
- Operating system and version: Ubuntu 22.04

## What did you expect

Build success.

Maybe [portable-atomic](https://github.com/taiki-e/portable-atomic) can be used.




Discussion / hints:

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a68b47ba..e3726ae8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,10 @@
 
 All notable changes to MiniJinja are documented here.
 
+## 0.30.4
+
+- Restore compilation on 32bit targets. (#207)
+
 ## 0.30.3
 
 - Added the Jinja2 tests `==`, `!=`, `<`, `<=`, `>`, `>=` and `in` for the
diff --git a/minijinja/src/value/mod.rs b/minijinja/src/value/mod.rs
index ac5a9f9b..04a848c1 100644
--- a/minijinja/src/value/mod.rs
+++ b/minijinja/src/value/mod.rs
@@ -108,7 +108,7 @@ use std::collections::BTreeMap;
 use std::convert::TryFrom;
 use std::fmt;
 use std::marker::PhantomData;
-use std::sync::atomic::{self, AtomicBool, AtomicU64};
+use std::sync::atomic::{self, AtomicBool, AtomicUsize};
 use std::sync::Arc;
 
 use serde::ser::{Serialize, Serializer};
@@ -146,8 +146,11 @@ pub(crate) type ValueMap = std::collections::BTreeMap<StaticKey, Value>;
 
 thread_local! {
     static INTERNAL_SERIALIZATION: AtomicBool = AtomicBool::new(false);
-    static LAST_VALUE_HANDLE: AtomicU64 = AtomicU64::new(0);
-    static VALUE_HANDLES: RefCell<BTreeMap<u64, Value>> = RefCell::new(BTreeMap::new());
+
+    // This should be an AtomicU64 but sadly 32bit targets do not necessarily have
+    // AtomicU64 available.
+    static LAST_VALUE_HANDLE: AtomicUsize = AtomicUsize::new(0);
+    static VALUE_HANDLES: RefCell<BTreeMap<usize, Value>> = RefCell::new(BTreeMap::new());
 }
 
 /// Function that returns true when serialization for [`Value`] is taking place.
diff --git a/minijinja/src/value/serialize.rs b/minijinja/src/value/serialize.rs
index 7aebd0a1..f14d2dee 100644
--- a/minijinja/src/value/serialize.rs
+++ b/minijinja/src/value/serialize.rs
@@ -374,7 +374,7 @@ impl ser::SerializeStruct for SerializeStruct {
         match self.name {
             VALUE_HANDLE_MARKER => {
                 let handle_id = match self.fields.get(&Key::Str("handle")) {
-                    Some(&Value(ValueRepr::U64(handle_id))) => handle_id,
+                    Some(&Value(ValueRepr::U64(handle_id))) => handle_id as usize,
                     _ => panic!("bad handle reference in value roundtrip"),
                 };
                 Ok(VALUE_HANDLES.with(|handles| {
diff --git a/minijinja/src/vm/fuel.rs b/minijinja/src/vm/fuel.rs
index e01c874c..860893a0 100644
--- a/minijinja/src/vm/fuel.rs
+++ b/minijinja/src/vm/fuel.rs
@@ -1,12 +1,14 @@
 use crate::compiler::instructions::Instruction;
 use crate::error::{Error, ErrorKind};
 
-use std::sync::atomic::{AtomicI64, Ordering};
+use std::sync::atomic::{AtomicIsize, Ordering};
 use std::sync::Arc;
 
 /// Helper for tracking fuel consumption
 pub struct FuelTracker {
-    remaining: AtomicI64,
+    // This should be an AtomicI64 but sadly 32bit targets do not necessarily have
+    // AtomicI64 available.
+    remaining: AtomicIsize,
 }
 
 impl FuelTracker {
@@ -16,7 +18,7 @@ impl FuelTracker {
     /// shared across nested invocations of the template evaluation.
     pub fn new(fuel: u64) -> Arc<FuelTracker> {
         Arc::new(FuelTracker {
-            remaining: AtomicI64::new(fuel as i64),
+            remaining: AtomicIsize::new(fuel as isize),
         })
     }
 
@@ -34,7 +36,7 @@ impl FuelTracker {
 }
 
 /// How much fuel does an instruction consume?
-fn fuel_for_instruction(instruction: &Instruction) -> i64 {
+fn fuel_for_instruction(instruction: &Instruction) -> isize {
     match instruction {
         Instruction::BeginCapture(_)
         | Instruction::LoadBlocks


Test patch:
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index 61cfa469..bae02d09 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -54,6 +54,21 @@ jobs:
   #         CARGO_NET_GIT_FETCH_WITH_CLI: "true"
   #         CARGO_HTTP_MULTIPLEXING: "false"
 
+  test-32bit:
+    name: Check on 1.61.0 (32bit)
+    runs-on: ubuntu-latest
+
+    steps:
+      - uses: actions/checkout@v1
+      - uses: actions-rs/toolchain@v1
+        with:
+          toolchain: 1.61.0
+          target: armv5te-unknown-linux-gnueabi
+          profile: minimal
+          override: true
+      - name: Check
+        run: cargo check --all-features -p minijinja --target armv5te-unknown-linux-gnueabi
+
   test-stable:
     name: Test on 1.61.0
     runs-on: ubuntu-latest