Skip to content

Commit 3f533b3

Browse files
committed
add .ejs files for ejs-llvm and node-compat. add makefile stuff to create a tarball for osx
1 parent 94111b9 commit 3f533b3

File tree

10 files changed

+130
-70
lines changed

10 files changed

+130
-70
lines changed

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,7 @@ ejs-es6.js.exe.stage3: ejs-es6.js.exe.stage2
5151
echo-command-line:
5252
@echo ./ejs.exe --leave-temp $(MODULE_DIRS) ejs-es6.js
5353

54+
osx-tarball:
55+
$(MAKE) -C release osx-tarball
56+
5457
include $(TOP)/build/build.mk

build/config.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ $(TOP)/build/host-config.mk:
1313
HOST_OS:=$(patsubst darwin%,darwin,$(HOST_OS))
1414

1515
PRODUCT_NAME=EchoJS
16-
PRODUCT_VERSION=0.1
16+
PRODUCT_VERSION=0.0.1-alpha1
1717

1818
PRODUCT_RELEASE_NOTES_URL=http://toshokelectric.com/echojs/release_notes
1919
PRODUCT_GITHUB_URL=https://github.com/toshok/echo-js

ejs-es6.js

+59-53
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ import { dumpModules, getAllModules, gatherAllModules } from './lib/passes/gathe
1616

1717
import { bold, reset, genFreshFileName } from './lib/echo-util';
1818

19-
// if we're running under coffee/node, argv will be ["coffee", ".../ejs", ...]
20-
// if we're running the compiled ejs.exe, argv will be [".../ejs.js.exe", ...]
21-
let slice_count = typeof(__ejs) === "undefined" ? 2 : 1;
22-
let argv = process.argv.slice(slice_count);
19+
// argv is [".../ejs", ...], so get rid of the ejs
20+
let argv = process.argv.slice(1);
2321

2422
let temp_files = [];
2523

24+
let running_from_source_dir = path.basename(ejs_exe_dirname()) !== "bin";
25+
2626
let host_arch = os.arch();
2727
if (host_arch === "x64")
2828
host_arch = "x86-64"; // why didn't we just standardize on 'amd64'? sigh
@@ -316,27 +316,37 @@ function target_libraries(platform, arch) {
316316

317317

318318
function target_libecho(platform, arch) {
319-
if (platform === "darwin") {
320-
if (arch === "x86-64") return "runtime/libecho.a";
319+
if (running_from_source_dir) {
320+
if (platform === "darwin") {
321+
if (arch === "x86-64") return "runtime/libecho.a";
321322

322-
return "runtime/libecho.a.ios";
323-
}
323+
return "runtime/libecho.a.ios";
324+
}
324325

325-
return "runtime/libecho.a";
326+
return "runtime/libecho.a";
327+
}
328+
else {
329+
return path.join(relative_to_ejs_exe(`../lib/${platform}-${arch}`), 'libecho.a');
330+
}
326331
}
327332

328333

329334
function target_extra_libs(platform, arch) {
330-
if (platform === "linux") return "external-deps/pcre-linux/.libs/libpcre16.a";
335+
if (running_from_source_dir) {
336+
if (platform === "linux") return "external-deps/pcre-linux/.libs/libpcre16.a";
337+
338+
if (platform === "darwin") {
339+
if (arch === "x86-64") return "external-deps/pcre-osx/.libs/libpcre16.a";
340+
if (arch === "x86") return "external-deps/pcre-iossim/.libs/libpcre16.a";
341+
if (arch === "arm") return "external-deps/pcre-iosdev/.libs/libpcre16.a";
342+
if (arch === "aarch64") return "external-deps/pcre-iosdevaarch64/.libs/libpcre16.a";
343+
}
331344

332-
if (platform === "darwin") {
333-
if (arch === "x86-64") return "external-deps/pcre-osx/.libs/libpcre16.a";
334-
if (arch === "x86") return "external-deps/pcre-iossim/.libs/libpcre16.a";
335-
if (arch === "arm") return "external-deps/pcre-iosdev/.libs/libpcre16.a";
336-
if (arch === "aarch64") return "external-deps/pcre-iosdevaarch64/.libs/libpcre16.a";
345+
throw new Error("no pcre for this platform");
346+
}
347+
else {
348+
return path.join(relative_to_ejs_exe(`../lib/${platform}-${arch}`), 'libpcre16.a');
337349
}
338-
339-
throw new Error("no pcre for this platform");
340350
}
341351

342352
function target_path_prepend (platform, arch) {
@@ -360,19 +370,22 @@ function compileFile(filename, parse_tree, modules) {
360370
}
361371

362372
let compiled_module;
363-
// try {
373+
try {
364374
compiled_module = compile(parse_tree, base_filename, filename, modules, options);
365-
// }
366-
// catch (e) {
367-
// console.warn(`${e}`);
368-
// if (options.debug_level == 0) process.exit(-1);
369-
// throw e;
370-
// }
371-
372-
let ll_filename = `${os.tmpdir()}/${base_filename}-${options.target_platform}-${options.target_arch}.ll`;
373-
let bc_filename = `${os.tmpdir()}/${base_filename}-${options.target_platform}-${options.target_arch}.bc`;
374-
let ll_opt_filename = `${os.tmpdir()}/${base_filename}-${options.target_platform}-${options.target_arch}.ll.opt`;
375-
let o_filename = `${os.tmpdir()}/${base_filename}-${options.target_platform}-${options.target_arch}.o`;
375+
}
376+
catch (e) {
377+
console.warn(`${e}`);
378+
if (options.debug_level == 0) process.exit(-1);
379+
throw e;
380+
}
381+
382+
function tmpfile(suffix) {
383+
return `${os.tmpdir()}/${base_filename}-${options.target_arch}-${options.target_platform}.${suffix}`;
384+
}
385+
let ll_filename = tmpfile(".ll");
386+
let bc_filename = tmpfile(".bc");
387+
let ll_opt_filename = tmpfile(".ll.opt");
388+
let o_filename = tmpfile(".o");
376389

377390
temp_files.push(ll_filename, bc_filename, ll_opt_filename, o_filename);
378391

@@ -393,8 +406,12 @@ function compileFile(filename, parse_tree, modules) {
393406
o_filenames.push(o_filename);
394407
}
395408

409+
function ejs_exe_dirname() {
410+
return path.dirname(path.resolve(process.argv[0]));
411+
}
412+
396413
function relative_to_ejs_exe(n) {
397-
return path.resolve(path.dirname(process.argv[typeof(__ejs) === 'undefined' ? 1 : 0]), n);
414+
return path.resolve(ejs_exe_dirname(), n);
398415
}
399416

400417

@@ -407,7 +424,7 @@ function generate_import_map (js_modules, native_modules) {
407424
};
408425
let map_path = `${os.tmpdir()}/${genFreshFileName(path.basename(main_file))}-import-map.cpp`;
409426
let map = fs.createWriteStream(map_path);
410-
map.write (`#include "${relative_to_ejs_exe('runtime/ejs-module.h')}"\n`);
427+
map.write (`#include "runtime/ejs-module.h"\n`);
411428
map.write ('extern "C" {\n');
412429

413430
js_modules.forEach( (module) => {
@@ -471,9 +488,8 @@ function do_final_link(main_file, modules) {
471488
let clang_args = target_link_args(options.target_platform, options.target_arch).concat([`-DEJS_BITS_PER_WORD=${options.target_pointer_size}`, "-o", output_filename].concat(o_filenames));
472489
if (arch_info[options.target_arch].little_endian)
473490
clang_args.unshift("-DIS_LITTLE_ENDIAN=1");
474-
475-
// XXX we shouldn't need this, but build is failing while compiling the require map
476-
clang_args.push("-I.");
491+
492+
clang_args.push(`-I${relative_to_ejs_exe(running_from_source_dir ? '.' : '../include')}`);
477493

478494
clang_args.push(map_filename);
479495

@@ -487,11 +503,12 @@ function do_final_link(main_file, modules) {
487503
if (seen_native_modules.has(mf)) return;
488504

489505
seen_native_modules.add(mf);
490-
491-
clang_args.push(mf);
506+
507+
clang_args.push(path.resolve(module.ejs_dir,
508+
running_from_source_dir ? '.' : `${options.target_platform}-${options.target_arch}`,
509+
mf));
492510
});
493511

494-
// very strange, not sure why we need this \n
495512
clang_args = clang_args.concat(module.link_flags.replace('\n', ' ').split(" "));
496513
});
497514

@@ -501,22 +518,9 @@ function do_final_link(main_file, modules) {
501518

502519
debug.log (1, `executing '${target_linker} ${clang_args.join(' ')}'`);
503520

504-
if (typeof(__ejs) != "undefined") {
505-
spawn(target_linker, clang_args);
506-
// we ignore leave_tmp_files here
507-
if (!options.quiet) console.warn(`${bold()}done.${reset()}`);
508-
}
509-
else {
510-
let clang = spawn(target_linker, clang_args);
511-
clang.stderr.on("data", (data) => { console.warn(`${data}`); });
512-
clang.on("exit", (code) => {
513-
if (!options.leave_temp_files) {
514-
cleanup ( () => {
515-
if (!options.quiet) console.warn(`${bold()}done.${reset()}`);
516-
});
517-
}
518-
});
519-
}
521+
spawn(target_linker, clang_args);
522+
// we ignore leave_tmp_files here
523+
if (!options.quiet) console.warn(`${bold()}done.${reset()}`);
520524
}
521525

522526
function cleanup(done) {
@@ -531,6 +535,8 @@ function cleanup(done) {
531535

532536
let main_file = file_args[0];
533537

538+
if (!running_from_source_dir)
539+
options.native_module_dirs.push(relative_to_ejs_exe("../lib"));
534540
let files = gatherAllModules(file_args, options);
535541
debug.log (1, () => dumpModules());
536542
let allModules = getAllModules();

ejs-llvm/ejs-llvm.ejs.in

+4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
{
2+
"ejs_version": "0.0.0-alpha1",
3+
24
"module_name": "llvm",
35
"init_function": "_ejs_llvm_init",
46
"link_flags": "@LLVM_LINK_FLAGS@",
57
"module_file": "libejsllvm-module.a",
68

9+
"module_version": "0.0.0-alpha1",
10+
711
"exports": [ "IRBuilder" ]
812
}

lib/module-info.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,13 @@ export class JSModuleInfo extends ModuleInfo {
6363
}
6464

6565
export class NativeModuleInfo extends ModuleInfo {
66-
constructor(name, init_function, link_flags, module_files) {
66+
constructor(name, init_function, link_flags, module_files, ejs_dir) {
6767
super(true);
6868
this.path = name;
6969
this.module_name = name;
7070
this.init_function = init_function;
7171
this.link_flags = link_flags.join(" ");
7272
this.module_files = module_files;
73+
this.ejs_dir = ejs_dir;
7374
}
7475
}

lib/passes/gather-imports.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,11 @@ function parseFile(filename, content) {
183183

184184
function registerNativeModuleInfo(ejs_dir, module_name, link_flags, module_files, module_info) {
185185
if (module_info.link_flags) link_flags = link_flags.concat(module_info.link_flags);
186-
if (module_info.module_file) module_files = module_files.concat(path.resolve(ejs_dir, module_info.module_file));
186+
if (module_info.module_file) module_files = module_files.concat(module_info.module_file);
187187

188188
if (module_info.init_function) {
189189
// this module can be imported
190-
let m = new NativeModuleInfo(module_name, module_info.init_function, link_flags, module_files);
190+
let m = new NativeModuleInfo(module_name, module_info.init_function, link_flags, module_files, ejs_dir);
191191
if (module_info.exports)
192192
module_info.exports.forEach( (v) => m.addExport(v));
193193

@@ -234,7 +234,7 @@ export function gatherAllModules(file_args, options) {
234234
let work_list = file_args.slice();
235235
let files = [];
236236

237-
gatherAllNativeModules(options.native_module_dirs.concat("/usr/local/lib/ejs")); // XXX
237+
gatherAllNativeModules(options.native_module_dirs);
238238

239239
// starting at the main file, gather all files we'll need
240240
while (work_list.length !== 0) {

node-compat/node-compat.ejs

+7-12
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
{
2+
"ejs_version": "0.0.0-alpha1",
3+
24
"module_name": "node-compat",
35
"submodules": [
4-
{ "module_name": "path", "init_function": "_ejs_path_module_func",
5-
"exports": [ "dirname", "basename", "extname", "resolve", "relative", "join" ]
6-
},
7-
{ "module_name": "os", "init_function": "_ejs_os_module_func",
8-
"exports": [ "arch", "platform", "tmpdir" ]
9-
},
10-
{ "module_name": "fs", "init_function": "_ejs_fs_module_func",
11-
"exports": [ "statSync", "readFileSync", "createWriteStream", "readdirSync" ]
12-
},
13-
{ "module_name": "child_process", "init_function": "_ejs_child_process_module_func",
14-
"exports": [ "spawn", "stdout", "stderr" ]
15-
}
6+
{ "module_name": "path", "init_function": "_ejs_path_module_func", "exports": [ "dirname", "basename", "extname", "resolve", "relative", "join" ] },
7+
{ "module_name": "os", "init_function": "_ejs_os_module_func", "exports": [ "arch", "platform", "tmpdir" ] },
8+
{ "module_name": "fs", "init_function": "_ejs_fs_module_func", "exports": [ "statSync", "readFileSync", "createWriteStream", "readdirSync" ] },
9+
{ "module_name": "child_process", "init_function": "_ejs_child_process_module_func", "exports": [ "spawn", "stdout", "stderr" ] }
1610
],
1711
"link_flags": "",
12+
"module_version": "0.0.0-alpha1",
1813
"module_file": "libejsnodecompat-module.a"
1914
}

release/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
release-readme.md
2+
echojs-*

release/Makefile

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
TOP=..
2+
3+
include $(TOP)/build/config.mk
4+
5+
TARBALL_DIR=$(PRODUCT_name)-$(PRODUCT_VERSION)
6+
libdir=$(TARBALL_DIR)/lib
7+
archlibdir=$(TARBALL_DIR)/lib/darwin-x86-64
8+
includedir=$(TARBALL_DIR)/include/runtime
9+
bindir=$(TARBALL_DIR)/bin
10+
sampledir=$(TARBALL_DIR)/samples
11+
12+
osx-tarball: osx-tarball-deps
13+
rm -f $(TARBALL_DIR).tar.bz2
14+
rm -rf $(TARBALL_DIR)
15+
mkdir -p $(bindir)
16+
mkdir -p $(archlibdir)
17+
mkdir -p $(includedir)
18+
mkdir -p $(sampledir)
19+
cp release-readme.md $(TARBALL_DIR)/README.md
20+
cp $(TOP)/ejs.exe $(bindir)/ejs
21+
cp $(TOP)/runtime/*.h $(includedir)
22+
cp $(TOP)/runtime/libecho.a $(archlibdir)
23+
cp $(TOP)/external-deps/pcre-osx/.libs/libpcre16.a $(archlibdir)
24+
cp $(TOP)/node-compat/node-compat.ejs $(libdir)
25+
cp $(TOP)/node-compat/libejsnodecompat-module.a $(archlibdir)
26+
cp $(TOP)/ejs-llvm/ejs-llvm.ejs $(libdir)
27+
cp $(TOP)/ejs-llvm/libejsllvm-module.a $(archlibdir)
28+
cp $(TOP)/test/fetch.js $(sampledir)
29+
tar -cvjf $(TARBALL_DIR).tar.gz $(TARBALL_DIR)
30+
31+
osx-tarball-deps: release-readme.md
32+
$(MAKE) -C .. all bootstrap
33+
34+
release-readme.md: release-readme.md.in
35+
@echo [gen] $< && sed -e "s,@PRODUCT_VERSION@,$(PRODUCT_VERSION)," $< > $@
36+
37+
include $(TOP)/build/build.mk

release/release-readme.md.in

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
EchoJS @PRODUCT_VERSION@
2+
------------------------
3+
4+
you need llvm34 installed.
5+
6+
$ brew install llvm34
7+
$ export LLVM_SUFFIX-3.4
8+
9+
as an example of XmlHTTPRequest + ES6 Promises:
10+
11+
$ bin/ejs samples/fetch.js
12+
$ samples/fetch.js.exe http://www.google.com/

0 commit comments

Comments
 (0)