Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Compiler.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[gd_scene load_steps=2 format=2]

[ext_resource path="res://ArcadiaGodot/ArcadiaHook.cs" type="Script" id=1]

[node name="Compiler" type="Node"]
script = ExtResource( 1 )
ready_fn = "#'arcadia.internal.compiler/ready"
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ For quick access try `telnet localhost 5571`.

After building your project you'll need to manually compile your clojure namespaces into the build directory:

#### Godot Headless compilation

The easiest way to compile your Clojure files is to use the `Compiler.tscn`
scene, either through the command-line or through the Godot editor. This will
look at the `:source-paths` and `:target-path` keywords in your
`configuration.edn` file. These default to `["src"]` and `"target"`
respectively.

```bash
godot3 -d ArcadiaGodot/Compiler.tscn
```

#### Manual compilation

```
(require 'arcadia.internal.compiler)
(arcadia.internal.compiler/aot "export/dlls" ['selfsame.core])
Expand Down
58 changes: 47 additions & 11 deletions Source/arcadia/internal/compiler.clj
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
(ns arcadia.internal.compiler
(:use
arcadia.core)
arcadia.core)
(:require
clojure.string
[arcadia.internal.config :as config])
[clojure.string :as string]
[arcadia.internal.config :as config]
[clojure.edn :as edn])
(:import
[Arcadia.Boot]))
[Arcadia.Boot]))

(defn- aot-namespaces [path nss]
;; We want to ensure that namespaces are neither double-aot'd, nor
Expand All @@ -30,14 +31,49 @@
(alter @#'clojure.core/*loaded-libs* into @loaded-libs'))
nil))

(defn aot [path ns-syms]
(defn aot
"aot ns-syms to the given path, with all dependencies"
[path ns-syms]
(Arcadia.Boot/SetClojureLoadPath)
(Arcadia.Boot/AddSourcePaths)
(aot-namespaces path (concat ns-syms [
'clojure.core
'clojure.core.server
'arcadia.internal.namespace
'arcadia.repl]))
(aot-namespaces path (concat ns-syms ['clojure.core
'clojure.core.server
'arcadia.internal.namespace
'arcadia.repl]))
(Arcadia.Boot/SetClojureLoadPathWithDLLs)
(Arcadia.Boot/AddSourcePaths))
(Arcadia.Boot/AddSourcePaths))

(defn- copy-infrastructure! [dlls-dir]
(doseq [file (System.IO.Directory/GetFiles "ArcadiaGodot/Infrastructure")
:when (string/ends-with? file "dll")]
(let [file-name (last (string/split file #"/"))]
(System.IO.File/Copy file (System.IO.Path/Combine dlls-dir file-name) true))))

(defn- compile-project! [target namespaces]
(let [dlls-dir (System.IO.Path/Combine target "dlls")]
(System.IO.Directory/CreateDirectory dlls-dir)
(copy-infrastructure! dlls-dir)
(aot dlls-dir namespaces)))

(defn- file-namespace [file]
(-> file (slurp :enc "utf-8") edn/read-string second symbol))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function assumes that the first statement of the file is (ns <namespace> ,,,). Maybe there's a more reliable way to find a file's namespace?


(defn- clojure-namespaces [source-paths]
(for [src source-paths
file (System.IO.Directory/GetFiles src "*.clj", SearchOption/AllDirectories)
:when (not (string/includes? file "ArcadiaGodot"))]
(file-namespace file)))

(defn- compile-from-configuration []
(let [source-paths (get config/config :source-paths [])
target-path (get config/config :target-path [])]
(compile-project! target-path (clojure-namespaces source-paths))))

(defn ready [_ _]
(try
(compile-from-configuration)
(.Quit (arcadia.core/tree) 0)
(catch Exception e
(println "ERROR: Compilation failure!")
(println e)
(.Quit (arcadia.core/tree) 1))))
3 changes: 3 additions & 0 deletions configuration.edn
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@
;; Source paths for Clojure files to include
:source-paths ["src"]

;; Target path for compiling clojure to dlls
:target-path "target"

;; enables filewatcher to reload .clj files when changed
:reload-on-change true}