Skip to content

Commit

Permalink
Split bundle hooks into separate files.
Browse files Browse the repository at this point in the history
Allow `janet bundle/build.janet`, `janet bundle/clean.janet`, etc.
to run things.
  • Loading branch information
bakpakin committed Oct 5, 2024
1 parent 04be599 commit d30a461
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 67 deletions.
53 changes: 53 additions & 0 deletions bundle/build.janet
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
(import "/spork/cc" :as cc)

(defn main
[& argv]
(os/mkdir "build")
(os/mkdir "build/objects")

(def suffix
(case (os/which)
:windows ".dll"
".so"))

(def asuffix
(case (os/which)
:windows ".lib"
".a"))

(def cc
(case (os/which)
:windows cc/msvc-compile-and-link-shared
cc/compile-and-link-shared))

(def static-cc
(case (os/which)
:windows cc/msvc-compile-and-make-archive
cc/compile-and-make-archive))

(when (= :windows (os/which))
(cc/msvc-find)
(assert (cc/msvc-setup?))
(setdyn cc/*msvc-libs* @[(cc/msvc-janet-import-lib)]))

(defn make1
[name & other-srcs]
(def from (string "src/" name ".c"))
(def to (string "build/" name suffix))
(def toa (string "build/" name asuffix))
(cc to from ;other-srcs)
(static-cc toa from ;other-srcs))

(setdyn cc/*visit* cc/visit-execute-if-stale)
(setdyn cc/*build-dir* "build/objects")
(make1 "crc")
(make1 "json")
(make1 "cmath")
(make1 "utf8")
(make1 "rawterm")
(make1 "tarray")
(make1 "base64")
(setdyn cc/*defines* {"_LARGEFILE64_SOURCE" true})
(make1 "zip" "deps/miniz/miniz.c")

(print "done!"))
5 changes: 5 additions & 0 deletions bundle/clean.janet
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(import "/spork/sh" :as sh)

(defn main
[&]
(sh/rm "build"))
79 changes: 12 additions & 67 deletions bundle/init.janet
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
(import "/spork/cc" :as cc)
(import "/spork/sh" :as sh)
(import ./test)
(import ./build :as b)
(import ./clean :as c)

(defn clean [&]
(c/main))

(defn check [&]
(test/main))

(defn build [&]
(b/main))

(defn install [m &]
(bundle/add-file m "src/tarray.h" "tarray.h")
Expand All @@ -11,68 +21,3 @@
(def f (string "build/" file))
(when (= (os/stat f :mode) :file)
(bundle/add-file m f (string "spork/" file)))))

(defn clean [&]
(sh/rm "build"))

(defn test [&]
(var failure-count 0)
(each suite (sorted (os/dir "test"))
(when (string/has-prefix? "suite-" suite)
(eprint "Running suite " suite)
(def result (os/execute [(dyn *executable*) (string "test/" suite)] :p))
(if-not (zero? result) (++ failure-count))))
(if (zero? failure-count)
(eprint "All Passed.")
(do (eprintf "Failures: %v" failure-count) (os/exit 1))))

(defn build [&]
(os/mkdir "build")
(os/mkdir "build/objects")

(def suffix
(case (os/which)
:windows ".dll"
".so"))

(def asuffix
(case (os/which)
:windows ".lib"
".a"))

(def cc
(case (os/which)
:windows cc/msvc-compile-and-link-shared
cc/compile-and-link-shared))

(def static-cc
(case (os/which)
:windows cc/msvc-compile-and-make-archive
cc/compile-and-make-archive))

(when (= :windows (os/which))
(cc/msvc-find)
(assert (cc/msvc-setup?))
(setdyn cc/*msvc-libs* @[(cc/msvc-janet-import-lib)]))

(defn make1
[name & other-srcs]
(def from (string "src/" name ".c"))
(def to (string "build/" name suffix))
(def toa (string "build/" name asuffix))
(cc to from ;other-srcs)
(static-cc toa from ;other-srcs))

(setdyn cc/*visit* cc/visit-execute-if-stale)
(setdyn cc/*build-dir* "build/objects")
(make1 "crc")
(make1 "json")
(make1 "cmath")
(make1 "utf8")
(make1 "rawterm")
(make1 "tarray")
(make1 "base64")
(setdyn cc/*defines* {"_LARGEFILE64_SOURCE" true})
(make1 "zip" "deps/miniz/miniz.c")

(print "done!"))
16 changes: 16 additions & 0 deletions bundle/test.janet
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#
# Run test scripts, and error if any fail.
# Pass through any args
#

(defn main [& argv]
(def failures-array @[])
(each suite (sorted (os/dir "test"))
(when (string/has-prefix? "suite-" suite)
(eprint "Running suite " suite)
(def result (os/execute [(dyn *executable*) (string "test/" suite) ;argv] :p))
(if-not (zero? result)
(array/push failures-array suite))))
(if (empty? failures-array)
(eprint "All Passed.")
(errorf "Failures in: %s" (string/join failures-array ", "))))

0 comments on commit d30a461

Please sign in to comment.