Skip to content

Commit

Permalink
fix: wasm-compiler bin package type (#3254)
Browse files Browse the repository at this point in the history
This PR updates the wasm-compiler to recognize, but not accept the `bin`
package type in a Nargo.toml file. Previously it would knew about
`binary` but the correct value is `bin`.

A couple of commits taken from #3250

---------

Co-authored-by: Dan Lee <dan@aztecprotocol.com>
  • Loading branch information
alexghr and dan-aztec authored Nov 7, 2023
1 parent b7fbe19 commit 2d50f11
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion yarn-project/foundation/src/noir/noir_package_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const noirLocalDependencySchema = z.object({
const noirPackageConfigSchema = z.object({
package: z.object({
name: z.string().default(''),
type: z.enum(['lib', 'contract', 'binary']).default('binary'),
type: z.enum(['lib', 'contract', 'bin']).default('bin'),
entry: z.string().optional(),
description: z.string().optional(),
authors: z.array(z.string()).optional(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,20 @@ export class NoirWasmContractCompiler {
* Compiles the project.
*/
public async compile(): Promise<NoirCompilationArtifacts[]> {
const isContract = this.#package.getType() === 'contract';
// limit to contracts-only because the rest of the pipeline only supports processing contracts
if (!isContract) {
throw new Error('Noir project is not a contract');
}

this.#debugLog(`Compiling contract at ${this.#package.getEntryPointPath()}`);
await this.#dependencyManager.resolveDependencies();
this.#debugLog(`Dependencies: ${this.#dependencyManager.getPackageNames().join(', ')}`);

initializeResolver(this.#resolveFile);

try {
const result = compile(this.#package.getEntryPointPath(), true, {
const result = compile(this.#package.getEntryPointPath(), isContract, {
/* eslint-disable camelcase */
root_dependencies: this.#dependencyManager.getEntrypointDependencies(),
library_dependencies: this.#dependencyManager.getLibraryDependencies(),
Expand All @@ -105,6 +111,7 @@ export class NoirWasmContractCompiler {
} catch (err) {
if (err instanceof Error && err.name === 'CompileError') {
this.#processCompileError(err as CompileError);
throw new Error('Compilation failed');
}

throw err;
Expand All @@ -121,7 +128,6 @@ export class NoirWasmContractCompiler {
};

#processCompileError(err: CompileError): void {
this.#log('Error compiling contract');
for (const diag of err.diagnostics) {
this.#log(` ${diag.message}`);
const contents = this.#resolveFile(diag.file);
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/noir-compiler/src/compile/noir/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class NoirPackage {
entrypoint = 'lib.nr';
break;
case 'contract':
case 'binary':
case 'bin':
entrypoint = 'main.nr';
break;
default:
Expand Down

0 comments on commit 2d50f11

Please sign in to comment.