Skip to content

Commit

Permalink
Integrate build-rules with cc.janet
Browse files Browse the repository at this point in the history
  • Loading branch information
bakpakin committed Dec 23, 2024
1 parent 3348318 commit ec27112
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 3 additions & 2 deletions spork/build-rules.janet
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,9 @@
(cond
(keyword? target) [(string target)]
(string? target) [target]
(indexed? target) target))
(def target (first target))
(indexed? target) target
(errorf "bad target %v" target)))
(def target (first all-targets))
(each d [;deps ;all-targets]
(assert (string? d) "inputs and outputs must be strings"))
(unless (get rules target)
Expand Down
12 changes: 11 additions & 1 deletion spork/cc.janet
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

(import ./path)
(import ./sh)
(import ./build-rules)

(defdyn *ar* "Archiver, defaults to `ar`.")
(defdyn *build-dir* "If generating intermediate files, store them in this directory")
Expand Down Expand Up @@ -51,6 +52,7 @@
Some linkers support this by default, but not at all. Defaults to true on linux and macos.``)
(defdyn *c-std* "C standard to use as a 2 digit number, defaults to 99 on GCC-like compilers, 11 on msvc.")
(defdyn *c++-std* "C++ standard to use as a 2 digit number, defaults to 11 on GCC-like compilers, 14 on msvc.")
(defdyn *rules* "Rules to use with visit-add-rule")

###
### Universal helpers for all toolchains
Expand Down Expand Up @@ -202,7 +204,7 @@
(defn compile-c++
"Compile a C++ program to an object file. Return the command arguments."
[from to]
(exec [(c++) (c++std) ;(opt) ;(cflags) ;(extra-paths) "-fPIC" ;(defines) "-c" from "-o" to "-pthread"]
(exec [(c++) (c++std) ;(opt) ;(c++flags) ;(extra-paths) "-fPIC" ;(defines) "-c" from "-o" to "-pthread"]
[from] [to] (string "compiling " from "...")))

(defn link-shared-c
Expand Down Expand Up @@ -539,6 +541,14 @@
(with [devnull (sh/devnull)]
(os/execute cmd :px {:out devnull :err devnull})))

(defn visit-add-rule
"Used in conjuction with spork/build-rules. Adds rules to the (dyn *rules* (curenv))"
[cmd inputs outputs message]
(def rules (dyn *rules* (curenv)))
(build-rules/build-rule
rules outputs inputs
(visit-execute cmd inputs outputs message)))

###
### Library discovery and self check
###
Expand Down

0 comments on commit ec27112

Please sign in to comment.