-
Notifications
You must be signed in to change notification settings - Fork 46
Phase 2C: generate the SDK wire types from a Rust emitter #559
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MGudgin
wants to merge
1
commit into
user/gudge/versioning_phase2b
Choose a base branch
from
user/gudge/versioning_phase2c_optC_rustemit
base: user/gudge/versioning_phase2b
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
250 changes: 0 additions & 250 deletions
250
schemas/stable/mxc-config.schema.0.5.0-alpha-strict.json
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| #!/usr/bin/env node | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| // SDK wire-types codegen gate (Phase 2C, option C): the committed | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: we should probably remove mentions of the phases and options from the comments. |
||
| // `sdk/src/generated/wire.ts` must be identical (modulo line endings) to the | ||
| // output of the Rust TypeScript emitter (`mxc_schema_gen --ts`), so the SDK's | ||
| // drift oracle can never go stale relative to the Rust wire model. Unlike | ||
| // options A/B, this uses NO third-party generator — the emitter lives in | ||
| // `wxc_common::ts_emit`. | ||
| // | ||
| // Mirrors `check-schema-codegen.js`. Run from anywhere: | ||
| // node scripts/versioning/check-sdk-types-codegen.js | ||
|
|
||
| const { readFileSync, mkdtempSync, rmSync } = require("fs"); | ||
| const { join } = require("path"); | ||
| const os = require("os"); | ||
| const { execFileSync } = require("child_process"); | ||
|
|
||
| const repoRoot = join(__dirname, "..", ".."); | ||
| const committedPath = join(repoRoot, "sdk", "src", "generated", "wire.ts"); | ||
|
|
||
| function fail(msg) { | ||
| console.error("SDK wire-types codegen check FAILED:"); | ||
| console.error(" - " + msg); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| let committed; | ||
| try { | ||
| committed = readFileSync(committedPath, "utf8"); | ||
| } catch (e) { | ||
| fail(`could not read committed ${committedPath}: ${e.message}`); | ||
| } | ||
|
|
||
| const tmpDir = mkdtempSync(join(os.tmpdir(), "mxc-ts-emit-")); | ||
| const tmpOut = join(tmpDir, "wire.ts"); | ||
| try { | ||
| // Build + run the emitter. Quiet so only our diagnostics surface. | ||
| execFileSync( | ||
| "cargo", | ||
| ["run", "-q", "-p", "mxc_schema_gen", "--", "--ts", tmpOut], | ||
| { cwd: join(repoRoot, "src"), stdio: ["ignore", "ignore", "inherit"] } | ||
| ); | ||
| const generated = readFileSync(tmpOut, "utf8"); | ||
|
|
||
| // Compare modulo line endings: the file is committed with LF, but a Windows | ||
| // checkout with core.autocrlf=true has CRLF in the working tree. The emitter | ||
| // always writes LF. | ||
| const normalize = (s) => s.replace(/\r\n/g, "\n"); | ||
| if (normalize(generated) !== normalize(committed)) { | ||
| const g = normalize(generated).split("\n"); | ||
| const c = normalize(committed).split("\n"); | ||
| let line = 0; | ||
| while (line < g.length && line < c.length && g[line] === c[line]) line++; | ||
| fail( | ||
| `committed SDK wire types are stale at ${committedPath}.\n` + | ||
| ` First difference at line ${line + 1}:\n` + | ||
| ` committed: ${JSON.stringify(c[line])}\n` + | ||
| ` generated: ${JSON.stringify(g[line])}\n` + | ||
| ` Regenerate with (from the repo root; the Cargo workspace is in src/):\n` + | ||
| ` cargo run --manifest-path src/Cargo.toml -p mxc_schema_gen -- --ts sdk/src/generated/wire.ts` | ||
| ); | ||
| } | ||
| } finally { | ||
| rmSync(tmpDir, { recursive: true, force: true }); | ||
| } | ||
|
|
||
| console.log( | ||
| "SDK wire-types codegen OK: committed sdk/src/generated/wire.ts matches the Rust emitter output." | ||
| ); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: I'm still wondering why we can't have a third party generator? Wouldn't that ease our maintenance burden here? To be honest thinking about it, it makes a lot of sense if the types we expose in type script are generated from the wire rust code. I'm trying to think of a reason why we wouldn't want to do that but can't. Would be great if us devs only need to run a script to update the typescript types and then check in the changes.
side note: I wonder if we should have just used flatbuffers for our schema. It allows json conversion between the flatbuffer schema and json. Just wondering since that would have done the work for us in generating both rust types and typescript types without us making anything new.