Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ahash to fix compilation issue on nightly #672

Merged
merged 3 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ data-encoding = "2.3.2"
lazy_static = "1.4.0"
const-str = "0.3.1"
pathdiff = "0.2.1"
ahash = "0.7.6"
ahash = "0.8.7"
paste = "1.0.12"
# CLI deps
atty = { version = "0.2", optional = true }
Expand All @@ -75,6 +75,9 @@ static-self = { version = "0.1.0", path = "static-self", optional = true }
[target.'cfg(target_os = "macos")'.dependencies]
jemallocator = { version = "0.3.2", features = ["disable_initial_exec_tls"], optional = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
getrandom = { version = "0.2", features = ["custom"], default-features = false }

[dev-dependencies]
indoc = "1.0.3"
assert_cmd = "2.0"
Expand Down
4 changes: 4 additions & 0 deletions node/test/bundle.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ import path from 'path';
import fs from 'fs';
import { test } from 'uvu';
import * as assert from 'uvu/assert';
import {webcrypto as crypto} from 'node:crypto';

let bundleAsync;
if (process.env.TEST_WASM === 'node') {
bundleAsync = (await import('../../wasm/wasm-node.mjs')).bundleAsync;
} else if (process.env.TEST_WASM === 'browser') {
// Define crypto globally for old node.
// @ts-ignore
globalThis.crypto ??= crypto;
let wasm = await import('../../wasm/index.mjs');
await wasm.default();
bundleAsync = function (options) {
Expand Down
4 changes: 4 additions & 0 deletions node/test/composeVisitors.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

import { test } from 'uvu';
import * as assert from 'uvu/assert';
import {webcrypto as crypto} from 'node:crypto';

let transform, composeVisitors;
if (process.env.TEST_WASM === 'node') {
({transform, composeVisitors} = await import('../../wasm/wasm-node.mjs'));
} else if (process.env.TEST_WASM === 'browser') {
// Define crypto globally for old node.
// @ts-ignore
globalThis.crypto ??= crypto;
let wasm = await import('../../wasm/index.mjs');
await wasm.default();
({transform, composeVisitors} = wasm);
Expand Down
4 changes: 4 additions & 0 deletions node/test/customAtRules.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
import { test } from 'uvu';
import * as assert from 'uvu/assert';
import fs from 'fs';
import {webcrypto as crypto} from 'node:crypto';

let bundle, transform;
if (process.env.TEST_WASM === 'node') {
({ bundle, transform } = await import('../../wasm/wasm-node.mjs'));
} else if (process.env.TEST_WASM === 'browser') {
// Define crypto globally for old node.
// @ts-ignore
globalThis.crypto ??= crypto;
let wasm = await import('../../wasm/index.mjs');
await wasm.default();
transform = wasm.transform;
Expand Down
4 changes: 4 additions & 0 deletions node/test/transform.test.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { test } from 'uvu';
import * as assert from 'uvu/assert';
import {webcrypto as crypto} from 'node:crypto';

let transform, Features;
if (process.env.TEST_WASM === 'node') {
({transform, Features} = await import('../../wasm/wasm-node.mjs'));
} else if (process.env.TEST_WASM === 'browser') {
// Define crypto globally for old node.
// @ts-ignore
globalThis.crypto ??= crypto;
let wasm = await import('../../wasm/index.mjs');
await wasm.default();
({transform, Features} = wasm);
Expand Down
4 changes: 4 additions & 0 deletions node/test/visitor.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
import { test } from 'uvu';
import * as assert from 'uvu/assert';
import fs from 'fs';
import {webcrypto as crypto} from 'node:crypto';

let bundle, bundleAsync, transform, transformStyleAttribute;
if (process.env.TEST_WASM === 'node') {
({ bundle, bundleAsync, transform, transformStyleAttribute } = await import('../../wasm/wasm-node.mjs'));
} else if (process.env.TEST_WASM === 'browser') {
// Define crypto globally for old node.
// @ts-ignore
globalThis.crypto ??= crypto;
let wasm = await import('../../wasm/index.mjs');
await wasm.default();
({ transform, transformStyleAttribute } = wasm);
Expand Down
14 changes: 12 additions & 2 deletions wasm/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,20 @@ export default async function init(input) {
input = fetchOrReadFromFs(input);
}

let env;
initPromise = input
.then(input => load(input, {env: {...napi, await_promise_sync}}))
.then(input => load(input, {
env: {
...napi,
await_promise_sync,
__getrandom_custom: (ptr, len) => {
let buf = env.memory.subarray(ptr, ptr + len);
crypto.getRandomValues(buf);
},
}
}))
.then(({instance}) => {
let env = new Environment(instance);
env = new Environment(instance);
bundleAsyncInternal = createBundleAsync(env);
wasm = env.exports;
});
Expand Down
7 changes: 6 additions & 1 deletion wasm/wasm-node.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { Environment, napi } from 'napi-wasm';
import { await_promise_sync, createBundleAsync } from './async.mjs';
import fs from 'fs';
import {webcrypto as crypto} from 'node:crypto';

let wasmBytes = fs.readFileSync(new URL('lightningcss_node.wasm', import.meta.url));
let wasmModule = new WebAssembly.Module(wasmBytes);
let instance = new WebAssembly.Instance(wasmModule, {
env: {
...napi,
await_promise_sync
await_promise_sync,
__getrandom_custom: (ptr, len) => {
let buf = env.memory.subarray(ptr, ptr + len);
crypto.getRandomValues(buf);
},
},
});
let env = new Environment(instance);
Expand Down
Loading