diff --git a/npm/qsharp/src/compiler/compiler.ts b/npm/qsharp/src/compiler/compiler.ts index 0775d0bb8c..806d77c988 100644 --- a/npm/qsharp/src/compiler/compiler.ts +++ b/npm/qsharp/src/compiler/compiler.ts @@ -240,6 +240,7 @@ export class Compiler implements ICompiler { eventHandler: IQscEventTarget, ): Promise { let sources; + let profile: TargetProfile = "unrestricted"; let languageFeatures: string[] = []; if (Array.isArray(sourcesOrConfig)) { @@ -249,6 +250,7 @@ export class Compiler implements ICompiler { // this is the new API sources = sourcesOrConfig.sources; languageFeatures = sourcesOrConfig.languageFeatures || []; + profile = sourcesOrConfig.profile || "unrestricted"; } // All results are communicated as events, but if there is a compiler error (e.g. an invalid // entry expression or similar), it may throw on run. The caller should expect this promise @@ -259,6 +261,7 @@ export class Compiler implements ICompiler { (msg: string) => onCompilerEvent(msg, eventHandler!), shots!, languageFeatures, + profile, ); } diff --git a/vscode/src/webviewPanel.ts b/vscode/src/webviewPanel.ts index 0e8edb839f..e68fa370a9 100644 --- a/vscode/src/webviewPanel.ts +++ b/vscode/src/webviewPanel.ts @@ -25,6 +25,7 @@ import { showDocumentationCommand } from "./documentation"; import { loadProject } from "./projectSystem"; import { EventType, sendTelemetryEvent } from "./telemetry"; import { getRandomGuid } from "./utils"; +import { getTarget } from "./config"; const QSharpWebViewType = "qsharp-webview"; const compilerRunTimeoutMs = 1000 * 60 * 5; // 5 minutes @@ -359,6 +360,7 @@ export function registerWebViewCommands(context: ExtensionContext) { const config = { sources, languageFeatures, + profile: getTarget(), }; await worker.run(config, "", parseInt(numberOfShots), evtTarget); sendTelemetryEvent( diff --git a/wasm/src/lib.rs b/wasm/src/lib.rs index 3ff8dfcd39..5902262353 100644 --- a/wasm/src/lib.rs +++ b/wasm/src/lib.rs @@ -296,6 +296,7 @@ fn run_internal_with_features( event_cb: F, shots: u32, language_features: LanguageFeatures, + capabilities: TargetCapabilityFlags, ) -> Result<(), Box> where F: FnMut(&str), @@ -311,7 +312,7 @@ where true, sources, PackageType::Exe, - Profile::Unrestricted.into(), + capabilities, language_features, ) { Ok(interpreter) => interpreter, @@ -353,6 +354,7 @@ pub fn run( event_cb: &js_sys::Function, shots: u32, language_features: Vec, + profile: &str, ) -> Result { if !event_cb.is_function() { return Err(JsError::new("Events callback function must be provided").into()); @@ -365,7 +367,15 @@ pub fn run( // See example at https://rustwasm.github.io/wasm-bindgen/reference/receiving-js-closures-in-rust.html let _ = event_cb.call1(&JsValue::null(), &JsValue::from(msg)); }; - match run_internal_with_features(sources, event_cb, shots, language_features) { + match run_internal_with_features( + sources, + event_cb, + shots, + language_features, + Profile::from_str(profile) + .map_err(|()| format!("Invalid target profile {profile}"))? + .into(), + ) { Ok(()) => Ok(true), Err(e) => Err(JsError::from(e).into()), } diff --git a/wasm/src/tests.rs b/wasm/src/tests.rs index 72de1ef808..c26c9cf926 100644 --- a/wasm/src/tests.rs +++ b/wasm/src/tests.rs @@ -13,7 +13,13 @@ fn run_internal(sources: SourceMap, event_cb: F, shots: u32) -> Result<(), Bo where F: FnMut(&str), { - run_internal_with_features(sources, event_cb, shots, LanguageFeatures::default()) + run_internal_with_features( + sources, + event_cb, + shots, + LanguageFeatures::default(), + TargetCapabilityFlags::all(), + ) } #[test]