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

feat: Add dependency resolver for noir_wasm and implement FileManager for consistency with native interface #3891

Merged
merged 53 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
1826d5d
Started merging changes
Thunkar Dec 18, 2023
29c1dda
Moving tests to jest
Thunkar Dec 18, 2023
d40c1ef
Fixed CJS compilation
Thunkar Dec 18, 2023
c857489
Merge branch 'master' of github.com:noir-lang/noir into gj/noir_wasm
Thunkar Dec 18, 2023
9129dbd
Cleanup
Thunkar Dec 19, 2023
487d48e
Working, tests green
Thunkar Dec 20, 2023
3cf9f97
Merge branch 'master' of github.com:noir-lang/noir into gj/noir_wasm
Thunkar Dec 20, 2023
89ef603
Merge branch 'master' of github.com:noir-lang/noir into gj/noir_wasm
Thunkar Dec 21, 2023
c3233a5
Deps cleanup
Thunkar Dec 21, 2023
81c7978
chore: try to build noir_wasm with yarn
sirasistant Dec 21, 2023
6335dc8
chore: build the fixtures on test
sirasistant Dec 21, 2023
edbe2fb
chore: add nargo to path
sirasistant Dec 21, 2023
c29145b
Fix types
Thunkar Dec 21, 2023
777d590
Used require for cjs import
Thunkar Dec 21, 2023
6efba0c
Moved integration tests to the correct package
Thunkar Dec 21, 2023
f35632e
Merge branch 'master' of github.com:noir-lang/noir into gj/noir_wasm
Thunkar Dec 21, 2023
3a0c688
Updated lock
Thunkar Dec 21, 2023
f983373
Fixed test loader
Thunkar Dec 21, 2023
4eb60f0
Fixed lock, module resolution
Thunkar Dec 21, 2023
9ebe032
Merge branch 'master' into gj/noir_wasm
Thunkar Dec 21, 2023
23f8b6e
chore: renames and removal of duplicated types
sirasistant Dec 22, 2023
e3b61ff
chore: zip dependency in test
sirasistant Dec 22, 2023
e2ec562
Merge branch 'master' into gj/noir_wasm
Thunkar Jan 2, 2024
d9b8200
Merge branch 'master' of github.com:noir-lang/noir into gj/noir_wasm
Thunkar Jan 2, 2024
64c8364
Changed compilation for better bundling
Thunkar Jan 3, 2024
61d8cf6
Merge branch 'master' into gj/noir_wasm
Thunkar Jan 5, 2024
e3156b8
logs
Thunkar Jan 5, 2024
b535ec5
Increased timeout
Thunkar Jan 5, 2024
f808f94
removed traces
Thunkar Jan 5, 2024
11fa714
Addressed PR feedback
Thunkar Jan 8, 2024
5cb08f3
Removed vscode settings
Thunkar Jan 8, 2024
a962f03
Merge branch 'master' of github.com:noir-lang/noir into gj/noir_wasm
Thunkar Jan 8, 2024
f6769b2
Merge branch 'master' of github.com:noir-lang/noir into gj/noir_wasm
Thunkar Jan 8, 2024
3cfdaad
Addressed feedback
Thunkar Jan 8, 2024
766440d
More PR comments
Thunkar Jan 8, 2024
dd7f8f4
Changed cache key
Thunkar Jan 8, 2024
e87e9bc
Merge branch 'master' of github.com:noir-lang/noir into gj/noir_wasm
Thunkar Jan 8, 2024
f0339d5
oops typo
Thunkar Jan 8, 2024
a9664df
Increased timeouts
Thunkar Jan 8, 2024
c51581e
Removed paths from tsconfig.json
Thunkar Jan 8, 2024
83cb722
Merge branch 'master' of github.com:noir-lang/noir into gj/noir_wasm
Thunkar Jan 8, 2024
cd9bb3c
Removed debug flag
Thunkar Jan 8, 2024
ca744ae
Moved timeouts to tests and not suites
Thunkar Jan 8, 2024
c8b5aa6
Make wasm-pack mimic the opt behavior of other packages
Thunkar Jan 9, 2024
8935bf0
Merge branch 'master' into gj/noir_wasm
Thunkar Jan 9, 2024
de08e5e
Update compiler/integration-tests/scripts/codegen-verifiers.sh
Thunkar Jan 9, 2024
3010201
allow embedding stdlib + wasm-opt disable
Thunkar Jan 9, 2024
c8bd920
Merge branch 'gj/noir_wasm' of github.com:noir-lang/noir into gj/noir…
Thunkar Jan 9, 2024
7115d28
fixed unused dep warning
Thunkar Jan 9, 2024
0c9e195
removed @ts-ignore, proper typings
Thunkar Jan 9, 2024
002ae8a
Merge branch 'master' of github.com:noir-lang/noir into gj/noir_wasm
Thunkar Jan 9, 2024
c15d48a
fixed compilation after clean
Thunkar Jan 9, 2024
f7f7f5e
Merge branch 'master' into gj/noir_wasm
TomAFrench Jan 11, 2024
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
7 changes: 7 additions & 0 deletions .vscode/settings.json
Thunkar marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,12 @@
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"jestrunner.projectPath": "./",
"jestrunner.debugOptions": {
"runtimeArgs": ["--experimental-vm-modules"],
"env": {
"NODE_NO_WARNINGS": 1
}
}
}
2 changes: 1 addition & 1 deletion compiler/wasm/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
extends: ["../../.eslintrc.js"],
extends: ['../../.eslintrc.js'],
};
2 changes: 2 additions & 0 deletions compiler/wasm/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
noir-script/target
dist
build
19 changes: 13 additions & 6 deletions compiler/wasm/.mocharc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
{
"extension": [
"ts"
],
"spec": "test/node/**/*.test.ts",
"require": "ts-node/register"
}
"require": "ts-node/register",
"extensions": [
"ts"
],
"spec": [
"**/!(browser)/*.test.ts"
],
"node-option": [
"experimental-specifier-resolution=node",
"loader=ts-node/esm"
]
}

5 changes: 5 additions & 0 deletions compiler/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ getrandom = { workspace = true, features = ["js"] }

[build-dependencies]
build-data.workspace = true

# `wasm-opt` is on by default in for the release profile, but it can be
# disabled by setting it to `false`
[package.metadata.wasm-pack.profile.release]
wasm-opt = false
Thunkar marked this conversation as resolved.
Show resolved Hide resolved
47 changes: 0 additions & 47 deletions compiler/wasm/build.sh

This file was deleted.

39 changes: 0 additions & 39 deletions compiler/wasm/buildPhaseCargoCommand.sh

This file was deleted.

10 changes: 0 additions & 10 deletions compiler/wasm/installPhase.sh

This file was deleted.

74 changes: 64 additions & 10 deletions compiler/wasm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,31 @@
],
"version": "0.22.0",
"license": "(MIT OR Apache-2.0)",
"main": "./nodejs/noir_wasm.js",
"types": "./web/noir_wasm.d.ts",
"module": "./web/noir_wasm.js",
"main": "dist/main.js",
"types": "dist/types",
"exports": {
"node": "./dist/node/main.js",
"default": "./dist/web/main.js",
"import": "./dist/web/main.js",
"require": "./dist/node/main.js"
},
"files": [
"nodejs",
"web",
"dist",
"package.json"
],
"sideEffects": false,
"repository": {
"type": "git",
"url": "https://github.com/noir-lang/noir.git"
},
"scripts": {
"build": "bash ./build.sh",
"serve": "webpack serve",
"build:fixtures": "cd public/fixtures && cd simple && nargo compile && cd ../with-deps && nargo compile && cd ../noir-contract && nargo compile && cd ../",
"build:webpack": "webpack",
"build": "yarn build:webpack && yarn build:fixtures",
"test": "yarn test:node && yarn test:browser",
"test:node": "env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\"}' mocha",
"test:node": "NODE_NO_WARNINGS=1 $(yarn bin mocha) --config ./.mocharc.json",
Thunkar marked this conversation as resolved.
Show resolved Hide resolved
"test:browser": "web-test-runner",
"clean": "chmod u+w web nodejs || true && rm -rf ./nodejs ./web ./target ./result",
"clean": "rm -rf ./build ./target ./dist public/fixtures/simple/target public/fixtures/with-deps/target public/fixtures/noir-contract/target",
Thunkar marked this conversation as resolved.
Show resolved Hide resolved
"nightly:version": "jq --arg new_version \"-$(git rev-parse --short HEAD)$1\" '.version = .version + $new_version' package.json > package-tmp.json && mv package-tmp.json package.json",
"publish": "echo 📡 publishing `$npm_package_name` && yarn npm publish",
"lint": "NODE_NO_WARNINGS=1 eslint . --ext .ts --ignore-path ./.eslintignore --max-warnings 0",
Expand All @@ -32,9 +38,57 @@
},
"devDependencies": {
"@esm-bundle/chai": "^4.3.4-fix.0",
"@jest/globals": "^29.7.0",
"@ltd/j-toml": "^1.38.0",
"@types/babel__preset-env": "^7",
"@types/chai": "^4",
"@types/chai-as-promised": "^7.1.8",
"@types/lodash.capitalize": "^4",
"@types/lodash.compact": "^3",
"@types/lodash.times": "^4",
"@types/lodash.upperfirst": "^4",
"@types/mocha": "^10.0.6",
"@types/mocha-each": "^2",
"@types/node": "^20.10.0",
"@types/pako": "^2",
"@types/path-browserify": "^1",
"@types/readable-stream": "^4",
"@types/sinon": "^17",
"@wasm-tool/wasm-pack-plugin": "^1.7.0",
"@web/dev-server-esbuild": "^0.3.6",
"@web/test-runner": "^0.15.3",
"@web/test-runner-playwright": "^0.10.0",
"mocha": "^10.2.0"
Thunkar marked this conversation as resolved.
Show resolved Hide resolved
Thunkar marked this conversation as resolved.
Show resolved Hide resolved
"assert": "^2.1.0",
Thunkar marked this conversation as resolved.
Show resolved Hide resolved
"browserify-fs": "^1.0.0",
"buffer": "^6.0.3",
"chai": "^4.3.10",
"copy-webpack-plugin": "^11.0.0",
"cross-env": "^7.0.3",
"file-loader": "^6.2.0",
"html-webpack-plugin": "^5.5.4",
"lodash.capitalize": "^4.2.1",
"lodash.compact": "^3.0.1",
"lodash.times": "^4.3.2",
"lodash.upperfirst": "^4.3.1",
"memfs": "^4.6.0",
"mocha": "^10.2.0",
"mocha-each": "^2.0.1",
"pako": "^2.1.0",
Thunkar marked this conversation as resolved.
Show resolved Hide resolved
"path-browserify": "^1.0.1",
"playwright": "^1.40.1",
"process": "^0.11.10",
"readable-stream": "^4.4.2",
"sinon": "^17.0.1",
"text-encoding": "^0.7.0",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"typescript": "~5.2.2",
"unzipit": "^1.4.3",
"url": "^0.11.3",
"util": "^0.12.5",
"webpack": "^5.49.0",
"webpack-cli": "^4.7.2",
"webpack-dev-server": "^4.15.1"
Thunkar marked this conversation as resolved.
Show resolved Hide resolved
}
}
7 changes: 7 additions & 0 deletions compiler/wasm/public/fixtures/deps/lib-c/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "lib_c"
authors = [""]
compiler_version = ">=0.18.0"
type = "lib"

[dependencies]
1 change: 1 addition & 0 deletions compiler/wasm/public/fixtures/deps/lib-c/src/lib.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod module;
1 change: 1 addition & 0 deletions compiler/wasm/public/fixtures/deps/lib-c/src/module.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod foo;
3 changes: 3 additions & 0 deletions compiler/wasm/public/fixtures/deps/lib-c/src/module/foo.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub fn bar(param: Field) -> Field {
dep::std::hash::pedersen_hash([param])
}
Binary file added compiler/wasm/public/fixtures/deps/test_lib.zip
Binary file not shown.
8 changes: 8 additions & 0 deletions compiler/wasm/public/fixtures/noir-contract/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "test"
authors = [""]
compiler_version = ">=0.18.0"
type = "contract"

[dependencies]
test = { path = "../deps/lib-c" }
12 changes: 12 additions & 0 deletions compiler/wasm/public/fixtures/noir-contract/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
contract TestContract {
use dep::test::module::foo;

fn constructor(param: Field, pub_param: pub Field) -> pub [Field; 2] {
[foo::bar(param), param + pub_param]
}

open fn openFunction() -> pub Field {
42
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ type="bin"
authors = [""]

[dependencies]
lib_a = { path="../lib-a" }
lib_a = { path="../deps/lib-a" }
26 changes: 26 additions & 0 deletions compiler/wasm/src/index.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { FileManager } from './noir/file-manager/file-manager';
import { createNodejsFileManager } from './noir/file-manager/nodejs-file-manager';
import { NoirWasmContractCompiler } from './noir/noir-wasm-compiler';
import { LogData, LogFn } from './utils';

async function compile(fileManager: FileManager, projectPath?: string, logFn?: LogFn) {
const cjs = await require('../build/cjs');
const compiler = await NoirWasmContractCompiler.new(
fileManager,
projectPath ?? fileManager.getDataDir(),
cjs,
new cjs.PathToFileSourceMap(),
{
log:
logFn ??
function (msg: string, _data?: LogData) {
console.log(msg);
},
},
);
return await compiler.compile();
}

const createFileManager = createNodejsFileManager;

export { compile, createFileManager };
27 changes: 27 additions & 0 deletions compiler/wasm/src/index.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { FileManager } from './noir/file-manager/file-manager';
import { createNodejsFileManager } from './noir/file-manager/nodejs-file-manager';
import { NoirWasmContractCompiler } from './noir/noir-wasm-compiler';
import { LogData, LogFn } from './utils';

async function compile(fileManager: FileManager, projectPath?: string, logFn?: LogFn) {
const esm = await import('../build/esm');
await esm.default;
const compiler = await NoirWasmContractCompiler.new(
fileManager,
projectPath ?? fileManager.getDataDir(),
esm,
new esm.PathToFileSourceMap(),
{
log:
logFn ??
function (msg: string, _data?: LogData) {
console.log(msg);
},
},
);
return await compiler.compile();
}

const createFileManager = createNodejsFileManager;

export { compile, createFileManager };
Loading
Loading