Skip to content

Commit b7f33e6

Browse files
authored
feat: enable no_opt_arch flag for mimalloc-safe on linux-aarch64 (#98)
1 parent 05b094f commit b7f33e6

File tree

8 files changed

+65
-53
lines changed

8 files changed

+65
-53
lines changed

Cargo.lock

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

benches/resolver.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ fn create_symlinks() -> io::Result<PathBuf> {
101101
Ok(temp_path)
102102
}
103103

104-
fn oxc_resolver() -> unrs_resolver::Resolver {
104+
fn unrs_resolver() -> unrs_resolver::Resolver {
105105
use unrs_resolver::{AliasValue, ResolveOptions, Resolver};
106106
let alias_value = AliasValue::from("./");
107107
Resolver::new(ResolveOptions {
@@ -148,7 +148,7 @@ fn bench_resolver(c: &mut Criterion) {
148148

149149
// check validity
150150
for (path, request) in &data {
151-
assert!(oxc_resolver().resolve(path, request).is_ok(), "{path:?} {request}");
151+
assert!(unrs_resolver().resolve(path, request).is_ok(), "{path:?} {request}");
152152
}
153153

154154
let symlink_test_dir = create_symlinks().expect("Create symlink fixtures failed");
@@ -157,27 +157,27 @@ fn bench_resolver(c: &mut Criterion) {
157157

158158
for i in symlinks_range.clone() {
159159
assert!(
160-
oxc_resolver().resolve(&symlink_test_dir, &format!("./file{i}")).is_ok(),
160+
unrs_resolver().resolve(&symlink_test_dir, &format!("./file{i}")).is_ok(),
161161
"file{i}.js"
162162
);
163163
}
164164

165165
let mut group = c.benchmark_group("resolver");
166166

167167
group.bench_with_input(BenchmarkId::from_parameter("single-thread"), &data, |b, data| {
168-
let oxc_resolver = oxc_resolver();
168+
let unrs_resolver = unrs_resolver();
169169
b.iter(|| {
170170
for (path, request) in data {
171-
_ = oxc_resolver.resolve(path, request);
171+
_ = unrs_resolver.resolve(path, request);
172172
}
173173
});
174174
});
175175

176176
group.bench_with_input(BenchmarkId::from_parameter("multi-thread"), &data, |b, data| {
177-
let oxc_resolver = oxc_resolver();
177+
let unrs_resolver = unrs_resolver();
178178
b.iter(|| {
179179
data.par_iter().for_each(|(path, request)| {
180-
_ = oxc_resolver.resolve(path, request);
180+
_ = unrs_resolver.resolve(path, request);
181181
});
182182
});
183183
});
@@ -186,11 +186,11 @@ fn bench_resolver(c: &mut Criterion) {
186186
BenchmarkId::from_parameter("resolve from symlinks"),
187187
&symlinks_range,
188188
|b, data| {
189-
let oxc_resolver = oxc_resolver();
189+
let unrs_resolver = unrs_resolver();
190190
b.iter(|| {
191191
for i in data.clone() {
192192
assert!(
193-
oxc_resolver.resolve(&symlink_test_dir, &format!("./file{i}")).is_ok(),
193+
unrs_resolver.resolve(&symlink_test_dir, &format!("./file{i}")).is_ok(),
194194
"file{i}.js"
195195
);
196196
}

justfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ alias r := ready
1010
# or install via `cargo install cargo-binstall`
1111
# Initialize the project by installing all the necessary tools.
1212
init:
13-
cargo binstall watchexec-cli typos-cli dprint -y
13+
cargo binstall cargo-shear dprint typos-cli watchexec-cli -y
1414

1515
install:
1616
pnpm install
@@ -52,6 +52,7 @@ check:
5252
# Run all the tests
5353
test:
5454
cargo test --all-features
55+
pnpm test
5556

5657
# Lint the whole project
5758
lint:

napi/Cargo.toml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ napi-derive = { version = "3.0.0-alpha.29" }
1616
oxc_resolver = { path = "..", package = "unrs_resolver" }
1717
tracing-subscriber = { version = "0.3.19", default-features = false, features = ["std", "fmt"] } # Omit the `regex` feature
1818

19-
[target.'cfg(all(not(target_os = "linux"), not(target_os = "freebsd"), not(target_arch = "arm"), not(target_family = "wasm")))'.dependencies]
20-
mimalloc-safe = { version = "0.1.50", features = ["skip_collect_on_exit"] }
19+
[target.'cfg(not(any(target_os = "linux", target_os = "freebsd", target_arch = "arm", target_family = "wasm")))'.dependencies]
20+
mimalloc-safe = { version = "0.1.51", features = ["skip_collect_on_exit"] }
2121

22-
[target.'cfg(all(target_os = "linux", not(target_arch = "arm")))'.dependencies]
23-
mimalloc-safe = { version = "0.1.50", features = ["skip_collect_on_exit", "local_dynamic_tls"] }
22+
[target.'cfg(all(target_os = "linux", not(target_arch = "arm"), not(target_arch = "aarch64")))'.dependencies]
23+
mimalloc-safe = { version = "0.1.51", features = ["skip_collect_on_exit", "local_dynamic_tls"] }
24+
25+
[target.'cfg(all(target_os = "linux", target_arch = "aarch64"))'.dependencies]
26+
mimalloc-safe = { version = "0.1.51", features = ["skip_collect_on_exit", "local_dynamic_tls", "no_opt_arch"] }
2427

2528
[build-dependencies]
2629
napi-build = "2.1.6"

napi/src/lib.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
// Disable mimalloc on ARM, FreeBSD, WASM, and Linux/aarch64 due to known allocator issues (see #64).
2-
#[cfg(not(any(
3-
target_arch = "arm",
4-
target_os = "freebsd",
5-
target_family = "wasm",
6-
all(target_os = "linux", target_arch = "aarch64")
7-
)))]
1+
#[cfg(not(any(target_arch = "arm", target_os = "freebsd", target_family = "wasm")))]
82
#[global_allocator]
93
static ALLOC: mimalloc_safe::MiMalloc = mimalloc_safe::MiMalloc;
104

napi/tests/resolver.test.mjs

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ if (process.env.WASI_TEST) {
1515

1616
const currentDir = join(fileURLToPath(import.meta.url), '..');
1717

18+
const rootDir = join(currentDir, '..', '..');
19+
20+
const fixturesDir = join(rootDir, 'fixtures');
21+
1822
const enhancedResolveRoot = join(
19-
currentDir,
20-
'..',
21-
'..',
22-
'fixtures',
23+
fixturesDir,
2324
'enhanced_resolve',
2425
'test',
2526
'fixtures',
@@ -232,9 +233,10 @@ for (
232233
});
233234
}
234235

236+
const pnpmDir = join(rootDir, 'node_modules', '.pnpm');
237+
235238
test('resolve pnpm package', () => {
236-
const rootDir = join(currentDir, '..', '..');
237-
const pnpmProjectPath = join(rootDir, 'fixtures', 'pnpm');
239+
const pnpmProjectPath = join(fixturesDir, 'pnpm');
238240
const resolver = new ResolverFactory({
239241
aliasFields: ['browser'],
240242
});
@@ -243,23 +245,35 @@ test('resolve pnpm package', () => {
243245
assert.deepEqual(
244246
styledComponents.path,
245247
join(
246-
rootDir,
247-
'node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/styled-components/dist/styled-components.browser.cjs.js',
248+
pnpmDir,
249+
'[email protected][email protected][email protected][email protected]/node_modules/styled-components/dist/styled-components.browser.cjs.js',
248250
),
249251
);
250252

251253
const react = resolver.sync(
252254
join(
253-
rootDir,
254-
'node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/styled-components',
255+
pnpmDir,
256+
255257
),
256258
'react',
257259
);
258260
assert.deepEqual(
259261
react.path,
260-
join(
261-
rootDir,
262-
'node_modules/.pnpm/[email protected]/node_modules/react/index.js',
263-
),
262+
join(pnpmDir, '[email protected]/node_modules/react/index.js'),
263+
);
264+
});
265+
266+
test('resolve recursive symbol link', () => {
267+
const workspaceProjectPath = join(fixturesDir, 'pnpm-workspace');
268+
const resolver = new ResolverFactory({});
269+
270+
const react = resolver.sync(
271+
join(workspaceProjectPath, './packages/app'),
272+
'./node_modules/@monorepo/lib/node_modules/react/package.json',
273+
);
274+
275+
assert.deepEqual(
276+
react.path,
277+
join(pnpmDir, '[email protected]/node_modules/react/package.json'),
264278
);
265279
});

npm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@
4949
"postinstall": "napi-postinstall unrs-resolver check"
5050
},
5151
"dependencies": {
52-
"napi-postinstall": "^0.1.5"
52+
"napi-postinstall": "^0.1.6"
5353
}
5454
}

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)