Skip to content

Commit

Permalink
Add auto detection code for C toolchain.
Browse files Browse the repository at this point in the history
Allows using non-msvc on windows via overrides.
  • Loading branch information
bakpakin committed Oct 19, 2024
1 parent ca774c4 commit 1bed0c9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@ _debug
/tmp
temp.html
temp.mdz
*.a
*.o
*.lib
*.obj

jpm_tree
34 changes: 19 additions & 15 deletions bundle/build.janet
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,41 @@
[& argv]
(os/mkdir "build")
(os/mkdir "build/objects")
(os/mkdir "build/spork")

(def suffix
(case (os/which)
:windows ".dll"
".so"))
# How should we do toolchain detection?
(def toolchain
(cond
(os/getenv "MSVC") :msvc
(os/getenv "GCC") :gcc
(os/getenv "CLANG") :clang
(os/getenv "CC") :cc # any posix compatible compiler accessed via `cc`
(= :windows (os/which)) :msvc
:cc))

(def asuffix
(case (os/which)
:windows ".lib"
".a"))
(def suffix (case toolchain :msvc ".dll" ".so"))
(def asuffix (case toolchain :msvc ".lib" ".a"))

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

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

(when (= :windows (os/which))
(when (= :msvc toolchain)
(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))
(def to (string "build/spork/" name suffix))
(def toa (string "build/spork/" name asuffix))
(cc to from ;other-srcs)
(static-cc toa from ;other-srcs))

Expand Down
4 changes: 2 additions & 2 deletions bundle/init.janet
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
(compwhen (dyn 'bundle/add-bin)
(bundle/add-bin m "bin/janet-format")
(bundle/add-bin m "bin/janet-netrepl"))
(each file (os/dir "build")
(def f (string "build/" file))
(each file (os/dir "build/spork")
(def f (string "build/spork/" file))
(when (= (os/stat f :mode) :file)
(bundle/add-file m f (string "spork/" file)))))
3 changes: 2 additions & 1 deletion bundle/test.janet
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@

(defn main [& argv]
(def failures-array @[])
(def build-path (os/realpath "build"))
(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))
(def result (os/execute [(dyn *executable*) "-m" build-path (string "test/" suite) ;argv] :p))
(if-not (zero? result)
(array/push failures-array suite))))
(if (empty? failures-array)
Expand Down

0 comments on commit 1bed0c9

Please sign in to comment.