|
@@ -1,11 +1,12 @@
|
|
|
-// This program builds the examples in a "web" version. You can use it as a basis for your own
|
|
|
|
|
-// Karl2D web build script.
|
|
|
|
|
|
|
+// This program builds a Karl2D game as a web version.
|
|
|
//
|
|
//
|
|
|
// Usage:
|
|
// Usage:
|
|
|
-// odin run build_web_example -- example_directory_name
|
|
|
|
|
|
|
+// odin run build_web -- directory_name
|
|
|
//
|
|
//
|
|
|
-// Replace `example_directory_name` with the example you wish to build a web version of. The
|
|
|
|
|
-// resulting web application will be in `example_directory_name/web/build`.
|
|
|
|
|
|
|
+// For example:
|
|
|
|
|
+// odin run build_web -- examples/minimal_web
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
//
|
|
//
|
|
|
// This program copies the `odin.js` from `<odin>/core/wasm/js/odin.js` to the build folder. It also
|
|
// This program copies the `odin.js` from `<odin>/core/wasm/js/odin.js` to the build folder. It also
|
|
|
// copies an `index.html` file there than is used to host your web program. The example itself is
|
|
// copies an `index.html` file there than is used to host your web program. The example itself is
|
|
@@ -18,7 +19,7 @@ import os "core:os/os2"
|
|
|
|
|
|
|
|
main :: proc() {
|
|
main :: proc() {
|
|
|
if len(os.args) != 2 {
|
|
if len(os.args) != 2 {
|
|
|
- fmt.eprintfln("Usage: 'odin run build_web_example -- example_directory_name'\nExample: 'odin run build_web_example -- minimal'")
|
|
|
|
|
|
|
+ fmt.eprintfln("Usage: 'odin run build_web -- directory_name'\nExample: 'odin run build_web -- examples/minimal_web'")
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -33,17 +34,23 @@ main :: proc() {
|
|
|
fmt.ensuref(dir_stat_err == nil, "Failed checking status of directory %v. Error: %v", dir, dir_stat_err)
|
|
fmt.ensuref(dir_stat_err == nil, "Failed checking status of directory %v. Error: %v", dir, dir_stat_err)
|
|
|
fmt.ensuref(dir_stat.type == .Directory, "%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)
|
|
|
|
|
|
|
+ dir_name := dir_stat.name
|
|
|
|
|
+
|
|
|
|
|
+ bin_dir := filepath.join({dir, "bin"})
|
|
|
|
|
+ os.make_directory(bin_dir, 0o644)
|
|
|
|
|
+ bin_web_dir := filepath.join({bin_dir, "web"})
|
|
|
|
|
+ os.make_directory(bin_web_dir, 0o644)
|
|
|
|
|
|
|
|
- web_build_dir := filepath.join({web_dir, "build"})
|
|
|
|
|
- os.make_directory(web_build_dir, 0o644)
|
|
|
|
|
|
|
+ build_dir := filepath.join({dir, "build"})
|
|
|
|
|
+ os.make_directory(build_dir, 0o644)
|
|
|
|
|
+ build_web_dir := filepath.join({build_dir, "web"})
|
|
|
|
|
+ os.make_directory(build_web_dir, 0o644)
|
|
|
|
|
|
|
|
- entry_odin_file_path := filepath.join({web_dir, fmt.tprintf("%v_web_entry.odin", filepath.stem(dir))})
|
|
|
|
|
|
|
+ entry_odin_file_path := filepath.join({build_web_dir, fmt.tprintf("%v_web_entry.odin", dir_name)})
|
|
|
write_entry_odin_err := os.write_entire_file(entry_odin_file_path, WEB_ENTRY_TEMPLATE)
|
|
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)
|
|
fmt.ensuref(write_entry_odin_err == nil, "Failed writing %v. Error: %v", entry_odin_file_path, write_entry_odin_err)
|
|
|
|
|
|
|
|
- entry_html_file_path := filepath.join({web_build_dir, "index.html"})
|
|
|
|
|
|
|
+ entry_html_file_path := filepath.join({bin_web_dir, "index.html"})
|
|
|
write_entry_html_err := os.write_entire_file(entry_html_file_path, WEB_ENTRY_INDEX)
|
|
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)
|
|
fmt.ensuref(write_entry_html_err == nil, "Failed writing %v. Error: %v", entry_html_file_path, write_entry_html_err)
|
|
|
|
|
|
|
@@ -56,15 +63,15 @@ main :: proc() {
|
|
|
|
|
|
|
|
js_runtime_path := filepath.join({odin_root, "core", "sys", "wasm", "js", "odin.js"})
|
|
js_runtime_path := filepath.join({odin_root, "core", "sys", "wasm", "js", "odin.js"})
|
|
|
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)
|
|
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)
|
|
|
|
|
|
|
+ os.copy_file(filepath.join({bin_web_dir, "odin.js"}), js_runtime_path)
|
|
|
|
|
|
|
|
- wasm_out_path := filepath.join({web_build_dir, "main.wasm"})
|
|
|
|
|
|
|
+ wasm_out_path := filepath.join({bin_web_dir, "main.wasm"})
|
|
|
|
|
|
|
|
_, build_std_out, build_std_err, _ := os.process_exec({
|
|
_, build_std_out, build_std_err, _ := os.process_exec({
|
|
|
command = {
|
|
command = {
|
|
|
"odin",
|
|
"odin",
|
|
|
"build",
|
|
"build",
|
|
|
- web_dir,
|
|
|
|
|
|
|
+ build_web_dir,
|
|
|
fmt.tprintf("-out:%v", wasm_out_path),
|
|
fmt.tprintf("-out:%v", wasm_out_path),
|
|
|
"-target:js_wasm32",
|
|
"-target:js_wasm32",
|
|
|
"-debug",
|
|
"-debug",
|