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

Implement improvements as suggested in the last report #360

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 7 additions & 3 deletions packages/near-sdk-js/builder/builder.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ static JSContext *JS_NewCustomContext(JSRuntime *rt)
return NULL;
JS_AddIntrinsicBaseObjects(ctx);
JS_AddIntrinsicDate(ctx);
JS_AddIntrinsicEval(ctx);
JS_AddIntrinsicStringNormalize(ctx);
JS_AddIntrinsicRegExp(ctx);
JS_AddIntrinsicJSON(ctx);
Expand All @@ -22,8 +21,15 @@ static JSContext *JS_NewCustomContext(JSRuntime *rt)
return ctx;
}

extern void _initialize(void);

#define DEFINE_NEAR_METHOD(name) \
void name () __attribute__((export_name(#name))) {\
static volatile int initialized = 0;\
if (initialized == 0) {\
_initialize();\
initialized = 1;\
}\
JSRuntime *rt;\
JSContext *ctx;\
JSValue mod_obj, fun_obj, result, error, error_message, error_stack;\
Expand Down Expand Up @@ -1186,6 +1192,4 @@ static void js_add_near_host_functions(JSContext* ctx) {
JSValue JS_Call(JSContext *ctx, JSValueConst func_obj, JSValueConst this_obj,
int argc, JSValueConst *argv);

void _start() {}

#include "methods.h"
10 changes: 2 additions & 8 deletions packages/near-sdk-js/lib/cli/cli.js

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

16 changes: 0 additions & 16 deletions packages/near-sdk-js/lib/cli/post-install.js

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

16 changes: 4 additions & 12 deletions packages/near-sdk-js/src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,6 @@ export async function transpileJsAndBuildWasmCom(
verbose
);

signale.await("Executing wasi-stub...");
await wasiStubContract(getContractTarget(target), verbose);

signale.success(
`Generated ${getContractTarget(target)} contract successfully!`
);
Expand Down Expand Up @@ -363,7 +360,7 @@ async function createWasmContract(
) {
const WASI_SDK_PATH = `${NEAR_SDK_JS}/lib/cli/deps/wasi-sdk`;

const CC = `${WASI_SDK_PATH}/bin/clang --sysroot=${WASI_SDK_PATH}/share/wasi-sysroot`;
const CC = `${WASI_SDK_PATH}/bin/clang`;
let DEFS = `-D_GNU_SOURCE '-DCONFIG_VERSION="2021-03-27"' -DCONFIG_BIGNUM`;

if (process.env.NEAR_NIGHTLY) {
Expand All @@ -382,14 +379,9 @@ async function createWasmContract(
fs.renameSync(qjscTarget, "build/code.h");

await executeCommand(
`${CC} --target=wasm32-wasi -nostartfiles -Oz -flto ${DEFS} ${INCLUDES} ${SOURCES} ${LIBS} -Wl,--no-entry -Wl,--allow-undefined -Wl,-z,stack-size=${
256 * 1024
} -Wl,--lto-O3 -o ${contractTarget}`,
`${CC} -mcpu=mvp -Oz -fno-strict-aliasing ${DEFS} ${INCLUDES} ${SOURCES} ${LIBS} -mexec-model=reactor -Wl,--allow-undefined -Wl,--stack-first,-z,stack-size=${
256 * 1024 * 2
} -Wl,--compress-relocations,--strip-debug -o ${contractTarget}`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

verbose
);
}

async function wasiStubContract(contractTarget: string, verbose = false) {
const WASI_STUB = `${NEAR_SDK_JS}/lib/cli/deps/binaryen/wasi-stub/run.sh`;
await executeCommand(`${WASI_STUB} ${contractTarget}`, verbose);
}
28 changes: 0 additions & 28 deletions packages/near-sdk-js/src/cli/post-install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,34 +31,6 @@ if (!SUPPORTED_ARCH.includes(ARCH)) {
process.exit(1);
}

signale.await("Installing wasi-stub...");

const BINARYEN_VERSION = `0.1.15`;
const BINARYEN_VERSION_TAG = `v${BINARYEN_VERSION}`;

const BINARYEN_SYSTEM_NAME =
PLATFORM === "linux"
? "Linux"
: PLATFORM === "darwin"
? "macOS"
: PLATFORM === "win32"
? "windows"
: "other";

const BINARYEN_ARCH_NAME =
ARCH === "x64" ? "X64" : ARCH === "arm64" ? "arm64" : "other";

const BINARYEN_TAR_NAME = `binaryen-${BINARYEN_SYSTEM_NAME}-${BINARYEN_ARCH_NAME}.tar.gz`;

await download(
`https://github.com/near/binaryen/releases/download/${BINARYEN_VERSION_TAG}/${BINARYEN_TAR_NAME}`
);

fs.mkdirSync("binaryen");

await executeCommand(`tar xvf ${BINARYEN_TAR_NAME} --directory binaryen`);
fs.rmSync(BINARYEN_TAR_NAME);

signale.await("Installing QuickJS...");

const QUICK_JS_VERSION = `0.1.3`;
Expand Down
Loading