|
|
@@ -12,10 +12,9 @@
|
|
|
// built using the `js_wasm32` target and put next to the index file.
|
|
|
package karl2d_build_web_example
|
|
|
|
|
|
-import "core:os"
|
|
|
import "core:fmt"
|
|
|
import "core:path/filepath"
|
|
|
-import "core:os/os2"
|
|
|
+import os "core:os/os2"
|
|
|
|
|
|
main :: proc() {
|
|
|
if len(os.args) != 2 {
|
|
|
@@ -28,46 +27,40 @@ main :: proc() {
|
|
|
|
|
|
dir := os.args[1]
|
|
|
dir_handle, dir_handle_err := os.open(dir)
|
|
|
-
|
|
|
fmt.ensuref(dir_handle_err == nil, "Failed finding directory %v. Error: %v", dir, dir_handle_err)
|
|
|
|
|
|
- dir_stat, dir_stat_err := os.fstat(dir_handle)
|
|
|
-
|
|
|
+ dir_stat, dir_stat_err := os.fstat(dir_handle, context.allocator)
|
|
|
fmt.ensuref(dir_stat_err == nil, "Failed checking status of directory %v. Error: %v", dir, dir_stat_err)
|
|
|
-
|
|
|
- fmt.ensuref(dir_stat.is_dir, "%v is not a directory!", dir)
|
|
|
+ fmt.ensuref(dir_stat.type == .Directory, "%v is not a directory!", dir)
|
|
|
|
|
|
web_dir := filepath.join({dir, "web"})
|
|
|
os.make_directory(web_dir, 0o644)
|
|
|
|
|
|
web_build_dir := filepath.join({web_dir, "build"})
|
|
|
-
|
|
|
os.make_directory(web_build_dir, 0o644)
|
|
|
|
|
|
- os.write_entire_file(
|
|
|
- filepath.join(
|
|
|
- {web_dir, fmt.tprintf("%v_web_entry.odin", filepath.stem(dir))},
|
|
|
- ),
|
|
|
- WEB_ENTRY_TEMPLATE,
|
|
|
- )
|
|
|
- os.write_entire_file(filepath.join({web_build_dir, "index.html"}), WEB_ENTRY_INDEX)
|
|
|
+ entry_odin_file_path := filepath.join({web_dir, fmt.tprintf("%v_web_entry.odin", filepath.stem(dir))})
|
|
|
+ write_entry_odin_err := os.write_entire_file(entry_odin_file_path, WEB_ENTRY_TEMPLATE)
|
|
|
+ fmt.ensuref(write_entry_odin_err == nil, "Failed writing %v. Error: %v", entry_odin_file_path, write_entry_odin_err)
|
|
|
|
|
|
- _, odin_root_stdout, _, odin_root_err := os2.process_exec({
|
|
|
+ entry_html_file_path := filepath.join({web_build_dir, "index.html"})
|
|
|
+ write_entry_html_err := os.write_entire_file(entry_html_file_path, WEB_ENTRY_INDEX)
|
|
|
+ fmt.ensuref(write_entry_html_err == nil, "Failed writing %v. Error: %v", entry_html_file_path, write_entry_html_err)
|
|
|
+
|
|
|
+ _, odin_root_stdout, _, odin_root_err := os.process_exec({
|
|
|
command = { "odin", "root" },
|
|
|
}, allocator = context.allocator)
|
|
|
|
|
|
ensure(odin_root_err == nil, "Failed fetching 'odin root' (Odin in PATH needed!)")
|
|
|
-
|
|
|
odin_root := string(odin_root_stdout)
|
|
|
|
|
|
js_runtime_path := filepath.join({odin_root, "core", "sys", "wasm", "js", "odin.js"})
|
|
|
- fmt.ensuref(os2.exists(js_runtime_path), "File does not exist: %v -- It is the Odin Javascript runtime that this program needs to copy to the web build output folder!", js_runtime_path)
|
|
|
-
|
|
|
- os2.copy_file(filepath.join({web_build_dir, "odin.js"}), js_runtime_path)
|
|
|
+ fmt.ensuref(os.exists(js_runtime_path), "File does not exist: %v -- It is the Odin Javascript runtime that this program needs to copy to the web build output folder!", js_runtime_path)
|
|
|
+ os.copy_file(filepath.join({web_build_dir, "odin.js"}), js_runtime_path)
|
|
|
|
|
|
wasm_out_path := filepath.join({web_build_dir, "main.wasm"})
|
|
|
|
|
|
- _, build_std_out, build_std_err, _ := os2.process_exec({
|
|
|
+ _, build_std_out, build_std_err, _ := os.process_exec({
|
|
|
command = {
|
|
|
"odin",
|
|
|
"build",
|