Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/typespec-rust/.scripts/tspcompile.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ function should_generate(name) {
return true
}

// When https://github.com/Azure/typespec-azure/pull/3950 is merged, and we use the newer version of @azure-tools/azure-http-specs,
// we can remove alternate_types from below, add it to azureHttpSpecsGroup above, and remove the checked-in tsp files
// from packages\typespec-rust\test\spector\azure\client-generator-core\alternate-type\.
const alternate_types = pkgRoot + 'test/tsp/AlternateTypes';
generate('alternate_types', alternate_types, 'test/other/alternate_types');

Expand Down Expand Up @@ -190,6 +193,9 @@ generate('pub_crate', pub_crate, 'test/other/pub_crate');
const client_option = pkgRoot + 'test/tsp/ClientOption';
generate('client_option', client_option, 'test/other/client_option');

const spector_alternatetype = pkgRoot + 'test/spector/azure/client-generator-core/alternate-type/client.tsp';
generate('spector_alternatetype', spector_alternatetype, 'test/spector/azure/client-generator-core/alternate-type');

loopSpec(httpSpecsGroup, httpSpecs)
loopSpec(azureHttpSpecsGroup, azureHttpSpecs)

Expand Down
2 changes: 1 addition & 1 deletion packages/typespec-rust/src/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function $onEmit(context: EmitContext<RustEmitterOptions>) {
let failed = false;
try {
const adapter = await Adapter.create(context);
const crate = adapter.tcgcToCrate();
const crate = adapter.tcgcToCrate(context);

await mkdir(`${context.emitterOutputDir}/src`, { recursive: true });

Expand Down
16 changes: 12 additions & 4 deletions packages/typespec-rust/src/tcgcadapter/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import * as utils from '../utils/utils.js';
import * as tcgc from '@azure-tools/typespec-client-generator-core';
import * as rust from '../codemodel/index.js';
import {FinalStateValue} from "@azure-tools/typespec-azure-core";
import {EmitContext, NoTarget} from "@typespec/compiler";

/** ErrorCode defines the types of adapter errors */
export type ErrorCode =
Expand Down Expand Up @@ -114,8 +115,8 @@ export class Adapter {
}

/** performs all the steps to convert tcgc to a crate */
tcgcToCrate(): rust.Crate {
this.adaptTypes();
tcgcToCrate(context: EmitContext<RustEmitterOptions>): rust.Crate {
this.adaptTypes(context);
this.adaptClients();

// marker models don't require serde so exclude them from the check
Expand Down Expand Up @@ -146,10 +147,17 @@ export class Adapter {
}

/** converts all tcgc types to their Rust type equivalent */
private adaptTypes(): void {
private adaptTypes(context: EmitContext<RustEmitterOptions>): void {
for (const sdkUnion of this.ctx.sdkPackage.unions.filter(u => u.kind === 'union')) {
if (!sdkUnion.discriminatedOptions) {
throw new AdapterError('UnsupportedTsp', 'non-discriminated unions are not supported', sdkUnion.__raw?.node);
// When https://github.com/microsoft/typespec/issues/9749 is fixed, we can return to throwing an exception here.
context.program.reportDiagnostic({
code: 'UnsupportedTsp',
severity: 'warning',
message: `Non-discriminated unions ('${sdkUnion.name}') are not supported. No type will be generated.`,
target: NoTarget,
})
continue;
}
const rustUnion = this.getDiscriminatedUnion(sdkUnion);
this.crate.unions.push(rustUnion);
Expand Down
Loading