Skip to content

fix: force C++17 for native module compilation in all CI workflows#592

Merged
cute-omega merged 2 commits intomasterfrom
copilot/fix-cpp17-build-issues
Apr 12, 2026
Merged

fix: force C++17 for native module compilation in all CI workflows#592
cute-omega merged 2 commits intomasterfrom
copilot/fix-cpp17-build-issues

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 12, 2026

@parcel/[email protected] uses std::optional, requiring C++17. CI runners default to an older standard, causing pnpm install to fail during native compilation.

Changes

  • All three workflows (test-and-upload.yml, build-and-release.yml, npm-run-electron.yml): inject compiler flags into GITHUB_ENV immediately before pnpm install:
    • Linux/macOS: CXXFLAGS=-std=c++17, CFLAGS=-std=c11 (GCC/Clang)
    • Windows: CL=/std:c++17 (MSVC)
  • .npmrc: added comments documenting the C++17 requirement for local builds
- name: "Set C++17 compiler flags (Linux / macOS)"
  if: ${{ matrix.os != 'windows' }}
  run: |
    echo "CXXFLAGS=-std=c++17" >> $GITHUB_ENV
    echo "CFLAGS=-std=c11" >> $GITHUB_ENV

- name: "Set C++17 compiler flags (Windows)"
  if: ${{ matrix.os == 'windows' }}
  run: |
    echo "CL=/std:c++17" >> $env:GITHUB_ENV
Original prompt

Create a PR in docmirror/dev-sidecar that fixes the failing GitHub Actions job (run 24313326100, job 70986644673). The failure occurs during pnpm install when @parcel/[email protected] is compiled and errors because std::optional requires C++17; the build is using an older C++ standard.

Goals:

  1. Ensure node-gyp/make builds native deps with C++17 on all systems (Linux, macOS, Windows) in CI.
  2. Do not limit the fix only to .github/workflows/test-and-upload.yml; update any other relevant CI/workflow/config files in the repo so that native module compilation consistently uses C++17 across environments.
  3. Prefer a robust approach that affects node-gyp builds (e.g., CXXFLAGS/CFLAGS on Unix, and MSVC flags on Windows via appropriate env vars such as CL=/std:c++17 or npm config variables), and verify it doesn’t break existing steps.
  4. Add/update documentation or project config (e.g., .npmrc, .yarnrc, package.json scripts, repo build docs) if needed so local builds are consistent or at least the rationale is captured.

Context:

  • Workflow file at commit 865e125: .github/workflows/test-and-upload.yml
  • The job log shows the compilation error: std::optional only available from C++17 onwards.

Acceptance criteria:

  • CI sets appropriate compiler flags for C++17 for native builds on Ubuntu/macOS and Windows.
  • Any other workflows that run pnpm install / electron-builder install-app-deps are updated similarly.
  • The PR includes concise explanation in the description/commit message.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: Please find a solution for this failing job. Use the logs, job definition, and any referenced files where the failure occurred. Keep your response focused on the solution and include code suggestions when appropriate.

Assistant: The job is failing during pnpm install when a native dependency (@parcel/[email protected]) is compiled as part of packages/gui’s postinstall (via electron-builder install-app-deps / @electron/rebuild). The compiler error is:

  • error: ‘optional’ in namespace ‘std’ does not name a template type
  • note: ‘std::optional’ is only available from C++17 onwards

That means the runner is using a C++ toolchain defaulting to < C++17, so the native build fails.

Fix (recommended): force C++17 on Linux/macOS builds

Add environment variables so node-gyp/make compile with C++17. Update .github/workflows/test-and-upload.yml to set these flags (globally or at least for non-Windows jobs).

Example (global in the job env:):

jobs:
  test-and-upload:
    runs-on: ${{ matrix.os }}-latest
    env:
      ELECTRON_CACHE: ${{ github.workspace }}/.cache/electron
      ELECTRON_BUILDER_CACHE: ${{ github.workspace }}/.cache/electron-builder
      CXXFLAGS: "-std=c++17"
      CFLAGS: "-std=c11"

If you prefer to scope it to Linux/macOS only:

- name: Set C++17 flags (non-Windows)
  if: ${{ matrix.os != 'windows' }}
  run: |
    echo "CXXFLAGS=-std=c++17" >> $GITHUB_ENV
    echo "CFLAGS=-std=c11" >> $GITHUB_ENV

This addresses the exact std::optional failure shown in the logs.

Alternative fix: pin Node to an LTS version known to have good prebuild coverage

Your matrix uses Node 22. Some native packages are slower to publish prebuilt binaries for the newest Node versions, which increases the chance you’ll compile from source (and hit toolchain issues). Consider switching the matrix to Node 20 (or 18) unless Node 22 is required:

strategy:
  matrix:
    os: [windows, ubuntu, macos]
    node: [20]

You can also keep 22 for one lane and run 20 for release builds.

Why this works

The failing compilation unit (@parcel/watcher sources) requires C++17 (std::optional). Forcing -std=c++17 ensures the native build uses the needed standard even if the runner’s default is older, unblocking pnpm install and everything after it (electron:build, artifact rename/upload).

User: Add environment variables so node-gyp/make compile with C++17 for all systems. Make a new pull request for it. You should edit all relative files, not only test-and-upload.yml

Assistant: I’ve kicked off the pull-request creation workflow for docmirror/dev-sidecar, and we’re now waiting on your confirmation in the dialog before I can proceed with the repository edits and open the PR.

This pull request was created from Copilot chat.

@parcel/[email protected] uses std::optional which requires C++17. Without
explicit flags node-gyp defaults to an older standard and the build
fails. Fix by writing the appropriate flags to GITHUB_ENV before
pnpm install runs in every workflow:
- Linux/macOS: CXXFLAGS=-std=c++17, CFLAGS=-std=c11 (GCC/Clang)
- Windows:     CL=/std:c++17 (MSVC)

All three workflow files (test-and-upload, build-and-release,
npm-run-electron) are updated. .npmrc is annotated with the requirement
so local developers know what to export when building native deps.

Agent-Logs-Url: https://github.com/docmirror/dev-sidecar/sessions/ff93a323-112d-4413-8665-e7393d39479f

Co-authored-by: cute-omega <[email protected]>
Copilot AI changed the title [WIP] Fix failing GitHub Actions job due to C++17 requirement fix: force C++17 for native module compilation in all CI workflows Apr 12, 2026
Copilot AI requested a review from cute-omega April 12, 2026 18:41
@cute-omega
Copy link
Copy Markdown
Collaborator

cute-omega commented Apr 12, 2026

c++ 17已正确启用,报错是因为flatpak打包失败。本问题应视为已解决。

如果不强制合并该PR,则PR #593 修复flatpak的PR也不能成功

@cute-omega cute-omega marked this pull request as ready for review April 12, 2026 18:56
Copilot AI review requested due to automatic review settings April 12, 2026 18:56
@cute-omega cute-omega merged commit f69b9c9 into master Apr 12, 2026
4 of 5 checks passed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses CI failures when compiling native Node dependencies (notably @parcel/[email protected]) by ensuring the compiler uses the C++17 standard across all GitHub Actions workflows that run pnpm install.

Changes:

  • Add a pre-install step in all relevant workflows to set C++17 flags for native compilation (Unix: CXXFLAGS=-std=c++17; Windows: CL=/std:c++17).
  • Add .npmrc comments documenting why C++17 is required and how CI enforces it.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
.npmrc Documents the C++17 requirement for native modules and notes how CI sets flags.
.github/workflows/test-and-upload.yml Sets C++17 flags immediately before pnpm install for all OSes in the matrix.
.github/workflows/npm-run-electron.yml Sets C++17 flags immediately before pnpm install for all OSes in the matrix.
.github/workflows/build-and-release.yml Sets C++17 flags immediately before pnpm install for all OSes in the matrix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@cute-omega cute-omega deleted the copilot/fix-cpp17-build-issues branch April 12, 2026 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants