@noir-lang/noir_wasm 0.24.0 → 0.25.0-265bd8b.nightly

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,7 @@
3
3
  "collaborators": [
4
4
  "The Noir Team <team@noir-lang.org>"
5
5
  ],
6
- "version": "0.24.0",
6
+ "version": "0.25.0",
7
7
  "license": "MIT OR Apache-2.0",
8
8
  "files": [
9
9
  "index_bg.wasm",
@@ -3,7 +3,7 @@
3
3
  "collaborators": [
4
4
  "The Noir Team <team@noir-lang.org>"
5
5
  ],
6
- "version": "0.24.0",
6
+ "version": "0.25.0",
7
7
  "license": "MIT OR Apache-2.0",
8
8
  "files": [
9
9
  "index_bg.wasm",
Binary file
package/dist/node/main.js CHANGED
@@ -32,12 +32,6 @@ function takeObject(idx) {
32
32
  return ret;
33
33
  }
34
34
 
35
- function _assertBoolean(n) {
36
- if (typeof(n) !== 'boolean') {
37
- throw new Error('expected a boolean argument');
38
- }
39
- }
40
-
41
35
  let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
42
36
 
43
37
  cachedTextDecoder.decode();
@@ -61,8 +55,6 @@ function addHeapObject(obj) {
61
55
  const idx = heap_next;
62
56
  heap_next = heap[idx];
63
57
 
64
- if (typeof(heap_next) !== 'number') throw new Error('corrupt heap');
65
-
66
58
  heap[idx] = obj;
67
59
  return idx;
68
60
  }
@@ -86,8 +78,6 @@ const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
86
78
 
87
79
  function passStringToWasm0(arg, malloc, realloc) {
88
80
 
89
- if (typeof(arg) !== 'string') throw new Error('expected a string argument');
90
-
91
81
  if (realloc === undefined) {
92
82
  const buf = cachedTextEncoder.encode(arg);
93
83
  const ptr = malloc(buf.length) >>> 0;
@@ -116,7 +106,7 @@ function passStringToWasm0(arg, malloc, realloc) {
116
106
  ptr = realloc(ptr, len, len = offset + arg.length * 3) >>> 0;
117
107
  const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
118
108
  const ret = encodeString(arg, view);
119
- if (ret.read !== arg.length) throw new Error('failed to pass whole string');
109
+
120
110
  offset += ret.written;
121
111
  }
122
112
 
@@ -202,26 +192,6 @@ function debugString(val) {
202
192
  return className;
203
193
  }
204
194
 
205
- function logError(f, args) {
206
- try {
207
- return f.apply(this, args);
208
- } catch (e) {
209
- let error = (function () {
210
- try {
211
- return e instanceof Error ? `${e.message}\n\nStack:\n${e.stack}` : e.toString();
212
- } catch(_) {
213
- return "<failed to stringify thrown value>";
214
- }
215
- }());
216
- console.error("wasm-bindgen: imported JS function that was not marked as `catch` threw an error:", error);
217
- throw e;
218
- }
219
- }
220
-
221
- function _assertNum(n) {
222
- if (typeof(n) !== 'number') throw new Error('expected a number argument');
223
- }
224
-
225
195
  function _assertClass(instance, klass) {
226
196
  if (!(instance instanceof klass)) {
227
197
  throw new Error(`expected instance of ${klass.name}`);
@@ -229,26 +199,21 @@ function _assertClass(instance, klass) {
229
199
  return instance.ptr;
230
200
  }
231
201
  /**
202
+ * This is a method that exposes the same API as `compile`
203
+ * But uses the Context based APi internally
232
204
  * @param {string} entry_point
233
- * @param {boolean | undefined} contracts
234
205
  * @param {DependencyGraph | undefined} dependency_graph
235
206
  * @param {PathToFileSourceMap} file_source_map
236
- * @returns {CompileResult}
207
+ * @returns {ProgramCompileResult}
237
208
  */
238
- module.exports.compile = function(entry_point, contracts, dependency_graph, file_source_map) {
209
+ module.exports.compile_program_ = function(entry_point, dependency_graph, file_source_map) {
239
210
  try {
240
211
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
241
212
  const ptr0 = passStringToWasm0(entry_point, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
242
213
  const len0 = WASM_VECTOR_LEN;
243
- if (!isLikeNone(contracts)) {
244
- _assertBoolean(contracts);
245
- }
246
214
  _assertClass(file_source_map, PathToFileSourceMap);
247
- if (file_source_map.__wbg_ptr === 0) {
248
- throw new Error('Attempt to use a moved value');
249
- }
250
215
  var ptr1 = file_source_map.__destroy_into_raw();
251
- wasm.compile(retptr, ptr0, len0, isLikeNone(contracts) ? 0xFFFFFF : contracts ? 1 : 0, isLikeNone(dependency_graph) ? 0 : addHeapObject(dependency_graph), ptr1);
216
+ wasm.compile_program_(retptr, ptr0, len0, isLikeNone(dependency_graph) ? 0 : addHeapObject(dependency_graph), ptr1);
252
217
  var r0 = getInt32Memory0()[retptr / 4 + 0];
253
218
  var r1 = getInt32Memory0()[retptr / 4 + 1];
254
219
  var r2 = getInt32Memory0()[retptr / 4 + 2];
@@ -265,25 +230,18 @@ module.exports.compile = function(entry_point, contracts, dependency_graph, file
265
230
  * This is a method that exposes the same API as `compile`
266
231
  * But uses the Context based APi internally
267
232
  * @param {string} entry_point
268
- * @param {boolean | undefined} contracts
269
233
  * @param {DependencyGraph | undefined} dependency_graph
270
234
  * @param {PathToFileSourceMap} file_source_map
271
- * @returns {CompileResult}
235
+ * @returns {ContractCompileResult}
272
236
  */
273
- module.exports.compile_ = function(entry_point, contracts, dependency_graph, file_source_map) {
237
+ module.exports.compile_contract_ = function(entry_point, dependency_graph, file_source_map) {
274
238
  try {
275
239
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
276
240
  const ptr0 = passStringToWasm0(entry_point, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
277
241
  const len0 = WASM_VECTOR_LEN;
278
- if (!isLikeNone(contracts)) {
279
- _assertBoolean(contracts);
280
- }
281
242
  _assertClass(file_source_map, PathToFileSourceMap);
282
- if (file_source_map.__wbg_ptr === 0) {
283
- throw new Error('Attempt to use a moved value');
284
- }
285
243
  var ptr1 = file_source_map.__destroy_into_raw();
286
- wasm.compile_(retptr, ptr0, len0, isLikeNone(contracts) ? 0xFFFFFF : contracts ? 1 : 0, isLikeNone(dependency_graph) ? 0 : addHeapObject(dependency_graph), ptr1);
244
+ wasm.compile_contract_(retptr, ptr0, len0, isLikeNone(dependency_graph) ? 0 : addHeapObject(dependency_graph), ptr1);
287
245
  var r0 = getInt32Memory0()[retptr / 4 + 0];
288
246
  var r1 = getInt32Memory0()[retptr / 4 + 1];
289
247
  var r2 = getInt32Memory0()[retptr / 4 + 2];
@@ -297,10 +255,10 @@ module.exports.compile_ = function(entry_point, contracts, dependency_graph, fil
297
255
  };
298
256
 
299
257
  /**
300
- * @param {string} filter
258
+ * @param {string} level
301
259
  */
302
- module.exports.init_log_level = function(filter) {
303
- const ptr0 = passStringToWasm0(filter, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
260
+ module.exports.init_log_level = function(level) {
261
+ const ptr0 = passStringToWasm0(level, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
304
262
  const len0 = WASM_VECTOR_LEN;
305
263
  wasm.init_log_level(ptr0, len0);
306
264
  };
@@ -313,6 +271,58 @@ module.exports.build_info = function() {
313
271
  return takeObject(ret);
314
272
  };
315
273
 
274
+ /**
275
+ * @param {string} entry_point
276
+ * @param {DependencyGraph | undefined} dependency_graph
277
+ * @param {PathToFileSourceMap} file_source_map
278
+ * @returns {ProgramCompileResult}
279
+ */
280
+ module.exports.compile_program = function(entry_point, dependency_graph, file_source_map) {
281
+ try {
282
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
283
+ const ptr0 = passStringToWasm0(entry_point, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
284
+ const len0 = WASM_VECTOR_LEN;
285
+ _assertClass(file_source_map, PathToFileSourceMap);
286
+ var ptr1 = file_source_map.__destroy_into_raw();
287
+ wasm.compile_program(retptr, ptr0, len0, isLikeNone(dependency_graph) ? 0 : addHeapObject(dependency_graph), ptr1);
288
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
289
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
290
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
291
+ if (r2) {
292
+ throw takeObject(r1);
293
+ }
294
+ return takeObject(r0);
295
+ } finally {
296
+ wasm.__wbindgen_add_to_stack_pointer(16);
297
+ }
298
+ };
299
+
300
+ /**
301
+ * @param {string} entry_point
302
+ * @param {DependencyGraph | undefined} dependency_graph
303
+ * @param {PathToFileSourceMap} file_source_map
304
+ * @returns {ContractCompileResult}
305
+ */
306
+ module.exports.compile_contract = function(entry_point, dependency_graph, file_source_map) {
307
+ try {
308
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
309
+ const ptr0 = passStringToWasm0(entry_point, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
310
+ const len0 = WASM_VECTOR_LEN;
311
+ _assertClass(file_source_map, PathToFileSourceMap);
312
+ var ptr1 = file_source_map.__destroy_into_raw();
313
+ wasm.compile_contract(retptr, ptr0, len0, isLikeNone(dependency_graph) ? 0 : addHeapObject(dependency_graph), ptr1);
314
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
315
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
316
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
317
+ if (r2) {
318
+ throw takeObject(r1);
319
+ }
320
+ return takeObject(r0);
321
+ } finally {
322
+ wasm.__wbindgen_add_to_stack_pointer(16);
323
+ }
324
+ };
325
+
316
326
  function handleError(f, args) {
317
327
  try {
318
328
  return f.apply(this, args);
@@ -351,9 +361,6 @@ class CompilerContext {
351
361
  */
352
362
  constructor(source_map) {
353
363
  _assertClass(source_map, PathToFileSourceMap);
354
- if (source_map.__wbg_ptr === 0) {
355
- throw new Error('Attempt to use a moved value');
356
- }
357
364
  var ptr0 = source_map.__destroy_into_raw();
358
365
  const ret = wasm.compilercontext_new(ptr0);
359
366
  return CompilerContext.__wrap(ret);
@@ -363,8 +370,6 @@ class CompilerContext {
363
370
  * @returns {CrateId}
364
371
  */
365
372
  process_root_crate(path_to_crate) {
366
- if (this.__wbg_ptr == 0) throw new Error('Attempt to use a moved value');
367
- _assertNum(this.__wbg_ptr);
368
373
  const ptr0 = passStringToWasm0(path_to_crate, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
369
374
  const len0 = WASM_VECTOR_LEN;
370
375
  const ret = wasm.compilercontext_process_root_crate(this.__wbg_ptr, ptr0, len0);
@@ -375,8 +380,6 @@ class CompilerContext {
375
380
  * @returns {CrateId}
376
381
  */
377
382
  process_dependency_crate(path_to_crate) {
378
- if (this.__wbg_ptr == 0) throw new Error('Attempt to use a moved value');
379
- _assertNum(this.__wbg_ptr);
380
383
  const ptr0 = passStringToWasm0(path_to_crate, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
381
384
  const len0 = WASM_VECTOR_LEN;
382
385
  const ret = wasm.compilercontext_process_dependency_crate(this.__wbg_ptr, ptr0, len0);
@@ -389,19 +392,11 @@ class CompilerContext {
389
392
  */
390
393
  add_dependency_edge(crate_name, from, to) {
391
394
  try {
392
- if (this.__wbg_ptr == 0) throw new Error('Attempt to use a moved value');
393
395
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
394
- _assertNum(this.__wbg_ptr);
395
396
  const ptr0 = passStringToWasm0(crate_name, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
396
397
  const len0 = WASM_VECTOR_LEN;
397
398
  _assertClass(from, CrateId);
398
- if (from.__wbg_ptr === 0) {
399
- throw new Error('Attempt to use a moved value');
400
- }
401
399
  _assertClass(to, CrateId);
402
- if (to.__wbg_ptr === 0) {
403
- throw new Error('Attempt to use a moved value');
404
- }
405
400
  wasm.compilercontext_add_dependency_edge(retptr, this.__wbg_ptr, ptr0, len0, from.__wbg_ptr, to.__wbg_ptr);
406
401
  var r0 = getInt32Memory0()[retptr / 4 + 0];
407
402
  var r1 = getInt32Memory0()[retptr / 4 + 1];
@@ -414,15 +409,12 @@ class CompilerContext {
414
409
  }
415
410
  /**
416
411
  * @param {number} program_width
417
- * @returns {CompileResult}
412
+ * @returns {ProgramCompileResult}
418
413
  */
419
414
  compile_program(program_width) {
420
415
  try {
421
- if (this.__wbg_ptr == 0) throw new Error('Attempt to use a moved value');
422
416
  const ptr = this.__destroy_into_raw();
423
417
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
424
- _assertNum(ptr);
425
- _assertNum(program_width);
426
418
  wasm.compilercontext_compile_program(retptr, ptr, program_width);
427
419
  var r0 = getInt32Memory0()[retptr / 4 + 0];
428
420
  var r1 = getInt32Memory0()[retptr / 4 + 1];
@@ -437,15 +429,12 @@ class CompilerContext {
437
429
  }
438
430
  /**
439
431
  * @param {number} program_width
440
- * @returns {CompileResult}
432
+ * @returns {ContractCompileResult}
441
433
  */
442
434
  compile_contract(program_width) {
443
435
  try {
444
- if (this.__wbg_ptr == 0) throw new Error('Attempt to use a moved value');
445
436
  const ptr = this.__destroy_into_raw();
446
437
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
447
- _assertNum(ptr);
448
- _assertNum(program_width);
449
438
  wasm.compilercontext_compile_contract(retptr, ptr, program_width);
450
439
  var r0 = getInt32Memory0()[retptr / 4 + 0];
451
440
  var r1 = getInt32Memory0()[retptr / 4 + 1];
@@ -464,10 +453,6 @@ module.exports.CompilerContext = CompilerContext;
464
453
  */
465
454
  class CrateId {
466
455
 
467
- constructor() {
468
- throw new Error('cannot invoke `new` directly');
469
- }
470
-
471
456
  static __wrap(ptr) {
472
457
  ptr = ptr >>> 0;
473
458
  const obj = Object.create(CrateId.prototype);
@@ -524,8 +509,6 @@ class PathToFileSourceMap {
524
509
  * @returns {boolean}
525
510
  */
526
511
  add_source_code(path, source_code) {
527
- if (this.__wbg_ptr == 0) throw new Error('Attempt to use a moved value');
528
- _assertNum(this.__wbg_ptr);
529
512
  const ptr0 = passStringToWasm0(path, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
530
513
  const len0 = WASM_VECTOR_LEN;
531
514
  const ptr1 = passStringToWasm0(source_code, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
@@ -540,36 +523,35 @@ module.exports.__wbindgen_object_drop_ref = function(arg0) {
540
523
  takeObject(arg0);
541
524
  };
542
525
 
543
- module.exports.__wbg_constructor_05d6d198f3477d6f = function() { return logError(function () {
544
- const ret = new Object();
526
+ module.exports.__wbg_constructor_e8f4e1ca46363e73 = function(arg0) {
527
+ const ret = new Error(takeObject(arg0));
545
528
  return addHeapObject(ret);
546
- }, arguments) };
529
+ };
547
530
 
548
531
  module.exports.__wbindgen_is_undefined = function(arg0) {
549
532
  const ret = getObject(arg0) === undefined;
550
- _assertBoolean(ret);
551
533
  return ret;
552
534
  };
553
535
 
554
- module.exports.__wbg_constructor_e8767839abf8a966 = function() { return logError(function (arg0) {
555
- const ret = new Error(takeObject(arg0));
536
+ module.exports.__wbg_constructor_9418a5e735182315 = function() {
537
+ const ret = new Object();
556
538
  return addHeapObject(ret);
557
- }, arguments) };
539
+ };
558
540
 
559
- module.exports.__wbg_new_abda76e883ba8a5f = function() { return logError(function () {
541
+ module.exports.__wbg_new_abda76e883ba8a5f = function() {
560
542
  const ret = new Error();
561
543
  return addHeapObject(ret);
562
- }, arguments) };
544
+ };
563
545
 
564
- module.exports.__wbg_stack_658279fe44541cf6 = function() { return logError(function (arg0, arg1) {
546
+ module.exports.__wbg_stack_658279fe44541cf6 = function(arg0, arg1) {
565
547
  const ret = getObject(arg1).stack;
566
548
  const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
567
549
  const len1 = WASM_VECTOR_LEN;
568
550
  getInt32Memory0()[arg0 / 4 + 1] = len1;
569
551
  getInt32Memory0()[arg0 / 4 + 0] = ptr1;
570
- }, arguments) };
552
+ };
571
553
 
572
- module.exports.__wbg_error_f851667af71bcfc6 = function() { return logError(function (arg0, arg1) {
554
+ module.exports.__wbg_error_f851667af71bcfc6 = function(arg0, arg1) {
573
555
  let deferred0_0;
574
556
  let deferred0_1;
575
557
  try {
@@ -579,52 +561,44 @@ module.exports.__wbg_error_f851667af71bcfc6 = function() { return logError(funct
579
561
  } finally {
580
562
  wasm.__wbindgen_export_2(deferred0_0, deferred0_1);
581
563
  }
582
- }, arguments) };
564
+ };
583
565
 
584
566
  module.exports.__wbindgen_string_new = function(arg0, arg1) {
585
567
  const ret = getStringFromWasm0(arg0, arg1);
586
568
  return addHeapObject(ret);
587
569
  };
588
570
 
589
- module.exports.__wbg_debug_e3f6a1578e6d45ca = function() { return logError(function (arg0) {
571
+ module.exports.__wbg_debug_e3f6a1578e6d45ca = function(arg0) {
590
572
  console.debug(getObject(arg0));
591
- }, arguments) };
573
+ };
592
574
 
593
- module.exports.__wbg_debug_efabe4eb183aa5d4 = function() { return logError(function (arg0, arg1, arg2, arg3) {
575
+ module.exports.__wbg_debug_efabe4eb183aa5d4 = function(arg0, arg1, arg2, arg3) {
594
576
  console.debug(getObject(arg0), getObject(arg1), getObject(arg2), getObject(arg3));
595
- }, arguments) };
577
+ };
596
578
 
597
- module.exports.__wbg_error_a7e23606158b68b9 = function() { return logError(function (arg0) {
579
+ module.exports.__wbg_error_a7e23606158b68b9 = function(arg0) {
598
580
  console.error(getObject(arg0));
599
- }, arguments) };
581
+ };
600
582
 
601
- module.exports.__wbg_error_50f42b952a595a23 = function() { return logError(function (arg0, arg1, arg2, arg3) {
583
+ module.exports.__wbg_error_50f42b952a595a23 = function(arg0, arg1, arg2, arg3) {
602
584
  console.error(getObject(arg0), getObject(arg1), getObject(arg2), getObject(arg3));
603
- }, arguments) };
585
+ };
604
586
 
605
- module.exports.__wbg_info_05db236d79f1b785 = function() { return logError(function (arg0) {
587
+ module.exports.__wbg_info_05db236d79f1b785 = function(arg0) {
606
588
  console.info(getObject(arg0));
607
- }, arguments) };
589
+ };
608
590
 
609
- module.exports.__wbg_info_24d8f53d98f12b95 = function() { return logError(function (arg0, arg1, arg2, arg3) {
591
+ module.exports.__wbg_info_24d8f53d98f12b95 = function(arg0, arg1, arg2, arg3) {
610
592
  console.info(getObject(arg0), getObject(arg1), getObject(arg2), getObject(arg3));
611
- }, arguments) };
612
-
613
- module.exports.__wbg_log_dc06ec929fc95a20 = function() { return logError(function (arg0) {
614
- console.log(getObject(arg0));
615
- }, arguments) };
616
-
617
- module.exports.__wbg_log_2f6947e39440ae3b = function() { return logError(function (arg0, arg1, arg2, arg3, arg4) {
618
- console.log(getObject(arg0), getObject(arg1), getObject(arg2), getObject(arg3), getObject(arg4));
619
- }, arguments) };
593
+ };
620
594
 
621
- module.exports.__wbg_warn_9bdd743e9f5fe1e0 = function() { return logError(function (arg0) {
595
+ module.exports.__wbg_warn_9bdd743e9f5fe1e0 = function(arg0) {
622
596
  console.warn(getObject(arg0));
623
- }, arguments) };
597
+ };
624
598
 
625
- module.exports.__wbg_warn_8342bfbc6028193a = function() { return logError(function (arg0, arg1, arg2, arg3) {
599
+ module.exports.__wbg_warn_8342bfbc6028193a = function(arg0, arg1, arg2, arg3) {
626
600
  console.warn(getObject(arg0), getObject(arg1), getObject(arg2), getObject(arg3));
627
- }, arguments) };
601
+ };
628
602
 
629
603
  module.exports.__wbindgen_string_get = function(arg0, arg1) {
630
604
  const obj = getObject(arg1);
@@ -647,7 +621,6 @@ module.exports.__wbg_stringify_d06ad2addc54d51e = function() { return handleErro
647
621
 
648
622
  module.exports.__wbg_set_07da13cc24b69217 = function() { return handleError(function (arg0, arg1, arg2) {
649
623
  const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
650
- _assertBoolean(ret);
651
624
  return ret;
652
625
  }, arguments) };
653
626
 
@@ -1238,18 +1211,54 @@ class NoirWasmCompiler {
1238
1211
  /**
1239
1212
  * Compile EntryPoint
1240
1213
  */
1214
+ async compile_program() {
1215
+ console.log(`Compiling at ${this.#package.getEntryPointPath()}`);
1216
+ if (this.#package.getType() !== 'bin') {
1217
+ throw new Error(`Expected to find package type "bin" but found ${this.#package.getType()}`);
1218
+ }
1219
+ await this.#dependencyManager.resolveDependencies();
1220
+ this.#debugLog(`Dependencies: ${this.#dependencyManager.getPackageNames().join(', ')}`);
1221
+ try {
1222
+ const entrypoint = this.#package.getEntryPointPath();
1223
+ const deps = {
1224
+ /* eslint-disable camelcase */
1225
+ root_dependencies: this.#dependencyManager.getEntrypointDependencies(),
1226
+ library_dependencies: this.#dependencyManager.getLibraryDependencies(),
1227
+ /* eslint-enable camelcase */
1228
+ };
1229
+ const packageSources = await this.#package.getSources(this.#fm);
1230
+ const librarySources = (await Promise.all(this.#dependencyManager
1231
+ .getLibraries()
1232
+ .map(async ([alias, library]) => await library.package.getSources(this.#fm, alias)))).flat();
1233
+ [...packageSources, ...librarySources].forEach((sourceFile) => {
1234
+ this.#debugLog(`Adding source ${sourceFile.path}`);
1235
+ this.#sourceMap.add_source_code(sourceFile.path, sourceFile.source);
1236
+ });
1237
+ const result = this.#wasmCompiler.compile_program(entrypoint, deps, this.#sourceMap);
1238
+ return result;
1239
+ }
1240
+ catch (err) {
1241
+ if (err instanceof Error && err.name === 'CompileError') {
1242
+ const logs = await this.#processCompileError(err);
1243
+ for (const log of logs) {
1244
+ this.#log(log);
1245
+ }
1246
+ throw new Error(logs.join('\n'));
1247
+ }
1248
+ throw err;
1249
+ }
1250
+ }
1241
1251
  /**
1242
1252
  * Compile EntryPoint
1243
1253
  */
1244
- async compile() {
1254
+ async compile_contract() {
1245
1255
  console.log(`Compiling at ${this.#package.getEntryPointPath()}`);
1246
- if (!(this.#package.getType() === 'contract' || this.#package.getType() === 'bin')) {
1247
- throw new Error(`Only supports compiling "contract" and "bin" package types (${this.#package.getType()})`);
1256
+ if (this.#package.getType() !== 'contract') {
1257
+ throw new Error(`Expected to find package type "contract" but found ${this.#package.getType()}`);
1248
1258
  }
1249
1259
  await this.#dependencyManager.resolveDependencies();
1250
1260
  this.#debugLog(`Dependencies: ${this.#dependencyManager.getPackageNames().join(', ')}`);
1251
1261
  try {
1252
- const isContract = this.#package.getType() === 'contract';
1253
1262
  const entrypoint = this.#package.getEntryPointPath();
1254
1263
  const deps = {
1255
1264
  /* eslint-disable camelcase */
@@ -1265,10 +1274,7 @@ class NoirWasmCompiler {
1265
1274
  this.#debugLog(`Adding source ${sourceFile.path}`);
1266
1275
  this.#sourceMap.add_source_code(sourceFile.path, sourceFile.source);
1267
1276
  });
1268
- const result = this.#wasmCompiler.compile(entrypoint, isContract, deps, this.#sourceMap);
1269
- if ((isContract && !('contract' in result)) || (!isContract && !('program' in result))) {
1270
- throw new Error('Invalid compilation result');
1271
- }
1277
+ const result = this.#wasmCompiler.compile_contract(entrypoint, deps, this.#sourceMap);
1272
1278
  return result;
1273
1279
  }
1274
1280
  catch (err) {
@@ -1397,7 +1403,7 @@ class Package {
1397
1403
  * Gets this package's dependencies.
1398
1404
  */
1399
1405
  getDependencies() {
1400
- return this.#config.dependencies;
1406
+ return this.#config.dependencies ?? {};
1401
1407
  }
1402
1408
  /**
1403
1409
  * Gets this package's sources.
@@ -1409,7 +1415,12 @@ class Package {
1409
1415
  return Promise.all(handles
1410
1416
  .filter((handle) => SOURCE_EXTENSIONS.find((ext) => handle.endsWith(ext)))
1411
1417
  .map(async (file) => {
1412
- const suffix = file.replace(this.#srcPath, '');
1418
+ // Github deps are directly added to the file manager, which causes them to be missing the absolute path to the source file
1419
+ // and only include the extraction directory relative to the fm root directory
1420
+ // This regexp ensures we remove the "real" source path for all dependencies, providing the compiler with what it expects for each source file:
1421
+ // <absoluteSourcePath> -> <sourceAsString> for bin/contract packages
1422
+ // <depAlias/relativePathToSource> -> <sourceAsString> for libs
1423
+ const suffix = file.replace(new RegExp(`.*${this.#srcPath}`), '');
1413
1424
  return {
1414
1425
  path: this.getType() === 'lib' ? `${alias ? alias : this.#config.package.name}${suffix}` : file,
1415
1426
  source: (await fm.readFile(file, 'utf-8')).toString(),
@@ -12817,7 +12828,7 @@ var exports = __webpack_exports__;
12817
12828
  \***********************/
12818
12829
 
12819
12830
  Object.defineProperty(exports, "__esModule", ({ value: true }));
12820
- exports.inflateDebugSymbols = exports.createFileManager = exports.compile = void 0;
12831
+ exports.inflateDebugSymbols = exports.createFileManager = exports.compile_contract = exports.compile_program = exports.compile = void 0;
12821
12832
  const nodejs_file_manager_1 = __webpack_require__(/*! ./noir/file-manager/nodejs-file-manager */ "./src/noir/file-manager/nodejs-file-manager.ts");
12822
12833
  const noir_wasm_compiler_1 = __webpack_require__(/*! ./noir/noir-wasm-compiler */ "./src/noir/noir-wasm-compiler.ts");
12823
12834
  const debug_1 = __webpack_require__(/*! ./noir/debug */ "./src/noir/debug.ts");
@@ -12834,30 +12845,71 @@ Object.defineProperty(exports, "inflateDebugSymbols", ({ enumerable: true, get:
12834
12845
  * ```typescript
12835
12846
  * // Node.js
12836
12847
  *
12837
- * import { compile, createFileManager } from '@noir-lang/noir_wasm';
12848
+ * import { compile_program, createFileManager } from '@noir-lang/noir_wasm';
12849
+ *
12850
+ * const fm = createFileManager(myProjectPath);
12851
+ * const myCompiledCode = await compile_program(fm);
12852
+ * ```
12853
+ *
12854
+ * ```typescript
12855
+ * // Browser
12856
+ *
12857
+ * import { compile_program, createFileManager } from '@noir-lang/noir_wasm';
12858
+ *
12859
+ * const fm = createFileManager('/');
12860
+ * for (const path of files) {
12861
+ * await fm.writeFile(path, await getFileAsStream(path));
12862
+ * }
12863
+ * const myCompiledCode = await compile_program(fm);
12864
+ * ```
12865
+ */
12866
+ async function compile_program(fileManager, projectPath, logFn, debugLogFn) {
12867
+ const compiler = await setup_compiler(fileManager, projectPath, logFn, debugLogFn);
12868
+ return await compiler.compile_program();
12869
+ }
12870
+ exports.compile = compile_program;
12871
+ exports.compile_program = compile_program;
12872
+ /**
12873
+ * Compiles a Noir project
12874
+ *
12875
+ * @param fileManager - The file manager to use
12876
+ * @param projectPath - The path to the project inside the file manager. Defaults to the root of the file manager
12877
+ * @param logFn - A logging function. If not provided, console.log will be used
12878
+ * @param debugLogFn - A debug logging function. If not provided, logFn will be used
12879
+ *
12880
+ * @example
12881
+ * ```typescript
12882
+ * // Node.js
12883
+ *
12884
+ * import { compile_contract, createFileManager } from '@noir-lang/noir_wasm';
12838
12885
  *
12839
12886
  * const fm = createFileManager(myProjectPath);
12840
- * const myCompiledCode = await compile(fm);
12887
+ * const myCompiledCode = await compile_contract(fm);
12841
12888
  * ```
12842
12889
  *
12843
12890
  * ```typescript
12844
12891
  * // Browser
12845
12892
  *
12846
- * import { compile, createFileManager } from '@noir-lang/noir_wasm';
12893
+ * import { compile_contract, createFileManager } from '@noir-lang/noir_wasm';
12847
12894
  *
12848
12895
  * const fm = createFileManager('/');
12849
12896
  * for (const path of files) {
12850
12897
  * await fm.writeFile(path, await getFileAsStream(path));
12851
12898
  * }
12852
- * const myCompiledCode = await compile(fm);
12899
+ * const myCompiledCode = await compile_contract(fm);
12853
12900
  * ```
12854
12901
  */
12855
- async function compile(fileManager, projectPath, logFn, debugLogFn) {
12902
+ async function compile_contract(fileManager, projectPath, logFn, debugLogFn) {
12903
+ const compiler = await setup_compiler(fileManager, projectPath, logFn, debugLogFn);
12904
+ return await compiler.compile_contract();
12905
+ }
12906
+ exports.compile_contract = compile_contract;
12907
+ async function setup_compiler(fileManager, projectPath, logFn, debugLogFn) {
12856
12908
  if (logFn && !debugLogFn) {
12857
12909
  debugLogFn = logFn;
12858
12910
  }
12859
12911
  const cjs = await __webpack_require__(/*! ../build/cjs */ "./build/cjs/index.js");
12860
- const compiler = await noir_wasm_compiler_1.NoirWasmCompiler.new(fileManager, projectPath ?? fileManager.getDataDir(), cjs, new cjs.PathToFileSourceMap(), {
12912
+ return await noir_wasm_compiler_1.NoirWasmCompiler.new(fileManager, projectPath ?? fileManager.getDataDir(), cjs, new cjs.PathToFileSourceMap(), {
12861
12913
  log: logFn ??
12862
12914
  function (msg, data) {
12863
12915
  if (data) {
@@ -12877,9 +12929,7 @@ async function compile(fileManager, projectPath, logFn, debugLogFn) {
12877
12929
  }
12878
12930
  },
12879
12931
  });
12880
- return await compiler.compile();
12881
12932
  }
12882
- exports.compile = compile;
12883
12933
  const createFileManager = nodejs_file_manager_1.createNodejsFileManager;
12884
12934
  exports.createFileManager = createFileManager;
12885
12935