urust: added #resource match pattern, can now pass --board

This commit is contained in:
Steven Hugg committed 2026-10-20 20:08:22 +02:00
1 parent 6c37941024
commit e0171ea2c1
5 files changed
+27 -3

No files matched your search

+7 -1
View File
@@ -171,9 +171,14 @@ export interface ToolMeta {
//// shared dependency-parsing patterns (from src/ide/project.ts)
// C / most assemblers: [.#%]?include|incbin|embed "file", //#resource "file"
// The resource form is also useful to tools whose own include syntax has no
// way to name a non-source file (e.g. urust's custom board TOML).
export const SHARED_RESOURCE_PATTERNS: RegExp[] = [
/^\s*([;']|[/][/])#(resource)\s+"(.+?)"/gm,
];
export const SHARED_INCLUDE_PATTERNS: RegExp[] = [
/^\s*[.#%]?(include|incbin|embed)\s+"(.+?)"/gmi,
/^\s*([;']|[/][/])#(resource)\s+"(.+?)"/gm,
...SHARED_RESOURCE_PATTERNS,
];
// dasm accepts include/incbin file names without quotes as well as quoted
@@ -265,6 +270,7 @@ const URUST_MOD_PATTERN = /^\s*(?:pub(?:\([^)]*\))?\s+)?mod\s+([A-Za-z_][A-Za-z0
const URUST_RS8_MODULE_PATTERN = /\brs8::(atari8|c64|conio|io|nes|rand|vcs)\b/g;
export const URUST_INCLUDE_PATTERNS: (RegExp | ToolIncludePattern)[] = [
/\binclude_(?:bytes|str)!\s*\(\s*"(.+?)"\s*\)/g,
...SHARED_RESOURCE_PATTERNS,
{ re: URUST_MOD_PATTERN, suffix: '.rs' },
{ re: URUST_MOD_PATTERN, suffix: '/mod.rs' },
{ re: URUST_RS8_MODULE_PATTERN, suffix: '.rs' },
+2 -1
View File
@@ -21,12 +21,12 @@ export function getToolForFilename_6502(fn: string): string {
if (fn.endsWith(".bb")) return "bataribasic";
if (fn.endsWith(".acme")) return "acme";
if (fn.endsWith(".xa")) return "xa";
if (fn.endsWith(".rs")) return "urust";
if (fn.endsWith(".wiz")) return "wiz";
if (fn.endsWith(".ecs")) return "ecs";
if (fn.endsWith(".cpp")) return "oscar64";
if (fn.endsWith(".cc")) return "oscar64";
if (fn.endsWith(".o64")) return "oscar64";
if (fn.endsWith(".rs")) return "urust";
return "dasm"; // .a
}
@@ -39,6 +39,7 @@ export function getToolForFilename_z80(fn: string): string {
if (fn.endsWith(".scc")) return "sccz80";
if (fn.endsWith(".z")) return "zmac";
if (fn.endsWith(".wiz")) return "wiz";
if (fn.endsWith(".rs")) return "urust";
return "zmac";
}
+8
View File
@@ -128,6 +128,14 @@ Passes arguments straight to one tool phase, with no interpretation:
Arguments may be quoted with single or double quotes when they contain
spaces. This is an escape hatch that the build system cannot validate.
If a flag names a file (for example urust's custom board), also list that
file as a resource so the IDE and CLI copy it into the build filesystem:
~~~rust
//#resource "vicdual.toml"
//#flag c --board vicdual.toml
~~~
### `//#tooldef` — set a typed build parameter
Sets a named build parameter that the build system understands:
+5 -1
View File
@@ -26,12 +26,16 @@ export function compileUrust(step: BuildStep): BuildStepResult {
const wasi = new WASIRunner();
wasi.initSync(wasiModule);
populateWASIFiles(wasi, step);
const args = ['urust', 'build', step.path, '--platform', platform, '--emit', 'bin', '-o', binpath,
let args = ['urust', 'build', step.path, '--emit', 'bin', '-o', binpath,
'-O1', '-fno-bounds-checks',
'-Wall',
'--auto-mod',
'--debug-out', dbgpath, '--error-format', 'json'];
args.push.apply(args, extraArgsFor('urust', step.params && step.params.buildArgs));
// TODO: put board in toolmeta?
if (!args.includes('--board') && !args.includes('--platform')) {
args.push.apply(args, ['--platform', platform]);
}
wasi.setArgs(args);
const trapped: WorkerError[] = [];
runWASI(wasi, trapped);
+5
View File
@@ -21,6 +21,11 @@ describe('urust tool', function () {
assert.deepStrictEqual(deps, ['art/a.bin', 't.txt', 'x']);
});
it('scans //#resource files as dependencies', function () {
const src = '//#resource "vicdual.toml"\n//#flag c --board vicdual.toml\nfn main() {}\n';
assert.deepStrictEqual(matchDependencyPatterns(src, getIncludePatterns('urust')), ['vicdual.toml']);
});
it('scans mod/use as module dependencies', function () {
const src = 'mod audio;\npub mod bcd;\n' +
'use audio::{music_play, SND_COIN};\nuse bcd::bcd_add;\nuse rs8::reset;\n';