mt-lang 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.ruby-version +1 -0
- data/AUTHORS +3 -0
- data/Gemfile +19 -0
- data/Gemfile.lock +82 -0
- data/LICENSE +21 -0
- data/README.md +1208 -0
- data/Rakefile +332 -0
- data/bin/mtc +8 -0
- data/bin/profile-mtc-checks +133 -0
- data/bin/tracy-profiler +0 -0
- data/docs/build-guide.md +536 -0
- data/docs/index.html +2778 -0
- data/docs/language-design.md +1519 -0
- data/docs/language-manual.md +1534 -0
- data/lib/milk_tea/base.rb +49 -0
- data/lib/milk_tea/bindings/bindgen/ast_parser.rb +398 -0
- data/lib/milk_tea/bindings/bindgen/declaration.rb +319 -0
- data/lib/milk_tea/bindings/bindgen/emitter.rb +387 -0
- data/lib/milk_tea/bindings/bindgen/overrides.rb +134 -0
- data/lib/milk_tea/bindings/bindgen/type_mapper.rb +622 -0
- data/lib/milk_tea/bindings/bindgen.rb +207 -0
- data/lib/milk_tea/bindings/cli.rb +121 -0
- data/lib/milk_tea/bindings/imported_bindings/defaults.rb +210 -0
- data/lib/milk_tea/bindings/imported_bindings/generator.rb +1114 -0
- data/lib/milk_tea/bindings/imported_bindings/method_source.rb +190 -0
- data/lib/milk_tea/bindings/imported_bindings/naming.rb +286 -0
- data/lib/milk_tea/bindings/imported_bindings.rb +215 -0
- data/lib/milk_tea/bindings/opengl_registry.rb +547 -0
- data/lib/milk_tea/bindings/raw_bindings/defaults.rb +1338 -0
- data/lib/milk_tea/bindings/raw_bindings.rb +269 -0
- data/lib/milk_tea/bindings/steamworks.rb +629 -0
- data/lib/milk_tea/bindings/upstream_sources.rb +352 -0
- data/lib/milk_tea/bindings/vendored_box2d.rb +79 -0
- data/lib/milk_tea/bindings/vendored_c_library.rb +322 -0
- data/lib/milk_tea/bindings/vendored_cjson.rb +52 -0
- data/lib/milk_tea/bindings/vendored_flecs.rb +78 -0
- data/lib/milk_tea/bindings/vendored_glfw.rb +77 -0
- data/lib/milk_tea/bindings/vendored_libuv.rb +75 -0
- data/lib/milk_tea/bindings/vendored_pcre2.rb +84 -0
- data/lib/milk_tea/bindings/vendored_raylib.rb +131 -0
- data/lib/milk_tea/bindings/vendored_sdl3.rb +78 -0
- data/lib/milk_tea/bindings/vendored_steamworks.rb +71 -0
- data/lib/milk_tea/bindings/vendored_tool.rb +71 -0
- data/lib/milk_tea/bindings/vendored_tools.rb +23 -0
- data/lib/milk_tea/bindings/vendored_tracy.rb +37 -0
- data/lib/milk_tea/bindings.rb +23 -0
- data/lib/milk_tea/core/ast.rb +311 -0
- data/lib/milk_tea/core/async_runtime_installer.rb +28 -0
- data/lib/milk_tea/core/binding_types.rb +18 -0
- data/lib/milk_tea/core/bindings/attribute_binding.rb +58 -0
- data/lib/milk_tea/core/bindings/function_binding.rb +5 -0
- data/lib/milk_tea/core/bindings/module_binding.rb +58 -0
- data/lib/milk_tea/core/bindings/value_binding.rb +21 -0
- data/lib/milk_tea/core/c_backend/aggregate_utils.rb +103 -0
- data/lib/milk_tea/core/c_backend/control_flow_emission.rb +412 -0
- data/lib/milk_tea/core/c_backend/expressions.rb +468 -0
- data/lib/milk_tea/core/c_backend/feature_detection.rb +483 -0
- data/lib/milk_tea/core/c_backend/reachability.rb +398 -0
- data/lib/milk_tea/core/c_backend/reinterpret.rb +226 -0
- data/lib/milk_tea/core/c_backend/runtime_helpers.rb +1080 -0
- data/lib/milk_tea/core/c_backend/statements.rb +563 -0
- data/lib/milk_tea/core/c_backend/type_collectors.rb +1545 -0
- data/lib/milk_tea/core/c_backend/type_declaration.rb +223 -0
- data/lib/milk_tea/core/c_backend/type_system.rb +345 -0
- data/lib/milk_tea/core/c_backend.rb +287 -0
- data/lib/milk_tea/core/compatibility_helpers.rb +79 -0
- data/lib/milk_tea/core/compile_time/const_eval.rb +187 -0
- data/lib/milk_tea/core/compile_time.rb +329 -0
- data/lib/milk_tea/core/control_flow/builder.rb +582 -0
- data/lib/milk_tea/core/control_flow/constant_propagation.rb +143 -0
- data/lib/milk_tea/core/control_flow/dataflow.rb +74 -0
- data/lib/milk_tea/core/control_flow/definite_assignment.rb +79 -0
- data/lib/milk_tea/core/control_flow/graph.rb +90 -0
- data/lib/milk_tea/core/control_flow/liveness.rb +24 -0
- data/lib/milk_tea/core/control_flow/nullability_flow.rb +43 -0
- data/lib/milk_tea/core/control_flow/reachability.rb +22 -0
- data/lib/milk_tea/core/control_flow/termination.rb +31 -0
- data/lib/milk_tea/core/control_flow.rb +34 -0
- data/lib/milk_tea/core/cst.rb +48 -0
- data/lib/milk_tea/core/cst_builder.rb +19 -0
- data/lib/milk_tea/core/ir.rb +85 -0
- data/lib/milk_tea/core/keywords.rb +97 -0
- data/lib/milk_tea/core/lexer/character_classes.rb +60 -0
- data/lib/milk_tea/core/lexer/format_strings.rb +225 -0
- data/lib/milk_tea/core/lexer/heredocs.rb +199 -0
- data/lib/milk_tea/core/lexer/indentation.rb +62 -0
- data/lib/milk_tea/core/lexer/numbers.rb +96 -0
- data/lib/milk_tea/core/lexer/recovery.rb +32 -0
- data/lib/milk_tea/core/lexer/strings.rb +167 -0
- data/lib/milk_tea/core/lexer/symbols.rb +71 -0
- data/lib/milk_tea/core/lexer/trivia.rb +53 -0
- data/lib/milk_tea/core/lexer.rb +430 -0
- data/lib/milk_tea/core/lowering/artifacts.rb +26 -0
- data/lib/milk_tea/core/lowering/async/analysis.rb +245 -0
- data/lib/milk_tea/core/lowering/async/lowering.rb +1399 -0
- data/lib/milk_tea/core/lowering/async/normalization.rb +459 -0
- data/lib/milk_tea/core/lowering/async.rb +714 -0
- data/lib/milk_tea/core/lowering/block.rb +1052 -0
- data/lib/milk_tea/core/lowering/calls.rb +1565 -0
- data/lib/milk_tea/core/lowering/declarations.rb +214 -0
- data/lib/milk_tea/core/lowering/dyn.rb +206 -0
- data/lib/milk_tea/core/lowering/events.rb +1054 -0
- data/lib/milk_tea/core/lowering/expressions.rb +1645 -0
- data/lib/milk_tea/core/lowering/foreign_cstr.rb +206 -0
- data/lib/milk_tea/core/lowering/functions.rb +242 -0
- data/lib/milk_tea/core/lowering/loops.rb +1087 -0
- data/lib/milk_tea/core/lowering/lowering_context.rb +80 -0
- data/lib/milk_tea/core/lowering/proc.rb +419 -0
- data/lib/milk_tea/core/lowering/resolve.rb +2516 -0
- data/lib/milk_tea/core/lowering/scans.rb +220 -0
- data/lib/milk_tea/core/lowering/str_buffer.rb +125 -0
- data/lib/milk_tea/core/lowering/utils.rb +1453 -0
- data/lib/milk_tea/core/lowering.rb +378 -0
- data/lib/milk_tea/core/module_binder.rb +181 -0
- data/lib/milk_tea/core/module_loader/errors.rb +21 -0
- data/lib/milk_tea/core/module_loader.rb +479 -0
- data/lib/milk_tea/core/module_path_resolver.rb +153 -0
- data/lib/milk_tea/core/module_roots.rb +88 -0
- data/lib/milk_tea/core/parser/attributes.rb +71 -0
- data/lib/milk_tea/core/parser/blocks.rb +119 -0
- data/lib/milk_tea/core/parser/declarations.rb +749 -0
- data/lib/milk_tea/core/parser/expressions.rb +624 -0
- data/lib/milk_tea/core/parser/recovery.rb +131 -0
- data/lib/milk_tea/core/parser/statements.rb +756 -0
- data/lib/milk_tea/core/parser/types.rb +271 -0
- data/lib/milk_tea/core/parser.rb +400 -0
- data/lib/milk_tea/core/prelude_installer.rb +29 -0
- data/lib/milk_tea/core/pretty_printer/ast_formatter.rb +917 -0
- data/lib/milk_tea/core/pretty_printer/base_formatter.rb +87 -0
- data/lib/milk_tea/core/pretty_printer/ir_formatter.rb +300 -0
- data/lib/milk_tea/core/pretty_printer.rb +17 -0
- data/lib/milk_tea/core/semantic_analyzer/analysis_context.rb +314 -0
- data/lib/milk_tea/core/semantic_analyzer/attributes.rb +184 -0
- data/lib/milk_tea/core/semantic_analyzer/calls.rb +992 -0
- data/lib/milk_tea/core/semantic_analyzer/expressions.rb +1735 -0
- data/lib/milk_tea/core/semantic_analyzer/flow_refinement.rb +355 -0
- data/lib/milk_tea/core/semantic_analyzer/foreign_functions.rb +155 -0
- data/lib/milk_tea/core/semantic_analyzer/function_binding.rb +354 -0
- data/lib/milk_tea/core/semantic_analyzer/generics.rb +383 -0
- data/lib/milk_tea/core/semantic_analyzer/interface_conformance.rb +78 -0
- data/lib/milk_tea/core/semantic_analyzer/module_context.rb +35 -0
- data/lib/milk_tea/core/semantic_analyzer/name_resolution.rb +1438 -0
- data/lib/milk_tea/core/semantic_analyzer/nullability.rb +421 -0
- data/lib/milk_tea/core/semantic_analyzer/statements.rb +1308 -0
- data/lib/milk_tea/core/semantic_analyzer/top_level.rb +588 -0
- data/lib/milk_tea/core/semantic_analyzer/type_compatibility.rb +307 -0
- data/lib/milk_tea/core/semantic_analyzer/type_declaration.rb +851 -0
- data/lib/milk_tea/core/semantic_analyzer.rb +327 -0
- data/lib/milk_tea/core/token.rb +26 -0
- data/lib/milk_tea/core/token_stream.rb +30 -0
- data/lib/milk_tea/core/types/layout.rb +243 -0
- data/lib/milk_tea/core/types/predicates.rb +609 -0
- data/lib/milk_tea/core/types/registry.rb +83 -0
- data/lib/milk_tea/core/types/types.rb +1696 -0
- data/lib/milk_tea/core/types/visitor.rb +442 -0
- data/lib/milk_tea/core.rb +25 -0
- data/lib/milk_tea/dap/backends/lldb_dap.rb +158 -0
- data/lib/milk_tea/dap/protocol.rb +58 -0
- data/lib/milk_tea/dap/server/breakpoints.rb +66 -0
- data/lib/milk_tea/dap/server/debug_map.rb +291 -0
- data/lib/milk_tea/dap/server/handlers.rb +374 -0
- data/lib/milk_tea/dap/server/launch.rb +261 -0
- data/lib/milk_tea/dap/server/lldb_backend.rb +380 -0
- data/lib/milk_tea/dap/server/pause_diagnostics.rb +109 -0
- data/lib/milk_tea/dap/server/utilities.rb +160 -0
- data/lib/milk_tea/dap/server/wire.rb +55 -0
- data/lib/milk_tea/dap/server.rb +131 -0
- data/lib/milk_tea/dap/session.rb +152 -0
- data/lib/milk_tea/dap.rb +6 -0
- data/lib/milk_tea/lsp/dependency_resolution.rb +52 -0
- data/lib/milk_tea/lsp/diagnostics.rb +611 -0
- data/lib/milk_tea/lsp/protocol.rb +104 -0
- data/lib/milk_tea/lsp/server/call_hierarchy.rb +274 -0
- data/lib/milk_tea/lsp/server/code_actions.rb +446 -0
- data/lib/milk_tea/lsp/server/code_lens.rb +97 -0
- data/lib/milk_tea/lsp/server/completion.rb +1099 -0
- data/lib/milk_tea/lsp/server/configuration.rb +167 -0
- data/lib/milk_tea/lsp/server/debug_info.rb +45 -0
- data/lib/milk_tea/lsp/server/definition.rb +779 -0
- data/lib/milk_tea/lsp/server/diagnostics_scheduling.rb +239 -0
- data/lib/milk_tea/lsp/server/execute_command.rb +25 -0
- data/lib/milk_tea/lsp/server/folding_range.rb +153 -0
- data/lib/milk_tea/lsp/server/formatting.rb +575 -0
- data/lib/milk_tea/lsp/server/hover.rb +1465 -0
- data/lib/milk_tea/lsp/server/inlay_hints.rb +204 -0
- data/lib/milk_tea/lsp/server/lifecycle.rb +234 -0
- data/lib/milk_tea/lsp/server/linked_editing_range.rb +43 -0
- data/lib/milk_tea/lsp/server/on_type_formatting.rb +73 -0
- data/lib/milk_tea/lsp/server/progress.rb +47 -0
- data/lib/milk_tea/lsp/server/references.rb +433 -0
- data/lib/milk_tea/lsp/server/rename.rb +598 -0
- data/lib/milk_tea/lsp/server/selection_range.rb +130 -0
- data/lib/milk_tea/lsp/server/semantic_tokens.rb +1745 -0
- data/lib/milk_tea/lsp/server/signature_help.rb +200 -0
- data/lib/milk_tea/lsp/server/text_documents.rb +125 -0
- data/lib/milk_tea/lsp/server/type_hierarchy.rb +167 -0
- data/lib/milk_tea/lsp/server/utilities.rb +520 -0
- data/lib/milk_tea/lsp/server.rb +415 -0
- data/lib/milk_tea/lsp/workspace/analysis.rb +209 -0
- data/lib/milk_tea/lsp/workspace/caches.rb +260 -0
- data/lib/milk_tea/lsp/workspace/collection.rb +98 -0
- data/lib/milk_tea/lsp/workspace/definition_index.rb +184 -0
- data/lib/milk_tea/lsp/workspace/dependency_graph.rb +282 -0
- data/lib/milk_tea/lsp/workspace/store.rb +154 -0
- data/lib/milk_tea/lsp/workspace/utilities.rb +490 -0
- data/lib/milk_tea/lsp/workspace.rb +127 -0
- data/lib/milk_tea/lsp.rb +13 -0
- data/lib/milk_tea/packages/atomic_write.rb +63 -0
- data/lib/milk_tea/packages/dependency_solver.rb +194 -0
- data/lib/milk_tea/packages/graph.rb +139 -0
- data/lib/milk_tea/packages/lock.rb +421 -0
- data/lib/milk_tea/packages/manager_cli.rb +485 -0
- data/lib/milk_tea/packages/manifest.rb +356 -0
- data/lib/milk_tea/packages/manifest_editor.rb +134 -0
- data/lib/milk_tea/packages/registry_metadata_provider.rb +34 -0
- data/lib/milk_tea/packages/registry_store.rb +420 -0
- data/lib/milk_tea/packages/services.rb +41 -0
- data/lib/milk_tea/packages/source_cache.rb +71 -0
- data/lib/milk_tea/packages/source_fetcher.rb +124 -0
- data/lib/milk_tea/packages/source_resolver.rb +389 -0
- data/lib/milk_tea/packages/version.rb +164 -0
- data/lib/milk_tea/packages.rb +16 -0
- data/lib/milk_tea/tooling/asset_pack.rb +141 -0
- data/lib/milk_tea/tooling/build.rb +1124 -0
- data/lib/milk_tea/tooling/build_cache.rb +240 -0
- data/lib/milk_tea/tooling/cli.rb +2688 -0
- data/lib/milk_tea/tooling/cst_formatter.rb +13 -0
- data/lib/milk_tea/tooling/debug_info_formatter.rb +456 -0
- data/lib/milk_tea/tooling/debug_map.rb +248 -0
- data/lib/milk_tea/tooling/docs_app.rb +369 -0
- data/lib/milk_tea/tooling/error_formatter.rb +86 -0
- data/lib/milk_tea/tooling/formatter.rb +787 -0
- data/lib/milk_tea/tooling/linter/doc_tags.rb +212 -0
- data/lib/milk_tea/tooling/linter/fix_engine.rb +237 -0
- data/lib/milk_tea/tooling/linter/flow_rules.rb +380 -0
- data/lib/milk_tea/tooling/linter/imports_platform.rb +841 -0
- data/lib/milk_tea/tooling/linter/release_rules.rb +744 -0
- data/lib/milk_tea/tooling/linter/reserved_names.rb +199 -0
- data/lib/milk_tea/tooling/linter/rules.rb +593 -0
- data/lib/milk_tea/tooling/linter/source_helpers.rb +407 -0
- data/lib/milk_tea/tooling/linter/trailing_comma.rb +139 -0
- data/lib/milk_tea/tooling/linter/visitors.rb +1286 -0
- data/lib/milk_tea/tooling/linter.rb +798 -0
- data/lib/milk_tea/tooling/project_scaffold.rb +82 -0
- data/lib/milk_tea/tooling/public/css/docs.css +166 -0
- data/lib/milk_tea/tooling/public/js/docs.js +94 -0
- data/lib/milk_tea/tooling/run.rb +408 -0
- data/lib/milk_tea/tooling/templates/wasm_shell.html +48 -0
- data/lib/milk_tea/tooling/toolchain_cli.rb +157 -0
- data/lib/milk_tea/tooling/views/404.erb +7 -0
- data/lib/milk_tea/tooling/views/index.erb +87 -0
- data/lib/milk_tea/tooling/views/layout.erb +69 -0
- data/lib/milk_tea/tooling/views/module.erb +97 -0
- data/lib/milk_tea/tooling/views/stdlib.erb +21 -0
- data/lib/milk_tea/tooling.rb +20 -0
- data/lib/milk_tea.rb +8 -0
- metadata +426 -0
data/docs/build-guide.md
ADDED
|
@@ -0,0 +1,536 @@
|
|
|
1
|
+
# Milk Tea Build Guide
|
|
2
|
+
|
|
3
|
+
This guide documents package manifests, local library dependencies, executable builds, and the current wasm workflow.
|
|
4
|
+
|
|
5
|
+
## 1. Packages And Entry Points
|
|
6
|
+
|
|
7
|
+
Milk Tea builds either a single source file or a package directory.
|
|
8
|
+
|
|
9
|
+
- A source build compiles one `.mt` file directly.
|
|
10
|
+
- A package build reads `package.toml` from the target directory.
|
|
11
|
+
|
|
12
|
+
Create a new application package scaffold with:
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
mtc new my-project
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
This writes `package.toml` and `src/main.mt` into `my-project/`. The scaffold uses an explicit `build.entry = "src/main.mt"`, normalizes the directory basename to snake_case for `package.name`, and generates a headerless entry file. For example, both `mtc new my-project` and `mtc new MyProject` generate `package.name = "my_project"` and `src/main.mt` with just the entry `function main()`.
|
|
19
|
+
The generated manifest also writes `package.source_root = "src"` explicitly so imports resolve from `src/` without requiring a `src.` prefix.
|
|
20
|
+
|
|
21
|
+
Minimal package example:
|
|
22
|
+
|
|
23
|
+
```toml
|
|
24
|
+
[package]
|
|
25
|
+
name = "game_engine"
|
|
26
|
+
version = "0.1.0"
|
|
27
|
+
source_root = "src"
|
|
28
|
+
|
|
29
|
+
[profile]
|
|
30
|
+
default = "debug"
|
|
31
|
+
|
|
32
|
+
[platform]
|
|
33
|
+
default = "wasm"
|
|
34
|
+
|
|
35
|
+
[build]
|
|
36
|
+
entry = "src/main.mt"
|
|
37
|
+
assets = "assets"
|
|
38
|
+
html_template = "web/shell.html"
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Relevant build keys:
|
|
42
|
+
|
|
43
|
+
- `package.kind`: optional package kind. The default is `application`. Use `library` for reusable source packages.
|
|
44
|
+
- `package.source_root`: optional module root for the package. When a package contains a `src/` directory, the default is `src`; otherwise the default is the package root.
|
|
45
|
+
- Module identity inside a package is inferred relative to `package.source_root`, so `src/main.mt` is module `main` and `src/game/player.mt` is module `game.player`.
|
|
46
|
+
- `build.entry`: entry source file, relative to the package root.
|
|
47
|
+
- `build.output`: optional explicit output path.
|
|
48
|
+
- `build.assets`: optional runtime asset path or array of paths. Each entry may be a file or directory. wasm builds preload each entry into the virtual filesystem; native builds either stage each entry beside the executable or pack them into `assets.mtpack` for bundle/archive outputs.
|
|
49
|
+
- `build.html_template`: optional HTML shell template for wasm builds.
|
|
50
|
+
- `profile.default`: default profile when the CLI does not receive `--profile`.
|
|
51
|
+
- `platform.default`: default platform when the CLI does not receive `--platform`.
|
|
52
|
+
|
|
53
|
+
Packages default to `build.entry = "src/main.mt"` when that file exists. Library packages do not have an executable entry point.
|
|
54
|
+
|
|
55
|
+
### 1.1 Platform-specific source file variants
|
|
56
|
+
|
|
57
|
+
Milk Tea supports platform-specific full-file replacements for ordinary source files.
|
|
58
|
+
|
|
59
|
+
Canonical filename forms are:
|
|
60
|
+
|
|
61
|
+
- shared file: `name.mt`
|
|
62
|
+
- Linux variant: `name.linux.mt`
|
|
63
|
+
- Windows variant: `name.windows.mt`
|
|
64
|
+
- wasm variant: `name.wasm.mt`
|
|
65
|
+
|
|
66
|
+
Resolution is deterministic:
|
|
67
|
+
|
|
68
|
+
1. choose the active target platform from `--platform`, otherwise `platform.default`, otherwise the host platform
|
|
69
|
+
2. when resolving `name.mt`, prefer `name.<platform>.mt`
|
|
70
|
+
3. fall back to `name.mt` when the platform-specific file does not exist
|
|
71
|
+
|
|
72
|
+
This applies to both imports and package entry files. For example, if `build.entry = "src/main.mt"` and the active target is `windows`, Milk Tea first tries `src/main.windows.mt` and falls back to `src/main.mt`.
|
|
73
|
+
|
|
74
|
+
Imports keep the ordinary logical module name:
|
|
75
|
+
|
|
76
|
+
```mt
|
|
77
|
+
import tetris.rules.scoring as scoring
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
The importer never spells the platform in the import path. `tetris.rules.scoring` may resolve to either `tetris/rules/scoring.mt` or `tetris/rules/scoring.<platform>.mt` depending on the active target.
|
|
81
|
+
|
|
82
|
+
Only the canonical suffixes `linux`, `windows`, and `wasm` are valid in source filenames. CLI and manifest aliases such as `web` and `browser` still normalize to `wasm`, but source files should use `*.wasm.mt`.
|
|
83
|
+
|
|
84
|
+
If you directly target a suffixed source file such as `src/main.windows.mt`, that file pins the target platform. Passing a conflicting explicit platform is an error.
|
|
85
|
+
|
|
86
|
+
## 2. Library Packages, Version Requirements, And Dependency Commands
|
|
87
|
+
|
|
88
|
+
Milk Tea packages can now depend on local reusable source packages.
|
|
89
|
+
|
|
90
|
+
Library package example:
|
|
91
|
+
|
|
92
|
+
```toml
|
|
93
|
+
[package]
|
|
94
|
+
name = "tetris.pieces"
|
|
95
|
+
version = "0.1.0"
|
|
96
|
+
kind = "library"
|
|
97
|
+
source_root = "src"
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Application package with local dependencies:
|
|
101
|
+
|
|
102
|
+
```toml
|
|
103
|
+
[package]
|
|
104
|
+
name = "tetris"
|
|
105
|
+
version = "0.1.0"
|
|
106
|
+
|
|
107
|
+
[build]
|
|
108
|
+
entry = "src/main.mt"
|
|
109
|
+
|
|
110
|
+
[dependencies]
|
|
111
|
+
"tetris.pieces" = { path = "packages/tetris_pieces", version = "0.1.0" }
|
|
112
|
+
"tetris.rules" = { path = "packages/tetris_rules", version = "0.1.0" }
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Application package with a pinned git dependency:
|
|
116
|
+
|
|
117
|
+
```toml
|
|
118
|
+
[package]
|
|
119
|
+
name = "tetris"
|
|
120
|
+
version = "0.1.0"
|
|
121
|
+
|
|
122
|
+
[dependencies]
|
|
123
|
+
"teefan.ui" = { git = "https://example.invalid/teefan/ui.git", rev = "deadbeef", subdir = "packages/ui" }
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Application package with an exact registry dependency:
|
|
127
|
+
|
|
128
|
+
```toml
|
|
129
|
+
[package]
|
|
130
|
+
name = "tetris"
|
|
131
|
+
version = "0.1.0"
|
|
132
|
+
|
|
133
|
+
[dependencies]
|
|
134
|
+
"teefan.ui" = "1.2.3"
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Application package with a ranged registry dependency:
|
|
138
|
+
|
|
139
|
+
```toml
|
|
140
|
+
[package]
|
|
141
|
+
name = "tetris"
|
|
142
|
+
version = "0.1.0"
|
|
143
|
+
|
|
144
|
+
[dependencies]
|
|
145
|
+
"teefan.ui" = "^1.2.3"
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Dependency paths are resolved relative to the depending package root.
|
|
149
|
+
|
|
150
|
+
Supported version requirement forms:
|
|
151
|
+
|
|
152
|
+
- exact: `1.2.3`
|
|
153
|
+
- lower bound: `>=1.2.3`
|
|
154
|
+
- upper bound: `<2.0.0`
|
|
155
|
+
- compatible release: `^1.2.3`
|
|
156
|
+
- patch-compatible release: `~1.2.3`
|
|
157
|
+
- conjunctions: `>=1.2.3, <2.0.0`
|
|
158
|
+
|
|
159
|
+
For local `path` dependencies, `version = "..."` is optional. When present, the depending manifest records the expected local package version and resolution fails if the target package's `package.version` does not satisfy that requirement.
|
|
160
|
+
|
|
161
|
+
Imported modules keep normal Milk Tea syntax:
|
|
162
|
+
|
|
163
|
+
```milk-tea
|
|
164
|
+
import tetris.pieces.defs as pieces
|
|
165
|
+
import tetris.rules.scoring as scoring
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Current scope:
|
|
169
|
+
|
|
170
|
+
- local `path` dependencies, optional versioned `path` dependencies, pinned git dependencies (`git`, `rev`, optional `subdir`), and exact or ranged registry dependencies are supported in dependency-management flows
|
|
171
|
+
- exact registry versions behave like fixed source identities in dependency-management and locked flows
|
|
172
|
+
- ranged registry dependencies are now solved per dependency instance, so different transitive paths may resolve the same package namespace to different registry versions when required
|
|
173
|
+
- dependency source roots are resolved recursively
|
|
174
|
+
- packages can import their own modules, `std`, and declared direct dependencies only
|
|
175
|
+
- transitive dependency packages are loaded for dependent packages, but they are not directly importable from the root application unless declared there too
|
|
176
|
+
- package dependency cycles are rejected during graph construction
|
|
177
|
+
- deterministic `package.lock` generation is supported for package-instance-aware graphs, including duplicate registry package namespaces
|
|
178
|
+
- `deps tree`, `deps lock`, `deps add`, `deps remove`, `deps update`, and `deps fetch` are explicit dependency-management commands; commands that need git or registry sources may materialize them into the shared source cache while reading manifests
|
|
179
|
+
- build, check, run, and live LSP dependency resolution stay fetch-free; git or registry manifests are meant to flow through `deps lock` plus `--locked` or `--frozen`, while live direct resolution continues to reject cache-backed dependencies
|
|
180
|
+
- local registry publish and fetch flows now exist, and `$MILK_TEA_PACKAGE_REGISTRY_UPSTREAM` may point either to another filesystem registry root or to a static HTTP mirror of the same published registry layout; `deps lock`, `deps update`, and `deps fetch` may sync missing registry versions from it
|
|
181
|
+
|
|
182
|
+
Inspect the current local package graph with:
|
|
183
|
+
|
|
184
|
+
```sh
|
|
185
|
+
mtc deps tree path/to/package
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
When run inside a package directory, `mtc deps tree` defaults to the current directory.
|
|
189
|
+
|
|
190
|
+
When pinned git or exact registry dependencies are present, `mtc deps tree` may materialize them into the shared source cache so it can read their manifests.
|
|
191
|
+
|
|
192
|
+
Add or update a dependency in `package.toml` and refresh `package.lock` with:
|
|
193
|
+
|
|
194
|
+
```sh
|
|
195
|
+
mtc deps add path/to/package teefan.ui@^1.2.3
|
|
196
|
+
mtc deps add path/to/package tetris.rules --path packages/tetris_rules --version 0.1.0
|
|
197
|
+
mtc deps add path/to/package teefan.ui --git https://example.invalid/teefan/ui.git --rev deadbeef --subdir packages/ui
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Remove a dependency and refresh `package.lock` with:
|
|
201
|
+
|
|
202
|
+
```sh
|
|
203
|
+
mtc deps remove path/to/package teefan.ui
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Re-resolve the current manifest and refresh `package.lock` with:
|
|
207
|
+
|
|
208
|
+
```sh
|
|
209
|
+
mtc deps update path/to/package
|
|
210
|
+
mtc deps update path/to/package teefan.ui
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
`deps update` keeps the manifest requirements unchanged and picks the newest available versions that still satisfy them under the current instance-aware registry solver.
|
|
214
|
+
|
|
215
|
+
When you pass one or more package names, `deps update` updates those packages and their currently locked transitive package-instance closure while keeping unrelated locked registry instances pinned to their existing versions.
|
|
216
|
+
|
|
217
|
+
Named selective updates require a current `package.lock` that still matches the current manifest, because that locked graph defines which transitive packages are allowed to move. If the lockfile is missing or stale, run plain `mtc deps update path/to/package` or `mtc deps lock path/to/package` first.
|
|
218
|
+
|
|
219
|
+
When `$MILK_TEA_PACKAGE_REGISTRY_UPSTREAM` is configured, `deps update` may also adopt a newer matching registry version from that upstream mirror and sync it into the local registry before materializing the shared source cache.
|
|
220
|
+
|
|
221
|
+
Publish a versioned package into the local registry store with:
|
|
222
|
+
|
|
223
|
+
```sh
|
|
224
|
+
mtc deps publish path/to/package
|
|
225
|
+
mtc deps publish path/to/package --upstream
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
Publishing rules:
|
|
229
|
+
|
|
230
|
+
- the package must declare `package.version`
|
|
231
|
+
- publishing is immutable; an existing `name + version` cannot be overwritten
|
|
232
|
+
- the local registry root is `$MILK_TEA_PACKAGE_REGISTRY` when set, otherwise `$XDG_DATA_HOME/milk_tea/registry` or `~/.local/share/milk_tea/registry`
|
|
233
|
+
- `--upstream` publishes into `$MILK_TEA_PACKAGE_REGISTRY_UPSTREAM` instead, when configured
|
|
234
|
+
- publishing still requires a filesystem registry root; HTTP upstreams are read-only static mirrors
|
|
235
|
+
- the static HTTP mirror contract is the published registry layout plus `packages/<name>/versions.txt` and `packages/<name>/<version>.tar.gz`, so any ordinary static file server can host it
|
|
236
|
+
|
|
237
|
+
Materialize any cache-backed sources referenced by the current `package.lock` with:
|
|
238
|
+
|
|
239
|
+
```sh
|
|
240
|
+
mtc deps fetch path/to/package
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
Current `deps fetch` scope:
|
|
244
|
+
|
|
245
|
+
- it reads `package.lock` explicitly instead of fetching during `check`, `build`, `run`, or LSP requests
|
|
246
|
+
- it is currently meaningful only for cache-backed sources recorded in `package.lock`
|
|
247
|
+
- git sources can be materialized into the shared source cache
|
|
248
|
+
- registry lock entries are materialized from the local registry store into the shared source cache, and may first be mirrored from `$MILK_TEA_PACKAGE_REGISTRY_UPSTREAM` when that exact version is missing locally
|
|
249
|
+
- path-only lockfiles report that there are no cache-backed sources to materialize
|
|
250
|
+
|
|
251
|
+
Write the current resolved local package graph to `package.lock` with:
|
|
252
|
+
|
|
253
|
+
```sh
|
|
254
|
+
mtc deps lock path/to/package
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
When run inside a package directory, `mtc deps lock` also defaults to the current directory.
|
|
258
|
+
|
|
259
|
+
Verify that the checked-in lockfile is current with:
|
|
260
|
+
|
|
261
|
+
```sh
|
|
262
|
+
mtc deps lock path/to/package --check
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
`--check` exits with status `0` when `package.lock` is current, and `1` when it is missing or out of date.
|
|
266
|
+
|
|
267
|
+
For pinned git or registry dependencies, `mtc deps lock` and `mtc deps lock --check` may materialize cache-backed package sources while recomputing the expected graph. Registry dependencies may also mirror missing versions from `$MILK_TEA_PACKAGE_REGISTRY_UPSTREAM` into the local registry first.
|
|
268
|
+
|
|
269
|
+
The current lockfile records:
|
|
270
|
+
|
|
271
|
+
- the schema version
|
|
272
|
+
- the root package name
|
|
273
|
+
- the root package instance id used to identify the root node inside the locked graph
|
|
274
|
+
- each resolved package's name, kind, version when present, stable package instance id, manifest path, source root, source kind, source identity fields (`source_path` for path dependencies, `git_url` and `git_rev` plus optional `git_subdir` for git dependencies, `registry_package` and `registry_version` for registry dependencies), direct dependency names for readability, and dependency edges by package instance id
|
|
275
|
+
|
|
276
|
+
The current lockfile is generated deterministically from local `path` dependencies, pinned git dependencies, and solved registry dependencies. It is safe to regenerate; cache-backed dependency-management commands may also refresh the shared source cache while resolving manifests.
|
|
277
|
+
|
|
278
|
+
You can opt into locked dependency resolution for the current compiler path with:
|
|
279
|
+
|
|
280
|
+
```sh
|
|
281
|
+
mtc lint path/to/file.mt --locked
|
|
282
|
+
mtc check path/to/file.mt --locked
|
|
283
|
+
mtc build path/to/package --locked
|
|
284
|
+
mtc run path/to/package --locked
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
You can make those commands strict with `--frozen`, which implies `--locked` and fails when `package.lock` is missing or stale:
|
|
288
|
+
|
|
289
|
+
```sh
|
|
290
|
+
mtc lint path/to/file.mt --frozen
|
|
291
|
+
mtc check path/to/file.mt --frozen
|
|
292
|
+
mtc build path/to/package --frozen
|
|
293
|
+
mtc run path/to/package --frozen
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
Current locked-resolution scope:
|
|
297
|
+
|
|
298
|
+
- it uses `package.lock` for dependency graph resolution and direct dependency checks
|
|
299
|
+
- it resolves package imports through the exact locked dependency edge, so `package.lock` can represent transitive duplicate package namespaces safely at analysis time
|
|
300
|
+
- `--frozen` requires a current `package.lock` before compilation starts
|
|
301
|
+
- `lint` uses the locked graph for sema-backed lint rules and fix-mode semantic assistance
|
|
302
|
+
- the VS Code LSP supports `milkTea.lsp.dependencyResolution = auto|live|locked|frozen`, with `auto` using the lockfile when it is current and `frozen` surfacing stale-lock diagnostics in the editor
|
|
303
|
+
- it still reads the root package manifest for build settings such as `build.entry`, output configuration, runtime assets, and HTML templates
|
|
304
|
+
- it currently applies to path dependencies and cache-backed git or registry lock entries
|
|
305
|
+
|
|
306
|
+
Current duplicate-version behavior:
|
|
307
|
+
|
|
308
|
+
- `package.lock`, locked compiler/LSP flows, live local-path package graphs, exact registry identities, and ranged registry dependencies all resolve imports through package instances instead of flat root order, so transitive duplicate package namespaces are safe once the graph is resolved
|
|
309
|
+
- direct duplicate dependency namespaces inside a single package manifest are still invalid, because Milk Tea imports target package namespaces rather than dependency aliases
|
|
310
|
+
|
|
311
|
+
Planned registry and source-cache model:
|
|
312
|
+
|
|
313
|
+
- dependency resolution should stay split in two phases: first resolve a dependency spec to a local package root, then build the package graph from that local source tree
|
|
314
|
+
- the current code now already follows that shape internally: `PackageSourceResolver` resolves a dependency into a local source plus lockfile metadata, and `PackageGraph` only consumes the resolved local package tree
|
|
315
|
+
- cache-backed dependencies should resolve into an immutable source cache keyed by the exact resolved source identity, such as package name plus exact version or git URL plus commit hash
|
|
316
|
+
- the local registry store is now one concrete source of those identities; an optional upstream filesystem registry or static HTTP mirror can feed into it today without changing locked compiler behavior
|
|
317
|
+
- the current cache root model is `$XDG_CACHE_HOME/milk_tea/package_sources` when `XDG_CACHE_HOME` is set, otherwise `~/.cache/milk_tea/package_sources`; path dependencies bypass that shared cache
|
|
318
|
+
- cache-backed identities now also map to a deterministic materialized package root under that cache; git package roots append the configured `git_subdir`, while local path dependencies still bypass cache materialization entirely
|
|
319
|
+
- locked loading now expects cache-backed entries to be materialized already; if the cached `package.toml` is missing, loading fails fast instead of silently constructing unusable package roots
|
|
320
|
+
- `package.lock` should record that exact resolved source identity so `--locked` and `--frozen` can rebuild the graph from cached sources without re-solving or re-fetching
|
|
321
|
+
- compiler and LSP analysis should keep operating on local source roots only; fetch, update, and cache-population behavior should stay in explicit tooling commands instead of being hidden inside `check`, `build`, or editor requests
|
|
322
|
+
|
|
323
|
+
## 3. Build Commands
|
|
324
|
+
|
|
325
|
+
Build a source file:
|
|
326
|
+
|
|
327
|
+
```sh
|
|
328
|
+
mtc build path/to/app.mt
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
Build a package:
|
|
332
|
+
|
|
333
|
+
```sh
|
|
334
|
+
mtc build path/to/package
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
Run a source file or package:
|
|
338
|
+
|
|
339
|
+
```sh
|
|
340
|
+
mtc run path/to/package
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
Common options:
|
|
344
|
+
|
|
345
|
+
- `--profile debug|release`
|
|
346
|
+
- `--platform linux|windows|wasm`
|
|
347
|
+
- `--cc COMPILER`
|
|
348
|
+
- `-o OUTPUT`
|
|
349
|
+
- `--keep-c PATH`
|
|
350
|
+
- `--no-cache` — skip the build cache, force a full rebuild from source
|
|
351
|
+
- `--bundle` for native package builds when you want a distributable app directory instead of a bare executable
|
|
352
|
+
- `--archive` for native package builds when you also want a `.tar.gz` archive of the bundle; this implies `--bundle`
|
|
353
|
+
|
|
354
|
+
The wasm platform also accepts the aliases `web`, `html5`, and `browser`.
|
|
355
|
+
|
|
356
|
+
For editor tooling, the Milk Tea VS Code extension also accepts `milkTea.lsp.platform = auto|linux|windows|wasm`.
|
|
357
|
+
|
|
358
|
+
- `auto`: use the open file suffix when present, otherwise the owning package default platform, otherwise the host platform
|
|
359
|
+
- `linux|windows|wasm`: force that platform for platform-specific import resolution in the language server
|
|
360
|
+
|
|
361
|
+
## 4. Output Paths
|
|
362
|
+
|
|
363
|
+
Default package output paths are:
|
|
364
|
+
|
|
365
|
+
```text
|
|
366
|
+
build/bin/<platform>/<profile>/<package-name>
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
Default native bundle output paths are:
|
|
370
|
+
|
|
371
|
+
```text
|
|
372
|
+
build/dist/<platform>/<profile>/<package-name>/
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
The bundle directory contains the entry executable named after the package plus an `assets.mtpack` file when `build.assets` is configured.
|
|
376
|
+
|
|
377
|
+
When `--archive` is enabled, Milk Tea also writes a sibling archive file:
|
|
378
|
+
|
|
379
|
+
```text
|
|
380
|
+
build/dist/<platform>/<profile>/<package-name>.tar.gz
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
Platform-specific extensions are added automatically:
|
|
384
|
+
|
|
385
|
+
- Linux: no extension
|
|
386
|
+
- Windows: `.exe`
|
|
387
|
+
- wasm: `.html`
|
|
388
|
+
|
|
389
|
+
For direct source builds, the default output is the source path without `.mt`, except wasm builds, which default to a sibling `.html` file.
|
|
390
|
+
|
|
391
|
+
When you pass `mtc build --bundle` or `mtc build --archive` for a native package build, `-o OUTPUT` becomes the bundle directory path instead of the executable file path.
|
|
392
|
+
|
|
393
|
+
For wasm outputs:
|
|
394
|
+
|
|
395
|
+
- if the explicit output path has no extension, Milk Tea appends `.html`
|
|
396
|
+
- if the explicit output path has an extension, it must be `.html`
|
|
397
|
+
|
|
398
|
+
When targeting wasm, Milk Tea emits an Emscripten bundle next to the HTML entry point. The normal outputs are:
|
|
399
|
+
|
|
400
|
+
- `<name>.html`
|
|
401
|
+
- `<name>.js`
|
|
402
|
+
- `<name>.wasm`
|
|
403
|
+
- `<name>.data` when `build.assets` is used
|
|
404
|
+
|
|
405
|
+
When targeting linux or windows with `build.assets`, Milk Tea also stages each configured file or directory next to the output binary using its basename.
|
|
406
|
+
|
|
407
|
+
When targeting linux or windows with `--bundle`, Milk Tea writes the executable into the bundle directory and packs `build.assets` into `assets.mtpack` beside it.
|
|
408
|
+
|
|
409
|
+
When targeting linux or windows with `--archive`, Milk Tea also writes a `.tar.gz` archive of that bundle directory beside it.
|
|
410
|
+
|
|
411
|
+
Depending on Emscripten flags and debug settings, extra side files such as worker scripts, symbol files, and source maps may also be generated.
|
|
412
|
+
|
|
413
|
+
`mtc build --clean` removes generated output artifacts. For wasm that includes the HTML entry point and sidecar bundle files; for native explicit outputs it also removes staged `build.assets` entries beside the binary.
|
|
414
|
+
|
|
415
|
+
`mtc build --clean --bundle` removes native bundle output directories. For the default package output it removes `build/dist`.
|
|
416
|
+
|
|
417
|
+
`mtc build --clean --archive` removes both the native bundle directory and its `.tar.gz` archive output.
|
|
418
|
+
|
|
419
|
+
## 5. Compiler Selection
|
|
420
|
+
|
|
421
|
+
Native builds use `--cc`, then `$CC`, then `cc`.
|
|
422
|
+
|
|
423
|
+
The generated C requires a Clang/GCC-family compiler. MSVC-style backends (`cl.exe`, `clang-cl`) are rejected for native targets. This is because the C backend emits GNU-style `__attribute__((packed))` and `__attribute__((aligned(N)))` for layout-sensitive declarations such as `@[packed]` and `@[align(...)]`. On Windows, use Clang or a GCC-family toolchain such as MinGW.
|
|
424
|
+
|
|
425
|
+
Wasm builds use `--cc` when you pass it explicitly. Otherwise Milk Tea switches to `$EMCC`, falling back to `emcc`.
|
|
426
|
+
|
|
427
|
+
Because the wasm build path passes Emscripten-specific linker and shell flags, an explicit `--cc` for wasm must still resolve to `emcc` or an emcc-named wrapper.
|
|
428
|
+
|
|
429
|
+
`emcc` uses the Clang frontend, so the same GNU-style attributes are accepted for wasm/browser builds. The layout rules still apply to generated C and to compile-time queries such as `size_of`, `align_of`, and `offset_of`. The main caveat is performance: packed data can force unaligned loads and stores, and while WebAssembly supports those accesses, Emscripten documents that they can be slower on some systems. Use packed layouts for ABI, file, and network formats, not as a default for ordinary hot-path game data.
|
|
430
|
+
|
|
431
|
+
That means these two commands are equivalent when `EMCC` is configured:
|
|
432
|
+
|
|
433
|
+
```sh
|
|
434
|
+
mtc build path/to/package --platform wasm
|
|
435
|
+
mtc build path/to/package --platform wasm --cc "$EMCC"
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
## 6. Runtime Assets
|
|
439
|
+
|
|
440
|
+
Use `build.assets` to declare one runtime asset path or an array of asset paths.
|
|
441
|
+
|
|
442
|
+
```toml
|
|
443
|
+
[build]
|
|
444
|
+
entry = "src/main.mt"
|
|
445
|
+
assets = ["assets", "credits.txt"]
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
Each configured path is resolved relative to the package root and must already exist. Array entries must have distinct basenames, because Milk Tea uses that basename as the wasm mount path and the staged native filename.
|
|
449
|
+
|
|
450
|
+
For wasm targets, Milk Tea passes each path to Emscripten `--preload-file` and mounts it at `/<basename>`. For example:
|
|
451
|
+
|
|
452
|
+
- `assets = "assets"` becomes `/assets`
|
|
453
|
+
- `assets = ["assets", "credits.txt"]` also mounts `/credits.txt`
|
|
454
|
+
- runtime code can load `assets/tetris_tiles.png`
|
|
455
|
+
|
|
456
|
+
For native targets without `--bundle`, Milk Tea copies each configured file or directory next to the final executable using the same basename. For example:
|
|
457
|
+
|
|
458
|
+
- `assets = "assets"` becomes `<output-dir>/assets`
|
|
459
|
+
- `assets = "data/game.db"` becomes `<output-dir>/game.db`
|
|
460
|
+
- `assets = ["assets", "credits.txt"]` also stages `<output-dir>/credits.txt`
|
|
461
|
+
|
|
462
|
+
For native `--bundle` and `--archive` package builds, Milk Tea writes one deterministic `assets.mtpack` file into the bundle root instead of copying raw files there. The pack keeps the same logical paths you would get from each source basename. For example:
|
|
463
|
+
|
|
464
|
+
- `assets = "assets"` stores `assets/...` entries inside `<bundle-dir>/assets.mtpack`
|
|
465
|
+
- `assets = ["assets", "credits.txt"]` also stores `credits.txt` inside the same pack
|
|
466
|
+
- `std.asset_pack` is the generic MTAP reader; `std.raylib.packed_assets` wraps it with a single `rl_assets.Error` enum for raylib-facing code, including packed image, texture, wave, sound, and music loading. Apps that support both packed bundle/archive runs and unpacked dev runs can prefer `std.raylib.packed_assets.open_assets_pack_if_present()`, treat `Option.none` as the unpacked case, and fall back to `std.raylib.runtime.enter_assets_directory()` there
|
|
467
|
+
- `std.raylib.packed_assets.load_music()` returns `rl_assets.PackedMusic`, which retains the packed source bytes for the lifetime of the raylib music stream; call `music.release()` when done instead of unloading the raw `rl.Music` handle directly
|
|
468
|
+
|
|
469
|
+
`mtc run` also stages `build.assets` entries beside its temporary native binary before launch.
|
|
470
|
+
|
|
471
|
+
If you want one asset-loading path to work for both wasm and native builds, resolve assets relative to the executable location on native builds instead of relying on the caller's working directory.
|
|
472
|
+
|
|
473
|
+
For raylib-based apps, `std.raylib.runtime.enter_assets_directory()` is the standard helper for that pattern: it first tries the executable directory, then falls back to the current working directory.
|
|
474
|
+
|
|
475
|
+
Using a single top-level asset directory is still the simplest layout, but it is no longer required when a few standalone files need to ship beside it.
|
|
476
|
+
|
|
477
|
+
Current asset-pack scope:
|
|
478
|
+
|
|
479
|
+
- the MTAP container and native bundle/archive flow are in place for packaged runtime assets
|
|
480
|
+
- `std.raylib.packed_assets` currently supports packed image, texture, wave, sound, and music loading
|
|
481
|
+
- packed music uses `rl_assets.PackedMusic` so the underlying bytes remain alive for the full stream lifetime instead of being released immediately after load
|
|
482
|
+
|
|
483
|
+
## 7. Custom HTML Templates
|
|
484
|
+
|
|
485
|
+
Use `build.html_template` to provide a package-owned HTML shell for wasm output.
|
|
486
|
+
|
|
487
|
+
```toml
|
|
488
|
+
[build]
|
|
489
|
+
entry = "src/main.mt"
|
|
490
|
+
html_template = "web/shell.html"
|
|
491
|
+
```
|
|
492
|
+
|
|
493
|
+
The template path is resolved relative to the package root and must point to an existing file.
|
|
494
|
+
|
|
495
|
+
The template must contain each placeholder exactly once:
|
|
496
|
+
|
|
497
|
+
```html
|
|
498
|
+
{{{ MILK_TEA_CANVAS }}}
|
|
499
|
+
{{{ MILK_TEA_OUTPUT }}}
|
|
500
|
+
{{{ MILK_TEA_BOOTSTRAP }}}
|
|
501
|
+
{{{ SCRIPT }}}
|
|
502
|
+
```
|
|
503
|
+
|
|
504
|
+
Placeholder contract:
|
|
505
|
+
|
|
506
|
+
- `{{{ MILK_TEA_CANVAS }}}`: where the app canvas is inserted.
|
|
507
|
+
- `{{{ MILK_TEA_OUTPUT }}}`: where stdout and stderr output is rendered.
|
|
508
|
+
- `{{{ MILK_TEA_BOOTSTRAP }}}`: Milk Tea bootstrap code that wires `Module.canvas`, `print`, and `printErr`.
|
|
509
|
+
- `{{{ SCRIPT }}}`: the Emscripten loader script placeholder.
|
|
510
|
+
|
|
511
|
+
`{{{ SCRIPT }}}` is not a Milk Tea placeholder. It is required by Emscripten and must remain in the template.
|
|
512
|
+
|
|
513
|
+
If `build.html_template` is omitted, Milk Tea uses the default template in `lib/milk_tea/tooling/templates/wasm_shell.html`.
|
|
514
|
+
|
|
515
|
+
## 8. Running wasm Targets
|
|
516
|
+
|
|
517
|
+
`mtc run` behaves differently for wasm targets than for native binaries.
|
|
518
|
+
|
|
519
|
+
```sh
|
|
520
|
+
mtc run path/to/package
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
For wasm targets, Milk Tea:
|
|
524
|
+
|
|
525
|
+
- builds the HTML bundle
|
|
526
|
+
- starts a local preview server rooted at the build output directory
|
|
527
|
+
- opens the generated HTML in the default browser
|
|
528
|
+
- keeps the server in the foreground until you press `Ctrl-C`
|
|
529
|
+
|
|
530
|
+
The preview server sends the cross-origin isolation headers required by the current raylib and Web Audio worker setup.
|
|
531
|
+
|
|
532
|
+
## 9. Generated JavaScript
|
|
533
|
+
|
|
534
|
+
The `<name>.js` file in a wasm build is generated by Emscripten from the emitted C program and the final linker flags. It is not handwritten Milk Tea runtime code.
|
|
535
|
+
|
|
536
|
+
Milk Tea controls the HTML shell and the Emscripten invocation, but the JavaScript loader itself comes from Emscripten.
|