diff --git a/CHANGELOG.md b/CHANGELOG.md index e71854b2..03c8cb2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ All notable changes to this project will be documented in this file. ## Unreleased +- Add the `quickbin` command to jpm. - Create shell.c when making the amlagamated source. This can be compiled with janet.c to make the janet interpreter. - Add `cli-main` function to the core, which invokes Janet's CLI interface. diff --git a/Makefile b/Makefile index 10a5eb78..744d5f55 100644 --- a/Makefile +++ b/Makefile @@ -346,6 +346,8 @@ test-install: && jpm --verbose build \ && jpm --verbose test \ && build/testexec \ + && jpm --verbose quickbin testexec.janet build/testexec2 \ + && build/testexec2 \ && jpm --verbose --modpath=. install https://github.com/janet-lang/json.git build/embed_janet.o: build/janet.c $(JANET_HEADERS) diff --git a/auxbin/jpm b/auxbin/jpm index 04ce2414..c6caa058 100755 --- a/auxbin/jpm +++ b/auxbin/jpm @@ -464,17 +464,17 @@ int main(int argc, const char **argv) { } /* Create enviornment */ - JanetTable *runtimeEnv = janet_table(0); - runtimeEnv->proto = env; - janet_table_put(runtimeEnv, janet_ckeywordv("args"), janet_wrap_array(args)); - janet_gcroot(janet_wrap_table(runtimeEnv)); + temptab = janet_table(0); + temptab = env; + janet_table_put(temptab, janet_ckeywordv("args"), janet_wrap_array(args)); + janet_gcroot(janet_wrap_table(temptab)); /* Unlock GC */ janet_gcunlock(handle); /* Run everything */ JanetFiber *fiber = janet_fiber(janet_unwrap_function(marsh_out), 64, argc, args->data); - fiber->env = runtimeEnv; + fiber->env = temptab; Janet out; JanetSignal result = janet_continue(fiber, janet_wrap_nil(), &out); if (result) { @@ -843,6 +843,7 @@ Subcommands are: or (rule "ouput.file" [deps...] ...). rules : list rules available with run. update-pkgs : Update the current package listing from the remote git repository selected. + quickbin entry executable : Create an executable from a janet script with a main function. Keys are: --modpath : The directory to install modules to. Defaults to $JANET_MODPATH, $JANET_PATH, or (dyn :syspath) @@ -900,6 +901,11 @@ Flags are: [] (install-git (dyn :pkglist default-pkglist))) +(defn- quickbin + [input output] + (create-executable @{} input output) + (do-rule output)) + (def- subcommands {"build" build "clean" clean @@ -912,7 +918,8 @@ Flags are: "run" local-rule "rules" list-rules "update-pkgs" update-pkgs - "uninstall" uninstall-cmd}) + "uninstall" uninstall-cmd + "quickbin" quickbin}) (def- args (tuple/slice (dyn :args) 1)) (def- len (length args)) diff --git a/build_win.bat b/build_win.bat index d4164702..b5206adf 100644 --- a/build_win.bat +++ b/build_win.bat @@ -179,6 +179,10 @@ call jpm --verbose --modpath=. install https://github.com/janet-lang/json.git @if errorlevel 1 goto :TESTFAIL call build\testexec @if errorlevel 1 goto :TESTFAIL +call jpm --verbose quickbin testexec.janet build\testexec2 +@if errorlevel 1 goto :TESTFAIL +call build\testexec2 +@if errorlevel 1 goto :TESTFAIL popd exit /b 0 diff --git a/jpm.1 b/jpm.1 index 2cb13e66..68c116b0 100644 --- a/jpm.1 +++ b/jpm.1 @@ -138,6 +138,13 @@ List all rules that can be run via run. This is useful for exploring rules in th .BR update-pkgs Update the package listing by installing the 'pkgs' package. Same as jpm install pkgs +.TP +.BR quickbin [\fBentry\fR] [\fBexecutable\fR] +Create a standalone, statically linked executable from a Janet source file that contains a main function. +The main function is the entry point of the program and will receive command line arguments +as function arguments. The entry file can import other modules, including native C modules, and +jpm will attempt to include the dependencies into the generated executable. + .SH ENVIRONMENT .B JANET_PATH