Skip to content
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

[native_assets_cli] Introduce CCompilerConfig.windows #1913

Merged
merged 7 commits into from
Jan 21, 2025

Conversation

dcharkes
Copy link
Collaborator

@dcharkes dcharkes commented Jan 20, 2025

Closes: #1606

This PR moves cCompilerConfig.envScript to cCompilerConfig.windows.developerCommandPrompt.script.

Notable changes:

  • The DeveloperCommandPrompt is optional, but if it's set, both the script and arguments must be set. Since clang on Windows detects the MSVC installations, the developerCommandPrompt itself is optional for the case where clang is passed as the compiler on Windows
  • The OS-specific configurations nested under CodeConfig have been renamed to <OS>CodeConfig avoid naming conflicts with <OS>CCompilerConfig.
  • The JSON structure has been updated with the nesting.

Up for discussion:

  • Naming (developerCommandPrompt is rather long)
  • Should we expose a Future<Map<String, String>> loadEnvironment() on DeveloperCommandPrompt? It's a bit out of place because the config is rather only a view on the JSON. However, it is most likely use case.

Copy link

PR Health

Breaking changes ✔️
Package Change Current Version New Version Needed Version Looking good?
Changelog Entry ✔️
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

API leaks ✔️

The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.

Package Leaked API symbols
License Headers ✔️
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
Files
no missing headers

All source files should start with a license header.

Unrelated files missing license headers
Files
pkgs/jni/lib/src/third_party/generated_bindings.dart
pkgs/objective_c/lib/src/ns_input_stream.dart

@coveralls
Copy link

coveralls commented Jan 20, 2025

Coverage Status

coverage: 91.19% (-0.05%) from 91.24%
when pulling a9ef15a on windows-dev-env
into d1d9aa5 on main.

@dcharkes dcharkes requested a review from mkustermann January 20, 2025 14:34
@dcharkes dcharkes marked this pull request as ready for review January 20, 2025 14:43
@dcharkes dcharkes requested a review from mosuem January 21, 2025 10:28

/// The json representation of this [CCompilerConfig].
///
/// The returned json can be used in [CCompilerConfig.fromJson] to
/// obtain a [CCompilerConfig] again.
Map<String, Object> toJson() => {
Map<String, Object> toJson({bool deprecatedTopLevel = false}) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation on this parameter is missing


/// Configuration provided when [CodeConfig.targetOS] is [OS.windows].
final class WindowsCCompilerConfig {
final DeveloperCommandPrompt? developerCommandPrompt;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I don't think the name is too long

/// The Windows Developer Command Prompt.
///
/// Sets up the environment variables for [CCompilerConfig.compiler],
/// [CCompilerConfig.linker], and [CCompilerConfig.archiver].
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// [CCompilerConfig.linker], and [CCompilerConfig.archiver].
/// [CCompilerConfig.linker], and [CCompilerConfig.archiver] on Windows.

@auto-submit auto-submit bot merged commit aa9994b into main Jan 21, 2025
41 checks passed
@auto-submit auto-submit bot deleted the windows-dev-env branch January 21, 2025 14:13
auto-submit bot pushed a commit that referenced this pull request Mar 26, 2025
Closes: #1826

This PR adds the final step to the generated syntax validation: conditionally required fields:

1. If target OS is `x`, then require `x` config in code config.
2. If target OS is `windows`, then require `windows` in the c compiler config (more info #1913).
3. If link mode is dynamic library bundled or static library, then require a file in a code asset.

We could consider trying to nest the fields under the condition, but that has other downsides:

RE 1: Then the OS is no longer an enum usable in the code-asset as OS field. (We could consider this if we remove the OS/arch from code asset outputs. We should be able to do this due to the code config always having a single OS and architecture anyway. #2127)
RE 2: That would mean the compiler config would be split over two places. `input.config.code.cCompiler` and `inputconfig.code.windows.cCompiler`. Maybe that's better? Maybe not?
RE 3: Treating a group of files in assets would then become `input.assets.code.switch( ... )` instead of simply `input.assets.code.map((a) => a.file)`. Maybe that's okay because we don't often use files in such way anyway?

WDYT @mosuem @HosseinYousefi?

(I'd probably do any of those refactorings in follow up PRs.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove CCompiler.{envScript,envScriptArgs} and replace by other means
3 participants