Skip to content

Commit f00b6a2

Browse files
jeffhuenclaude
andcommitted
Bump to v0.1.1, fix musl builds without mimalloc
- Add .cargo/config.toml with -crt-static for musl cdylib support - Add Cross.toml for RUSTLER_NIF_VERSION passthrough - Remove mimalloc dependency (not needed, caused perf regression) - Use Relaxed ordering in TrackingAllocator for better performance - Add nif_versions to native.ex for precompiled downloads - Enable LTO for release builds Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent fbda099 commit f00b6a2

File tree

7 files changed

+34
-73
lines changed

7 files changed

+34
-73
lines changed

lib/rusty_csv/native.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ defmodule RustyCSV.Native do
3333
crate: "rustycsv",
3434
base_url: "https://github.com/jeffhuen/rustycsv/releases/download/v#{version}",
3535
force_build: System.get_env("FORCE_RUSTYCSV_BUILD") in ["1", "true"],
36+
nif_versions: ["2.15", "2.16", "2.17"],
3637
targets:
3738
Enum.uniq(
3839
["aarch64-apple-darwin", "x86_64-apple-darwin"] ++

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule RustyCSV.MixProject do
22
use Mix.Project
33

4-
@version "0.1.0"
4+
@version "0.1.1"
55
@source_url "https://github.com/jeffhuen/rustycsv"
66

77
def project do

native/rustycsv/.cargo/config.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[target.'cfg(target_os = "macos")']
2+
rustflags = [
3+
"-C", "link-arg=-undefined",
4+
"-C", "link-arg=dynamic_lookup",
5+
]
6+
7+
# See https://github.com/rust-lang/rust/issues/59302
8+
[target.x86_64-unknown-linux-musl]
9+
rustflags = [
10+
"-C", "target-feature=-crt-static"
11+
]
12+
13+
[target.aarch64-unknown-linux-musl]
14+
rustflags = [
15+
"-C", "target-feature=-crt-static"
16+
]
17+
18+
[profile.release]
19+
lto = true

native/rustycsv/Cargo.lock

Lines changed: 0 additions & 48 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

native/rustycsv/Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rustycsv"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
authors = ["Jeff Huen"]
55
edition = "2021"
66

@@ -13,11 +13,8 @@ crate-type = ["cdylib"]
1313
rustler = "0.37"
1414
memchr = "2.7" # Fast byte searching, uses SIMD when available
1515
rayon = "1.10" # Data parallelism for parallel parsing
16-
mimalloc = { version = "0.1", default-features = false, optional = true }
1716

1817
[features]
19-
default = ["mimalloc"]
20-
mimalloc = ["dep:mimalloc"]
2118
# NIF version features for rustler_precompiled (OTP 24+ = 2.15, OTP 26 = 2.16, OTP 27+ = 2.17)
2219
nif_version_2_15 = ["rustler/nif_version_2_15"]
2320
nif_version_2_16 = ["rustler/nif_version_2_16"]

native/rustycsv/Cross.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[build.env]
2+
passthrough = [
3+
"RUSTLER_NIF_VERSION"
4+
]

native/rustycsv/src/lib.rs

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,9 @@
88
// E: Parallel parsing via rayon (parse_string_parallel)
99

1010
use rustler::{Binary, Env, NifResult, ResourceArc, Term};
11-
use std::alloc::{GlobalAlloc, Layout};
11+
use std::alloc::{GlobalAlloc, Layout, System};
1212
use std::sync::atomic::{AtomicUsize, Ordering};
1313

14-
#[cfg(feature = "mimalloc")]
15-
use mimalloc::MiMalloc;
16-
17-
#[cfg(not(feature = "mimalloc"))]
18-
use std::alloc::System;
19-
2014
mod core;
2115
mod resource;
2216
mod strategy;
@@ -39,25 +33,19 @@ static PEAK_ALLOCATED: AtomicUsize = AtomicUsize::new(0);
3933

4034
struct TrackingAllocator;
4135

42-
#[cfg(feature = "mimalloc")]
43-
static BASE_ALLOCATOR: MiMalloc = MiMalloc;
44-
45-
#[cfg(not(feature = "mimalloc"))]
46-
static BASE_ALLOCATOR: System = System;
47-
4836
unsafe impl GlobalAlloc for TrackingAllocator {
4937
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
50-
let ptr = BASE_ALLOCATOR.alloc(layout);
38+
let ptr = System.alloc(layout);
5139
if !ptr.is_null() {
52-
let current = ALLOCATED.fetch_add(layout.size(), Ordering::SeqCst) + layout.size();
40+
let current = ALLOCATED.fetch_add(layout.size(), Ordering::Relaxed) + layout.size();
5341
// Update peak if we exceeded it
54-
let mut peak = PEAK_ALLOCATED.load(Ordering::SeqCst);
42+
let mut peak = PEAK_ALLOCATED.load(Ordering::Relaxed);
5543
while current > peak {
5644
match PEAK_ALLOCATED.compare_exchange_weak(
5745
peak,
5846
current,
59-
Ordering::SeqCst,
60-
Ordering::SeqCst,
47+
Ordering::Relaxed,
48+
Ordering::Relaxed,
6149
) {
6250
Ok(_) => break,
6351
Err(p) => peak = p,
@@ -68,8 +56,8 @@ unsafe impl GlobalAlloc for TrackingAllocator {
6856
}
6957

7058
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
71-
ALLOCATED.fetch_sub(layout.size(), Ordering::SeqCst);
72-
BASE_ALLOCATOR.dealloc(ptr, layout)
59+
ALLOCATED.fetch_sub(layout.size(), Ordering::Relaxed);
60+
System.dealloc(ptr, layout)
7361
}
7462
}
7563

0 commit comments

Comments
 (0)