Skip to content

fix: check Linux system deps before native rebuild - #5134

Closed
rkristelijn wants to merge 2 commits into
marktext:developfrom
rkristelijn:fix/postinstall-dep-check
Closed

rkristelijn wants to merge 2 commits into
marktext:developfrom
rkristelijn:fix/postinstall-dep-check

Conversation

@rkristelijn

Copy link
Copy Markdown
Contributor

Closes #5133

Summary

pnpm install on Linux fails with a cryptic node-gyp error when system dependencies (libx11-dev, libxkbfile-dev, libsecret-1-dev) are missing. This PR adds a clear pre-flight check.

Changes

  • scripts/postinstall.ts: Added a Linux-only check (step 0) that verifies required system packages via dpkg -s before attempting the native rebuild. On failure, prints the exact apt-get install command needed.
  • Makefile: Added for dev workflow convenience (make deps, make install, make dev, make build). Happy to discuss whether this belongs in the project.

Testing

  • Verified on Linux Mint 22.3 with Node v24.15.0 and pnpm 10.33.4
  • Without deps: clear error message with install instructions
  • With deps: postinstall completes successfully

- Add pre-flight check in postinstall.ts for libx11-dev, libxkbfile-dev,
  libsecret-1-dev, pkg-config on Linux (dpkg-based distros)
- Clear error message with exact apt-get command on failure
- Add Makefile for dev workflow shortcuts (deps, install, dev, build)

@Jocs Jocs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for picking this up — the cryptic node-gyp error is a real papercut. But the check as written blocks installs that would succeed, which is why CI is red.

1. CI failure: build-essential is a meta-package the GitHub runner doesn't have (blocking)

Both PR Build (linux) and E2E Test fail in Run postinstall:

✖ Missing system dependencies: build-essential

ubuntu-latest ships gcc/g++/make but not the build-essential meta-package, so dpkg -s build-essential fails and the script exits 1 before electron-rebuild — which passes on the same runner in every other PR. Any Debian/Ubuntu machine whose toolchain was installed piecemeal hits the same false failure. website-deploy.yml would break too after merge: it runs pnpm install with only libx11-dev libxkbfile-dev libsecret-1-dev installed.

2. Package names are not what the build needs (blocking)

  • Fedora has no package named pkg-config; it is a Provides of pkgconf-pkg-config. rpm -q matches package names only, so the check fails on every Fedora install — and running the suggested sudo dnf install -y pkg-config (dnf resolves Provides) doesn't make the next run pass.
  • Ubuntu 24.04 / Debian 13: pkg-config is a transitional package, so a machine with only pkgconf fails.
  • python3 from pyenv/conda/asdf is invisible to dpkg/rpm.
  • A Fedora box that happens to have dpkg installed is checked against Debian names; openSUSE is rpm-based but uses zypper, not dnf.
  • process.exit(1) on a heuristic leaves no way to proceed.

Suggestion: check the capabilities node-gyp actually uses. The error in #5133 comes from pkg-config x11 xkbfile --libs, so something like:

pkg-config --exists x11 xkbfile libsecret-1
command -v make && command -v "${CXX:-g++}" && command -v python3

That is distro-agnostic and has no meta-package problem. The failure message can then list the apt/dnf/pacman commands (packages/website/content/docs/dev/BUILD.md already has them) instead of branching on the detected package manager. Alternatively, skip the pre-check and print the hint only when electron-rebuild fails — then a working setup can never be blocked.

3. Please drop the Makefile from this PR

  • make clean runs rm -rf packages/desktop/build (and again via pnpm --filter marktext exec, which runs in the same directory). packages/desktop/build/ is tracked: electron-builder icons, entitlements, NSIS scripts, THIRD-PARTY-LICENSES.txt. The real outputs — dist/ at the repo root and packages/desktop/out/ — are left alone.
  • deps is apt-only, and install / dev / build are one-line aliases for existing pnpm scripts.

Linux setup instructions live in packages/website/content/docs/dev/BUILD.md and LINUX_DEV.md; that's the place for anything missing.

Minor

  • The branch is 392 commits behind develop; please rebase.
  • // Detect available package manager restates hasCmd('dpkg') — see .github/COMMENTING-GUIDELINES.md.
  • The dpkg and rpm branches are copy-pasted; moot with the capability check.

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.

bug: postinstall fails without clear error when Linux system deps are missing

2 participants