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: Added Makefile for simpler build process #38

Merged
merged 5 commits into from
May 19, 2022
Merged
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
39 changes: 39 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

.ONESHELL: # Applies to every targets in the file!
QUIET := @

OS = $(shell uname -s)
ARCH = $(shell uname -m)

all: setup build yarn

setup:
cd jsvm && ./setup.sh && cd ..

build: jsvm qjsc

jsvm:
echo "Building jsvm.wasm..."
cd jsvm && ./build.sh && cd ..
cp jsvm/jsvm.wasm res/jsvm.wasm

qjsc:
echo "Building qjsc bytecode compiler"
cd quickjs && ./build.sh && cd ..
cp quickjs/qjsc res/$(OS)-$(ARCH)-qjsc

yarn:
$(QUIET)yarn

clean: clean-vendor clean-node

clean-vendor:
$(QUIET)rm -rf jsvm/vendor

clean-node:
$(QUIET)rm -rf node_modules


.PHONY: all setup build yarn
.PHONY: jsvm qjsc
.PHONY: clean clean-vendor clean-node
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This README is a work in porgress. The best way to start using `near-sdk-js` is
It is tested on Ubuntu 20.04 and Intel Mac. Other linux and M1 Macs should also work but they're not tested.

1. Make sure you have `wget`, `make`, `cmake` and `nodejs`. On Linux, also make sure you have `gcc`.
2. Run `./rebuild_recources.sh` to get platform specific `qjsc` and `jsvm` contract in `res` folder.
2. Run `make` to get platform specific `qjsc` and `jsvm` contract in `res` folder.

## Usage
1. `cd examples/<example>`
Expand Down Expand Up @@ -35,7 +35,7 @@ near call <jsvm-account> remove_js_contract --accountId <your-account>

1. Build the jsvm contract
```
./rebuild_recources.sh
make
```

2. Go to nearcore, Build and start a local node
Expand Down
35 changes: 22 additions & 13 deletions cli/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import { babel } from '@rollup/plugin-babel';

import { rollup } from 'rollup';

import { exec } from 'child_process';
import { exec as exec_ } from 'child_process';
import { promisify } from 'util';

const exec = promisify(exec_);

//TODO: build passed file instead of hardcoded one
yargs(hideBin(process.argv))
Expand Down Expand Up @@ -44,25 +47,31 @@ async function build(argv) {

console.log('Creating <>.base64 file with the use of QJSC...');
const SAVE_BYTECODE = './node_modules/near-sdk-js/cli/save_bytecode.js';
const QJSC = './node_modules/near-sdk-js/res/qjsc';
const os = await executeCommand('uname -s', true);
const arch = await executeCommand('uname -m', true);
const QJSC = `./node_modules/near-sdk-js/res/${os}-${arch}-qjsc`;
const TEMP = 'build/contract.h';
const TARGET = 'build/contract.base64';
const CONTRACT_JS_FILE = 'build/contract.js';
await executeCommand(`${QJSC} -c -m -o ${TEMP} -N code ${CONTRACT_JS_FILE}`);
await executeCommand(`node ${SAVE_BYTECODE} ${TEMP} ${TARGET}`);
}

async function executeCommand(command) {
async function executeCommand(command, silent=false) {
console.log(command);
exec(command, (error, stdout, stderr) => {
if (error) {
console.log(error);
process.exit(1);
}
if (stderr) {
console.log(stderr);
process.exit(1);
}
const {error, stdout, stderr} = await exec(command);

if (error) {
console.log(error);
process.exit(1);
}
if (stderr && !silent) {
console.error(stderr);
}

if (silent) {
return stdout.trim();
} else {
console.log(stdout);
});
}
}
10 changes: 0 additions & 10 deletions rebuild_resources.sh

This file was deleted.

Binary file added res/Darwin-arm64-qjsc
Binary file not shown.
File renamed without changes.
Binary file added res/Linux-x86_64-qjsc
Binary file not shown.
Binary file modified res/jsvm.wasm
Binary file not shown.
Loading