Skip to content

Commit

Permalink
Merge pull request #38 from near/feat/makefile
Browse files Browse the repository at this point in the history
feat: Added Makefile for the simpler build process
  • Loading branch information
volovyks authored May 19, 2022
2 parents 9a6172e + 787ff8f commit 366e33b
Show file tree
Hide file tree
Showing 9 changed files with 664 additions and 626 deletions.
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

0 comments on commit 366e33b

Please sign in to comment.