Skip to content

Commit

Permalink
Update ahash to fix compilation issue on nightly (#672)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kobzol committed Feb 10, 2024
1 parent 1c3af71 commit 97d9e82
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 12 deletions.
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
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
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
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
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
@@ -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
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
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
@@ -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

0 comments on commit 97d9e82

Please sign in to comment.