1
0
mirror of https://github.com/janet-lang/janet synced 2025-11-18 16:25:11 +00:00

Address #478 - Disable core in static binaries/

Add --no-core option to quickbin, as well as :no-core option
to declare executable. This doesn't use the autodetection when
making binaries, instead opting for manual intervention.
This commit is contained in:
Calvin Rose
2021-01-23 17:47:41 -06:00
parent f22472a644
commit 01a3d8f932

40
jpm
View File

@@ -602,7 +602,7 @@
(string (string/slice path 0 (- -1 (length modext))) statext)) (string (string/slice path 0 (- -1 (length modext))) statext))
(defn- make-bin-source (defn- make-bin-source
[declarations lookup-into-invocations] [declarations lookup-into-invocations no-core]
(string (string
declarations declarations
``` ```
@@ -627,15 +627,22 @@ int main(int argc, const char **argv) {
janet_init(); janet_init();
```
(if no-core
```
/* Get core env */
JanetTable *env = janet_table(8);
JanetTable *lookup = janet_core_lookup_table(NULL);
JanetTable *temptab;
int handle = janet_gclock();
```
```
/* Get core env */ /* Get core env */
JanetTable *env = janet_core_env(NULL); JanetTable *env = janet_core_env(NULL);
JanetTable *lookup = janet_env_lookup(env); JanetTable *lookup = janet_env_lookup(env);
JanetTable *temptab; JanetTable *temptab;
int handle = janet_gclock(); int handle = janet_gclock();
```)
/* Load natives into unmarshalling dictionary */
```
lookup-into-invocations lookup-into-invocations
``` ```
/* Unmarshal bytecode */ /* Unmarshal bytecode */
@@ -699,7 +706,7 @@ int main(int argc, const char **argv) {
"Links an image with libjanet.a (or .lib) to produce an "Links an image with libjanet.a (or .lib) to produce an
executable. Also will try to link native modules into the executable. Also will try to link native modules into the
final executable as well." final executable as well."
[opts source dest] [opts source dest no-core]
# Create executable's janet image # Create executable's janet image
(def cimage_dest (string dest ".c")) (def cimage_dest (string dest ".c"))
@@ -715,7 +722,16 @@ int main(int argc, const char **argv) {
(def dep-ldflags @[]) (def dep-ldflags @[])
# Create marshalling dictionary # Create marshalling dictionary
(def mdict (invert (env-lookup root-env))) (def mdict1 (invert (env-lookup root-env)))
(def mdict
(if no-core
(let [temp @{}]
(eachp [k v] mdict1
(if (or (cfunction? k) (abstract? k))
(put temp k v)))
temp)
mdict1))
# Load all native modules # Load all native modules
(def prefixes @{}) (def prefixes @{})
(def static-libs @[]) (def static-libs @[])
@@ -760,7 +776,7 @@ int main(int argc, const char **argv) {
# Make image byte buffer # Make image byte buffer
(create-buffer-c-impl image cimage_dest "janet_payload_image") (create-buffer-c-impl image cimage_dest "janet_payload_image")
# Append main function # Append main function
(spit cimage_dest (make-bin-source declarations lookup-into-invocations) :ab) (spit cimage_dest (make-bin-source declarations lookup-into-invocations no-core) :ab)
(def oimage_dest (out-path cimage_dest ".c" ".o")) (def oimage_dest (out-path cimage_dest ".c" ".o"))
# Compile and link final exectable # Compile and link final exectable
(unless no-compile (unless no-compile
@@ -1049,10 +1065,10 @@ int main(int argc, const char **argv) {
This executable can be installed as well to the --binpath given." This executable can be installed as well to the --binpath given."
[&keys {:install install :name name :entry entry :headers headers [&keys {:install install :name name :entry entry :headers headers
:cflags cflags :lflags lflags :deps deps :ldflags ldflags :cflags cflags :lflags lflags :deps deps :ldflags ldflags
:no-compile no-compile}] :no-compile no-compile :no-core no-core}]
(def name (if is-win (string name ".exe") name)) (def name (if is-win (string name ".exe") name))
(def dest (string "build" sep name)) (def dest (string "build" sep name))
(create-executable @{:cflags cflags :lflags lflags :ldflags ldflags :no-compile no-compile} entry dest) (create-executable @{:cflags cflags :lflags lflags :ldflags ldflags :no-compile no-compile} entry dest no-core)
(if no-compile (if no-compile
(let [cdest (string dest ".c")] (let [cdest (string dest ".c")]
(add-dep "build" cdest)) (add-dep "build" cdest))
@@ -1359,7 +1375,9 @@ Flags are:
(defn quickbin (defn quickbin
[input output] [input output]
(create-executable @{} input output) (if (= (os/stat output :mode) :file)
(print "output " output " exists."))
(create-executable @{:no-compile (dyn :no-compile)} input output (dyn :no-core))
(do-rule output)) (do-rule output))
(defn jpm-debug-repl (defn jpm-debug-repl