Only apply subsystem to final binary, not cdylibs (#5002)

This commit is contained in:
Evan Almloff authored and GitHub committed 2025-11-21 10:12:49 -08:00
1 parent 75d9ece3af
commit 84efc00757
10 files changed
+177 -60

No files matched your search

+21 -21
View File
@@ -400,6 +400,7 @@ pub(crate) struct BuildRequest {
pub(crate) apple_team_id: Option<String>,
pub(crate) session_cache_dir: PathBuf,
pub(crate) raw_json_diagnostics: bool,
pub(crate) windows_subsystem: Option<String>,
}
/// dx can produce different "modes" of a build. A "regular" build is a "base" build. The Fat and Thin
@@ -909,27 +910,6 @@ impl BuildRequest {
]);
}
// On windows, we pass /SUBSYSTEM:WINDOWS to prevent a console from appearing
if matches!(bundle, BundleFormat::Windows)
&& !rustflags
.flags
.iter()
.any(|f| f.starts_with("-Clink-arg=/SUBSYSTEM:"))
{
let subsystem = args
.windows_subsystem
.clone()
.unwrap_or_else(|| "WINDOWS".to_string());
rustflags
.flags
.push(format!("-Clink-arg=/SUBSYSTEM:{}", subsystem));
// We also need to set the entry point to mainCRTStartup to avoid windows looking
// for a WinMain function
rustflags
.flags
.push("-Clink-arg=/ENTRY:mainCRTStartup".to_string());
}
// Make sure we set the sysroot for ios builds in the event the user doesn't have it set
if matches!(bundle, BundleFormat::Ios) {
let xcode_path = Workspace::get_xcode_path()
@@ -1040,6 +1020,7 @@ impl BuildRequest {
apple_entitlements: args.apple_entitlements.clone(),
apple_team_id: args.apple_team_id.clone(),
raw_json_diagnostics: args.raw_json_diagnostics,
windows_subsystem: args.windows_subsystem.clone(),
})
}
@@ -2673,6 +2654,25 @@ impl BuildRequest {
cargo_args.push("--".to_string());
cargo_args.extend(self.extra_rustc_args.clone());
// On windows, we pass /SUBSYSTEM:WINDOWS to prevent a console from appearing
if matches!(self.bundle, BundleFormat::Windows)
&& !self
.rustflags
.flags
.iter()
.any(|f| f.starts_with("-Clink-arg=/SUBSYSTEM:"))
{
let subsystem = self
.windows_subsystem
.clone()
.unwrap_or_else(|| "WINDOWS".to_string());
cargo_args.push(format!("-Clink-arg=/SUBSYSTEM:{}", subsystem));
// We also need to set the entry point to mainCRTStartup to avoid windows looking
// for a WinMain function
cargo_args.push("-Clink-arg=/ENTRY:mainCRTStartup".to_string());
}
// The bundle splitter needs relocation data to create a call-graph.
// This will automatically be erased by wasm-opt during the optimization step.
if self.bundle == BundleFormat::Web && self.wasm_split {
+8
View File
@@ -67,6 +67,7 @@ pub struct Config {
pub(crate) window_close_behavior: WindowCloseBehaviour,
pub(crate) custom_event_handler: Option<CustomEventHandler>,
pub(crate) disable_file_drop_handler: bool,
pub(crate) additional_windows_args: Option<String>,
#[allow(clippy::type_complexity)]
pub(crate) on_window: Option<Box<dyn FnMut(Arc<Window>, &mut VirtualDom) + 'static>>,
@@ -118,6 +119,7 @@ impl Config {
custom_event_handler: None,
disable_file_drop_handler: false,
on_window: None,
additional_windows_args: None,
}
}
@@ -312,6 +314,12 @@ impl Config {
self.on_window = Some(Box::new(f));
self
}
/// Add additional windows only launch arguments for webview2
pub fn with_windows_browser_args(mut self, additional_args: impl ToString) -> Self {
self.additional_windows_args = Some(additional_args.to_string());
self
}
}
impl Default for Config {
+8
View File
@@ -442,6 +442,14 @@ impl WebviewInstance {
None
};
#[cfg(target_os = "windows")]
{
use wry::WebViewBuilderExtWindows;
if let Some(additional_windows_args) = &cfg.additional_windows_args {
webview = webview.with_additional_browser_args(additional_windows_args);
}
}
#[cfg(any(
target_os = "windows",
target_os = "macos",
+60 -36
View File
@@ -8,44 +8,24 @@ const path = require("path");
*/
// require('dotenv').config();
/**
* @see https://playwright.dev/docs/test-configuration
*/
module.exports = defineConfig({
testDir: ".",
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: "html",
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://127.0.0.1:3000',
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: "retain-on-failure",
// Increase the timeout for navigations to give dx time to build the project
navigationTimeout: 50 * 60 * 1000,
},
timeout: 50 * 60 * 1000,
/* Configure projects for major browsers */
projects: [
let webServer = [];
let grep = undefined;
let grepInvert = undefined;
if (process.platform === "win32") {
webServer = [
{
name: "chromium",
use: { ...devices["Desktop Chrome"] },
cwd: path.join(process.cwd(), "windows-headless"),
command:
"cargo run --package dioxus-cli --release -- run --force-sequential",
port: 8787,
timeout: 50 * 60 * 1000,
reuseExistingServer: !process.env.CI,
stdout: "pipe",
},
],
/* Run your local dev server before starting the tests */
webServer: [
];
grep = /windows/;
} else {
webServer = [
{
command:
"cargo run --package dioxus-playwright-liveview-test --bin dioxus-playwright-liveview-test",
@@ -224,5 +204,49 @@ module.exports = defineConfig({
reuseExistingServer: !process.env.CI,
stdout: "pipe",
},
];
grepInvert = /windows/;
}
/**
* @see https://playwright.dev/docs/test-configuration
*/
module.exports = defineConfig({
testDir: ".",
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: "html",
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://127.0.0.1:3000',
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: "retain-on-failure",
// Increase the timeout for navigations to give dx time to build the project
navigationTimeout: 50 * 60 * 1000,
},
timeout: 50 * 60 * 1000,
/* Configure projects for major browsers */
projects: [
{
name: "chromium",
grep,
grepInvert,
use: { ...devices["Desktop Chrome"] },
},
],
/* Run your local dev server before starting the tests */
webServer,
});
@@ -0,0 +1,7 @@
[package]
name = "windows-headless"
edition = "2024"
version.workspace = true
[dependencies]
dioxus = { workspace = true, features = ["desktop"] }
@@ -0,0 +1,23 @@
use dioxus::LaunchBuilder;
use dioxus::prelude::*;
fn main() {
LaunchBuilder::new()
.with_cfg(
dioxus::desktop::Config::new()
.with_windows_browser_args("--remote-debugging-port=8787"),
)
.launch(app);
}
fn app() -> Element {
let mut count = use_signal(|| 0);
rsx! {
h1 { "High-five counter: {count}" }
button {
id: "increment-button",
onclick: move |_| count += 1, "Up high!"
}
}
}
+37
View File
@@ -0,0 +1,37 @@
const { expect, defineConfig } = require("@playwright/test");
import { test as base } from '@playwright/test';
import fs from 'fs';
import os from 'os';
import path from 'path';
import childProcess from 'child_process';
export const test = base.extend({
browser: async ({ playwright }, use, testInfo) => {
const browser = await playwright.chromium.connectOverCDP(`http://127.0.0.1:8787`);
await use(browser);
await browser.close();
},
context: async ({ browser }, use) => {
const context = browser.contexts()[0];
await use(context);
},
page: async ({ context }, use) => {
const page = context.pages()[0];
await use(page);
},
});
test("button click", async ({ page }) => {
// Expect the page to contain the counter text.
const main = page.locator("#main");
await expect(main).toContainText("High-five counter: 0");
// Click the increment button.
let button = page.locator("button#increment-button");
await button.click();
// Expect the page to contain the updated counter text.
await expect(main).toContainText("High-five counter: 1");
});