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

reorganize build process #2012

Merged
merged 29 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
79b7989
reorganize build process
lastmjs Aug 21, 2024
3597bc7
try to get the stable tests to pass
lastmjs Aug 23, 2024
92afbaf
reorganize
lastmjs Aug 23, 2024
f82159b
fix the azle package path variable
lastmjs Aug 23, 2024
7a8f924
move the new test for http-server into http-server, change dfx.json e…
lastmjs Aug 23, 2024
de999b5
fix broken class_syntax tests
lastmjs Aug 23, 2024
3efa078
remove candid_gen automatic
lastmjs Aug 23, 2024
074c1de
remove newlines in dfx.json and fix phone-book tsconfig.json
lastmjs Aug 26, 2024
8133d75
clean up the stable stuff
lastmjs Aug 26, 2024
0485b49
experimental mode moving along, ensuring stable is only stable
lastmjs Aug 27, 2024
8bc3641
greatly refactor the wasm binary manpipulation, tis beautiful now
lastmjs Aug 27, 2024
b8c096e
experimental section nearly complete
lastmjs Aug 27, 2024
1f93354
Merge branch 'main' of github.com:demergent-labs/azle into build_process
lastmjs Aug 27, 2024
7658e41
fix dfx.json files to use custom inside of functional_syntax
lastmjs Aug 27, 2024
d0bf32e
update dfx.json files in http_server tests
lastmjs Aug 27, 2024
14f8ad6
fix the example dfx.json
lastmjs Aug 27, 2024
bc9ece9
remove candid_gen automatic in property testS
lastmjs Aug 27, 2024
c21f1df
allow basic asset uploading
lastmjs Aug 27, 2024
60b8319
add build assets
lastmjs Aug 27, 2024
0171f98
add candid_gen http
lastmjs Aug 27, 2024
3aaecdc
update a couple bitcoin examples with candid_gen http
lastmjs Aug 27, 2024
9cc86c6
fix nest and typeorm problem
lastmjs Aug 27, 2024
6f108c9
attempt to fix autoreload file watching
lastmjs Aug 27, 2024
ca4916d
remove compile directory mostly
lastmjs Aug 27, 2024
b9ee2a2
move rust
lastmjs Aug 27, 2024
a903e55
stop experimental dfx.json values from being used in a stable canister
lastmjs Aug 28, 2024
c48acd5
handle TODOs in build/experimental
lastmjs Aug 28, 2024
de9bea4
change global variable to azle node wasm environment
lastmjs Aug 28, 2024
a6b1d97
update wasm binaries
lastmjs Aug 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ jobs:
"tests/end_to_end/candid_rpc/class_syntax/motoko_examples/superheroes",
"tests/end_to_end/candid_rpc/class_syntax/motoko_examples/threshold_ecdsa",
"tests/end_to_end/candid_rpc/class_syntax/motoko_examples/whoami",
"tests/end_to_end/candid_rpc/class_syntax/new",
"tests/end_to_end/candid_rpc/class_syntax/new_candid_rpc",
"tests/end_to_end/candid_rpc/class_syntax/notify_raw",
"tests/end_to_end/candid_rpc/class_syntax/null_example",
Expand Down Expand Up @@ -284,6 +283,7 @@ jobs:
"tests/end_to_end/http_server/internet_identity",
"tests/end_to_end/http_server/large_files",
"tests/end_to_end/http_server/nest",
"tests/end_to_end/http_server/new",
"tests/end_to_end/http_server/open_value_sharing",
"tests/end_to_end/http_server/sqlite",
"tests/end_to_end/http_server/sqlite_drizzle",
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[workspace]
members = ["src/compiler/rust/canister", "src/compiler/rust/open_value_sharing"]
members = ["src/build/rust/canister", "src/build/rust/open_value_sharing"]
Binary file modified canister_templates/experimental.wasm
Binary file not shown.
Binary file modified canister_templates/stable.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion dfx_extension/extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"canister_type": {
"defaults": {
"candid": ".azle/{{canister_name}}/{{canister_name}}.did",
"build": "npx azle {{canister_name}}",
"build": "npx azle compile {{canister_name}}",
"post_install": "npx azle upload-assets {{canister_name}}",
"wasm": ".azle/{{canister_name}}/{{canister_name}}.wasm",
"gzip": true,
Expand Down
5 changes: 3 additions & 2 deletions examples/basic_bitcoin/dfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
"basic_bitcoin": {
"type": "azle",
"main": "src/index.ts",
"env": ["BITCOIN_NETWORK"],
"custom": {
"experimental": true
"experimental": true,
"candid_gen": "http",
"env": ["BITCOIN_NETWORK"]
}
}
},
Expand Down
5 changes: 3 additions & 2 deletions examples/bitcoin_psbt/dfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
"bitcoin_psbt": {
"type": "azle",
"main": "src/index.ts",
"env": ["BITCOIN_NETWORK"],
"custom": {
"experimental": true
"experimental": true,
"candid_gen": "http",
"env": ["BITCOIN_NETWORK"]
}
}
},
Expand Down
9 changes: 6 additions & 3 deletions examples/ckbtc/dfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@
"type": "azle",
"main": "wallet/backend/index.ts",
"candid": "wallet/backend/index.did",
"candid_gen": "custom",
"env": ["CK_BTC_PRINCIPAL", "MINTER_PRINCIPAL"],
"assets": [["minter/minter.did", "minter/minter.did"]],
"declarations": {
"node_compatibility": true,
"output": "wallet/frontend/dfx_generated/wallet_backend"
},
"custom": {
"experimental": true,
"assets": [["minter/minter.did", "minter/minter.did"]],
"candid_gen": "custom",
"env": ["CK_BTC_PRINCIPAL", "MINTER_PRINCIPAL"]
}
},
"wallet_frontend": {
Expand Down
6 changes: 3 additions & 3 deletions examples/hello_world/dfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"backend": {
"type": "azle",
"main": "src/backend/index.ts",
"assets": [["src/frontend/dist", "dist"]],
"build_assets": "npm run build",
"custom": {
"experimental": true
"experimental": true,
"assets": [["src/frontend/dist", "dist"]],
"build_assets": "npm run build"
}
}
}
Expand Down
1 change: 0 additions & 1 deletion examples/hello_world_candid_rpc/dfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"hello_world": {
"type": "azle",
"main": "src/index.ts",
"candid_gen": "automatic",
"declarations": {
"output": "test/dfx_generated/hello_world",
"node_compatibility": true
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"type": "module",
"bin": {
"azle": "./src/compiler/index.ts"
"azle": "./src/build/index.ts"
},
"main": "./src/lib/stable/index.ts",
"repository": {
Expand Down
102 changes: 102 additions & 0 deletions src/build/experimental/commands/compile/candid_and_method_meta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { IOType } from 'child_process';
import { readFile } from 'fs/promises';
import { join } from 'path';

import { execute } from '../../../stable/commands/compile/candid_and_method_meta/execute';
import { AZLE_PACKAGE_PATH } from '../../../stable/utils/global_paths';
import {
CandidAndMethodMeta,
CandidGen,
MethodMeta
} from '../../../stable/utils/types';
import { WasmData } from '../../utils/types';
import { getWasmBinary } from './wasm_binary';

export async function getCandidAndMethodMeta(
canisterName: string,
candidGen: CandidGen | undefined,
canisterPath: string,
candidPath: string,
js: string,
ioType: IOType,
wasmData: WasmData
): Promise<CandidAndMethodMeta> {
if (
candidGen === undefined ||
candidGen === 'automatic' ||
candidGen === 'custom'
) {
return await handleAutomaticAndCustom(
candidGen,
candidPath,
canisterName,
ioType,
js,
wasmData,
canisterPath
);
}

if (candidGen === 'http') {
return await handleHttp();
}

throw new Error(`dfx.json: "candid_gen": "${candidGen}" is not supported`);
}

async function handleAutomaticAndCustom(
candidGen: CandidGen | undefined,
candidPath: string,
canisterName: string,
ioType: IOType,
js: string,
wasmData: WasmData,
canisterPath: string
): Promise<CandidAndMethodMeta> {
const wasmBinary = await getWasmBinary(
canisterName,
ioType,
js,
wasmData,
canisterPath
);

const { candid, methodMeta } = await execute(wasmBinary);

return {
candid:
candidGen === 'custom'
? (await readFile(candidPath)).toString()
: candid,
methodMeta
};
}

async function handleHttp(): Promise<CandidAndMethodMeta> {
const candid = (
await readFile(join(AZLE_PACKAGE_PATH, 'server.did'))
).toString();

const methodMeta: MethodMeta = {
queries: [
{
name: 'http_request',
index: 0,
composite: true
}
],
updates: [
{
name: 'http_request_update',
index: 1
}
],
init: { name: 'init', index: 2 },
post_upgrade: { name: 'postUpgrade', index: 3 }
};

return {
candid,
methodMeta
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import { Actor, ActorMethod, ActorSubclass } from '@dfinity/agent';
import { watch } from 'chokidar';
import { writeFile } from 'fs/promises';

import { createAuthenticatedAgent } from '../../../dfx';
import { getCanisterJavaScript } from '../get_canister_javascript';
import { generateUploaderIdentity } from '../uploader_identity';
import { ok } from '../utils/result';
import { createAuthenticatedAgent } from '../../../../../../dfx';
import { generateUploaderIdentity } from '../../upload_assets/uploader_identity';
import { compile as compileJavaScript } from '../javascript';

type ActorReloadJs = ActorSubclass<_SERVICE>;
interface _SERVICE {
Expand All @@ -27,7 +26,6 @@ const esmAliases = JSON.parse(process.argv[6]);
const esmExternals = JSON.parse(process.argv[7]);
const canisterName = process.argv[8];
const postUpgradeIndex = Number(process.argv[9]);
const experimental = process.argv[10] === 'true' ? true : false;

// TODO https://github.com/demergent-labs/azle/issues/1664
const watcher = watch([`**/*.ts`, `**/*.js`], {
Expand All @@ -50,8 +48,7 @@ watcher.on('all', async (event, path) => {
actor,
reloadedJsPath,
mainPath,
wasmedgeQuickJsPath,
experimental
wasmedgeQuickJsPath
);
} catch (error) {
console.error(error);
Expand All @@ -63,28 +60,16 @@ async function reloadJs(
actor: ActorReloadJs,
reloadedJsPath: string,
mainPath: string,
wasmedgeQuickJsPath: string,
experimental: boolean
wasmedgeQuickJsPath: string
): Promise<void> {
const canisterJavaScriptResult = await getCanisterJavaScript(
const javaScript = await compileJavaScript(
mainPath,
wasmedgeQuickJsPath,
esmAliases,
esmExternals,
experimental
esmExternals
);

if (!ok(canisterJavaScriptResult)) {
if (process.env.AZLE_VERBOSE === 'true') {
console.error(canisterJavaScriptResult.err!.error);
console.error(canisterJavaScriptResult.err!.suggestion);
console.error(canisterJavaScriptResult.err!.exitCode);
}

throw new Error(`TypeScript compilation failed`);
}

const reloadedJs = Buffer.from(canisterJavaScriptResult.ok);
const reloadedJs = Buffer.from(javaScript);

const chunkSize = 2_000_000; // The current message limit is about 2 MiB
const timestamp = process.hrtime.bigint();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { spawn } from 'child_process';
import { join } from 'path';

import { execSyncPretty } from '../utils/exec_sync_pretty';
import { AZLE_PACKAGE_PATH } from '../utils/global_paths';
import { execSyncPretty } from '../../../../stable/utils/exec_sync_pretty';
import { AZLE_PACKAGE_PATH } from '../../../../stable/utils/global_paths';

export function setupFileWatcher(
reloadedJsPath: string,
Expand All @@ -12,8 +12,7 @@ export function setupFileWatcher(
esmAliases: Record<string, string>,
esmExternals: string[],
canisterName: string,
postUpgradeIndex: number,
experimental: boolean
postUpgradeIndex: number
): void {
try {
// TODO should we check that this was successful in killing
Expand All @@ -36,7 +35,10 @@ export function setupFileWatcher(
join(
AZLE_PACKAGE_PATH,
'src',
'compiler',
'build',
'experimental',
'commands',
'compile',
'file_watcher',
'file_watcher_loader.js'
),
Expand All @@ -47,8 +49,7 @@ export function setupFileWatcher(
JSON.stringify(esmAliases),
JSON.stringify(esmExternals),
canisterName,
postUpgradeIndex.toString(),
experimental.toString()
postUpgradeIndex.toString()
],
{
detached: true,
Expand Down
55 changes: 55 additions & 0 deletions src/build/experimental/commands/compile/get_context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { readFile } from 'fs/promises';
import { join } from 'path';

import { getCanisterId } from '../../../../../dfx';
import { version } from '../../../../../package.json';
import { getContext as getStableContext } from '../../../stable/commands/compile/get_context';
import {
AZLE_PACKAGE_PATH,
GLOBAL_AZLE_CONFIG_DIR
} from '../../../stable/utils/global_paths';
import { CanisterConfig } from '../../../stable/utils/types';
import { Context, WasmData } from '../../utils/types';
import { getConsumer } from './open_value_sharing/consumer';

export async function getContext(
canisterName: string,
canisterConfig: CanisterConfig
): Promise<Context> {
const stableContext = getStableContext(canisterName, canisterConfig);

const canisterId = getCanisterId(canisterName);

const esmAliases = canisterConfig.custom?.esm_aliases ?? {};
const esmExternals = canisterConfig.custom?.esm_externals ?? [];

const reloadedJsPath = join('.azle', canisterName, 'main_reloaded.js');

const consumer = await getConsumer(canisterConfig);
const managementDid = (
await readFile(
join(AZLE_PACKAGE_PATH, 'canisters', 'management', 'ic.did')
)
).toString();
const wasmData: WasmData = {
...stableContext.wasmData,
consumer,
managementDid
};

const wasmedgeQuickJsName = `wasmedge-quickjs_${version}`;
const wasmedgeQuickJsPath = join(
GLOBAL_AZLE_CONFIG_DIR,
wasmedgeQuickJsName
);

return {
...stableContext,
canisterId,
esmAliases,
esmExternals,
reloadedJsPath,
wasmData,
wasmedgeQuickJsPath
};
}
Loading
Loading