mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-14 04:11:03 +00:00
Add minification for resolc_packed.js
This commit is contained in:
@@ -28,22 +28,9 @@ install-bin:
|
|||||||
install-npm:
|
install-npm:
|
||||||
npm install && npm fund
|
npm install && npm fund
|
||||||
|
|
||||||
RESOLC_WASM_TARGET_DIR=target/wasm32-unknown-emscripten/release
|
|
||||||
RESOLC_WASM=$(RESOLC_WASM_TARGET_DIR)/resolc.wasm
|
|
||||||
RESOLC_JS=$(RESOLC_WASM_TARGET_DIR)/resolc.js
|
|
||||||
RESOLC_JS_PACKED=$(RESOLC_WASM_TARGET_DIR)/resolc_packed.js
|
|
||||||
|
|
||||||
install-wasm: install-npm
|
install-wasm: install-npm
|
||||||
cargo build --target wasm32-unknown-emscripten -p revive-solidity --release --no-default-features
|
cargo build --target wasm32-unknown-emscripten -p revive-solidity --release --no-default-features
|
||||||
@echo "let moduleArgs = { wasmBinary: (function(source, uncompressedSize) {" > $(RESOLC_JS_PACKED)
|
npm run build:package
|
||||||
@cat js/utils/mini-lz4.js >> $(RESOLC_JS_PACKED)
|
|
||||||
@cat js/utils/base64DecToArr.js >> $(RESOLC_JS_PACKED)
|
|
||||||
@echo "return uncompress(base64DecToArr(source), uncompressedSize);})(" >> $(RESOLC_JS_PACKED)
|
|
||||||
@echo "\"$$(lz4c --no-frame-crc --best --favor-decSpeed "${RESOLC_WASM}" - | tail -c +8 | base64 -w 0 )\"," >> $(RESOLC_JS_PACKED)
|
|
||||||
@echo "$$(wc -c < $(RESOLC_WASM)))};" >> $(RESOLC_JS_PACKED)
|
|
||||||
@cat $(RESOLC_JS) >> $(RESOLC_JS_PACKED)
|
|
||||||
@echo "createRevive = createRevive.bind(null, moduleArgs);" >> $(RESOLC_JS_PACKED)
|
|
||||||
@echo "Combined script written to $(RESOLC_JS_PACKED)"
|
|
||||||
|
|
||||||
install-llvm-builder:
|
install-llvm-builder:
|
||||||
cargo install --path crates/llvm-builder
|
cargo install --path crates/llvm-builder
|
||||||
|
|||||||
+63
@@ -0,0 +1,63 @@
|
|||||||
|
const fs = require("fs");
|
||||||
|
const path = require("path");
|
||||||
|
const { execSync } = require("child_process");
|
||||||
|
const { minify } = require("terser");
|
||||||
|
|
||||||
|
const RESOLC_WASM_TARGET_DIR = path.join(
|
||||||
|
__dirname,
|
||||||
|
"../target/wasm32-unknown-emscripten/release",
|
||||||
|
);
|
||||||
|
const RESOLC_WASM = path.join(RESOLC_WASM_TARGET_DIR, "resolc.wasm");
|
||||||
|
const RESOLC_JS = path.join(RESOLC_WASM_TARGET_DIR, "resolc.js");
|
||||||
|
const RESOLC_JS_PACKED = path.join(RESOLC_WASM_TARGET_DIR, "resolc_packed.js");
|
||||||
|
|
||||||
|
const execShellCommand = (cmd) => {
|
||||||
|
return execSync(cmd, {
|
||||||
|
encoding: "utf-8",
|
||||||
|
maxBuffer: 1024 * 1024 * 100,
|
||||||
|
}).trim();
|
||||||
|
};
|
||||||
|
|
||||||
|
const wasmBase64 = execShellCommand(
|
||||||
|
`lz4c --no-frame-crc --best --favor-decSpeed "${RESOLC_WASM}" - | tail -c +8 | base64 -w 0`,
|
||||||
|
);
|
||||||
|
|
||||||
|
const wasmSize = fs.statSync(RESOLC_WASM).size;
|
||||||
|
|
||||||
|
const miniLz4 = fs.readFileSync(
|
||||||
|
path.join(__dirname, "utils/mini-lz4.js"),
|
||||||
|
"utf-8",
|
||||||
|
);
|
||||||
|
const base64DecToArr = fs.readFileSync(
|
||||||
|
path.join(__dirname, "utils/base64DecToArr.js"),
|
||||||
|
"utf-8",
|
||||||
|
);
|
||||||
|
const resolcJs = fs.readFileSync(RESOLC_JS, "utf-8");
|
||||||
|
|
||||||
|
const packedJsContent = `
|
||||||
|
let moduleArgs = { wasmBinary: (function(source, uncompressedSize) {
|
||||||
|
${miniLz4}
|
||||||
|
${base64DecToArr}
|
||||||
|
return uncompress(base64DecToArr(source), uncompressedSize);
|
||||||
|
})("${wasmBase64}", ${wasmSize}),
|
||||||
|
};
|
||||||
|
|
||||||
|
${resolcJs}
|
||||||
|
|
||||||
|
createRevive = createRevive.bind(null, moduleArgs);
|
||||||
|
`;
|
||||||
|
|
||||||
|
minify(packedJsContent)
|
||||||
|
.then((minifiedJs) => {
|
||||||
|
if (minifiedJs.error) {
|
||||||
|
console.error("Error during minification:", minifiedJs.error);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.writeFileSync(RESOLC_JS_PACKED, minifiedJs.code, "utf-8");
|
||||||
|
console.log(`Combined script written to ${RESOLC_JS_PACKED}`);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error("Minification failed:", err);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
+4
-2
@@ -11,13 +11,15 @@
|
|||||||
"test:node": "mocha --timeout 60000 ./tests",
|
"test:node": "mocha --timeout 60000 ./tests",
|
||||||
"test:bun": "bun test --timeout 60000 node.test",
|
"test:bun": "bun test --timeout 60000 node.test",
|
||||||
"test:all": "npm run test:node && npm run test:bun",
|
"test:all": "npm run test:node && npm run test:bun",
|
||||||
"format": "prettier --write ."
|
"format": "prettier --write .",
|
||||||
|
"build:package": "node ./build.js"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@playwright/test": "^1.49.1",
|
"@playwright/test": "^1.49.1",
|
||||||
"chai": "^5.1.2",
|
"chai": "^5.1.2",
|
||||||
"http-server": "^14.1.1",
|
"http-server": "^14.1.1",
|
||||||
"mocha": "^11.0.1",
|
"mocha": "^11.0.1",
|
||||||
"prettier": "^3.4.2"
|
"prettier": "^3.4.2",
|
||||||
|
"terser": "^5.37.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
function uncompress(source, uncompressedSize) {
|
function uncompress(source, uncompressedSize) {
|
||||||
/*
|
/*
|
||||||
|
Source https://github.com/ethereum/solidity/blob/develop/scripts/ci/mini-lz4.js
|
||||||
|
====
|
||||||
based off https://github.com/emscripten-core/emscripten/blob/main/third_party/mini-lz4.js
|
based off https://github.com/emscripten-core/emscripten/blob/main/third_party/mini-lz4.js
|
||||||
The license only applies to the body of this function (``uncompress``).
|
The license only applies to the body of this function (``uncompress``).
|
||||||
====
|
====
|
||||||
|
|||||||
+2
-1
@@ -3,7 +3,8 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test:cli": "npm run test -w crates/solidity/src/tests/cli-tests",
|
"test:cli": "npm run test -w crates/solidity/src/tests/cli-tests",
|
||||||
"test:wasm": "npm run test:all -w js"
|
"test:wasm": "npm run test:all -w js",
|
||||||
|
"build-package": "npm run build:package -w js"
|
||||||
},
|
},
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"crates/solidity/src/tests/cli-tests",
|
"crates/solidity/src/tests/cli-tests",
|
||||||
|
|||||||
Reference in New Issue
Block a user