Skip to content

Commit 283701d

Browse files
committed
fix: make mimalloc and rayon conditional for wasm32 target
1 parent 09366cf commit 283701d

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

.cargo/config.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
1-
[build]
1+
[target.x86_64-unknown-linux-gnu]
2+
rustflags = ["-C", "target-cpu=native"]
3+
4+
[target.aarch64-unknown-linux-gnu]
5+
rustflags = ["-C", "target-cpu=native"]
6+
7+
[target.x86_64-apple-darwin]
8+
rustflags = ["-C", "target-cpu=native"]
9+
10+
[target.aarch64-apple-darwin]
211
rustflags = ["-C", "target-cpu=native"]

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ lto = "fat"
3333
codegen-units = 1
3434
panic = "abort"
3535

36-
[dependencies.mimalloc]
36+
[target.'cfg(not(target_arch = "wasm32"))'.dependencies.mimalloc]
3737
version = "0.1"
3838
default-features = false
3939

40-
[dependencies.rayon]
40+
[target.'cfg(not(target_arch = "wasm32"))'.dependencies.rayon]
4141
version = "1.10"

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::{
33
path::{Path, PathBuf},
44
};
55

6+
#[cfg(not(target_arch = "wasm32"))]
67
#[global_allocator]
78
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
89

src/render.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::sync::atomic::{AtomicUsize, Ordering};
22

33
use image::{Rgba, RgbaImage};
4+
#[cfg(not(target_arch = "wasm32"))]
45
use rayon::prelude::*;
56

67
use crate::{
@@ -93,10 +94,12 @@ impl Render {
9394
let row_stride = out_w * 4;
9495
let out_raw = self.out.as_mut();
9596

96-
out_raw
97-
.par_chunks_mut(row_stride)
98-
.enumerate()
99-
.for_each(|(y, row)| {
97+
#[cfg(not(target_arch = "wasm32"))]
98+
let iter = out_raw.par_chunks_mut(row_stride).enumerate();
99+
#[cfg(target_arch = "wasm32")]
100+
let iter = out_raw.chunks_mut(row_stride).enumerate();
101+
102+
iter.for_each(|(y, row)| {
100103
let map_y_base = (y as i32 + off) as u32;
101104
if map_y_base >= mapping.map1.height() || map_y_base >= mapping.map2.height() {
102105
return;

0 commit comments

Comments
 (0)