From 10380c394d292f19e3a295ee5c7859ea5c6433de Mon Sep 17 00:00:00 2001 From: c0repwn3r Date: Wed, 12 Apr 2023 11:16:34 -0400 Subject: [PATCH] [wip] spacetime build - build client with both texture loaders --- spacetime/spacetime.py | 57 +++++++++++++++++++++++++++++++++++++++++- st | 29 ++++++++++++++++++--- 2 files changed, 81 insertions(+), 5 deletions(-) diff --git a/spacetime/spacetime.py b/spacetime/spacetime.py index da923aa062fef41223a339928a3fce36041e75de..285da74d859198ba91f6e33de8fa07ccaff169ab 100644 --- a/spacetime/spacetime.py +++ b/spacetime/spacetime.py @@ -58,6 +58,59 @@ def gen_inkscape_rules_for_asset(root, asset, writer, files_375, files_full, fil writer.build([out_375], rule_375, [in_file]) writer.build([out_125], rule_125, [in_file]) +def gen_rules_for_client(root, env, writer): + if env == 'dev': + writer.rule('cargo-client', 'wasm-pack build --target web client', depfile=f'{root}/target/wasm32-unknown-unknown/release/starkingdoms_client.d', pool='console') + elif env == 'prod': + writer.rule('cargo-client', 'wasm-pack build --target web client --no-default-features --features textures-fast', depfile=f'{root}/target/wasm32-unknown-unknown/release/starkingdoms_client.d', pool='console') + writer.build( + [ + f'{root}/client/pkg/.gitignore', + f'{root}/client/pkg/package.json', + f'{root}/client/pkg/starkingdoms_client.d.ts', + f'{root}/client/pkg/starkingdoms_client.js', + f'{root}/client/pkg/starkingdoms_client_bg.wasm', + f'{root}/client/pkg/starkingdoms_client_bg.wasm.d.ts', + f'{root}/target/wasm32-unknown-unknown/release/starkingdoms_client.wasm' + ], + 'cargo-client', + [ + f'{root}/assets/dist/spritesheet-125', + f'{root}/assets/dist/spritesheet-125.png', + f'{root}/assets/dist/spritesheet-125.ron', + f'{root}/assets/dist/spritesheet-375', + f'{root}/assets/dist/spritesheet-375.png', + f'{root}/assets/dist/spritesheet-375.ron', + f'{root}/assets/dist/spritesheet-full', + f'{root}/assets/dist/spritesheet-full.png', + f'{root}/assets/dist/spritesheet-full.ron', + ] + ) + + writer.rule('client-copy-file', f'cp -r {root}/client/pkg {root}/web/dist') + + writer.build( + [ + f'{root}/web/dist/.gitignore', + f'{root}/web/dist/package.json', + f'{root}/web/dist/starkingdoms_client.d.ts', + f'{root}/web/dist/starkingdoms_client.js', + f'{root}/web/dist/starkingdoms_client_bg.wasm', + f'{root}/web/dist/starkingdoms_client_bg.wasm.d.ts' + ], + 'client-copy-file', + [ + f'{root}/client/pkg/.gitignore', + f'{root}/client/pkg/package.json', + f'{root}/client/pkg/starkingdoms_client.d.ts', + f'{root}/client/pkg/starkingdoms_client.js', + f'{root}/client/pkg/starkingdoms_client_bg.wasm', + f'{root}/client/pkg/starkingdoms_client_bg.wasm.d.ts', + ], + ) + + writer.build(['client'], 'phony', [f'{root}/web/dist/starkingdoms_client.js']) + def gen_inkscape(root, assets, writer, files_375, files_full, files_125): gen_inkscape_rules_for_asset_sizes(writer) @@ -102,7 +155,7 @@ def main(): target = sys.argv[1] env = sys.argv[2] root = sys.argv[3] - print(f'[spacetime] Configuring target {target} with ENV={env}, buildroot={root}') + print(f'[spacetime] Configuring ninja for PRIMARY_TARGET={target} with ENV={env}, BUILDROOT={root}') with open(f'{root}/build.ninja', 'w') as f: writer = Writer(f) @@ -114,6 +167,8 @@ def main(): assets = scan_assets(root) generate_assets_build_command(root, assets, writer) + gen_rules_for_client(root, env, writer) + print(f'[spacetime] Configured build') diff --git a/st b/st index 94d37460bc8744d87f2352cf0f69ffbe9a9ec8c6..bb29f6d5c2b927b34997df5256a87440e09b00da 100755 --- a/st +++ b/st @@ -22,11 +22,12 @@ sub_help() { echo "Spacetime is a small utility program to generate Ninja build manifests for compiling StarKingdoms." echo "Available targets:" echo " help - Show this help screen" # done - echo " run_http - Compile the client and run a development http server for testing it" - echo " run_http_prod - Compile the client in production mode and run a development http server for testing it" + echo " run_http - Compile the client and run a development http server for testing it" # done + echo " run_http_prod - Compile the client in production mode and run a development http server for testing it" # done echo " run_server (default) - Compile and run the game server" - echo " build_client_bundle - Compile an optimized WebAssembly client bundle" - echo " build_client_bundle_prod - Compile an optimized WebAssembly client bundle using textures-fast" + echo " build_server - Compile the game server" + echo " build_client_bundle - Compile an optimized WebAssembly client bundle" # done + echo " build_client_bundle_prod - Compile an optimized WebAssembly client bundle using textures-fast" # done echo " install_tooling - Install the compilation utilities required for compiling StarKingdoms" # done echo " build_assets - Compile spritesheets in all three texture sizes for textures-fast" # done echo " build_assets_full - Compile spritesheets in full size for textures-fast" # done @@ -72,6 +73,26 @@ sub_build_client_bundle() { exec_ninja client } +sub_run_http() { + check_all + exec_spacetime client dev "$SCRIPT_DIR" + exec_ninja client + cd web && python3 -m http.server +} + +sub_build_client_bundle_prod() { + check_all + exec_spacetime client prod "$SCRIPT_DIR" + exec_ninja client +} + +sub_run_http_prod() { + check_all + exec_spacetime client prod "$SCRIPT_DIR" + exec_ninja client + cd web && python3 -m http.server +} + sub_build_assets() { check_all exec_spacetime asset dev "$SCRIPT_DIR"