Repository navigation
windows_sys: gate #[link] behind cfg(windows) so non-Windows cargo test binaries link #35084
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
50db2e6
windows_sys: gate #[link] directives behind cfg(windows)
robobun 3d50b67
[autofix.ci] apply automated fixes
autofix-ci[bot] bdd901b
test: skip when cargo workspace is not resolvable (test-only lanes)
robobun 1619b62
source-lints: guard against bare #[link(name=...)] in bun_windows_sys
robobun 06d79c3
test: pass --locked to cargo, matching linear-fifo.test.ts
robobun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| // bun_windows_sys is a #![no_std] leaf crate that several workspace crates | ||
| // (bun_errno, bun_spawn_sys) depend on unconditionally so that Win32 POD types | ||
| // like IO_COUNTERS resolve on every target. Its #[link(name = "...")] | ||
| // attributes must therefore be gated behind cfg(windows), or the linker for | ||
| // any standalone test binary on a non-Windows host sees | ||
| // ld.lld: error: unable to find library -lntdll / -lkernel32 / ... | ||
| // as soon as bun_windows_sys.rlib lands on the link line. | ||
| // | ||
| // `cargo check --tests` type-checks only and will not catch this; it has to | ||
| // be `cargo test --no-run` so rustc actually drives the linker. The crate has | ||
| // zero dependencies, so linking completes in well under a second on a warm tree. | ||
| import { which } from "bun"; | ||
| import { expect, test } from "bun:test"; | ||
| import { isWindows } from "harness"; | ||
| import { existsSync } from "node:fs"; | ||
| import { join } from "node:path"; | ||
|
|
||
| const cargo = which("cargo"); | ||
| const repoRoot = join(import.meta.dir, "..", ".."); | ||
| // Cargo parses the whole workspace manifest (including path deps) before | ||
| // applying -p, so it needs vendor/lolhtml on disk even for a zero-dep crate. | ||
| // Test-only CI lanes run a prebuilt binary and never fetch it; skip there. | ||
| // Same prerequisite check as linear-fifo.test.ts / scripts/rust-miri.ts. | ||
| const workspaceResolvable = | ||
| existsSync(join(repoRoot, "vendor", "lolhtml", "Cargo.toml")) && | ||
| existsSync(join(repoRoot, "build", "debug", "codegen", "build_options.rs")); | ||
|
|
||
| test.skipIf(isWindows || !cargo || !workspaceResolvable)( | ||
| "cargo test -p bun_windows_sys links on non-Windows hosts", | ||
| async () => { | ||
| await using proc = Bun.spawn({ | ||
| cmd: [cargo!, "test", "-p", "bun_windows_sys", "--no-run", "--quiet"], | ||
| cwd: repoRoot, | ||
| env: { ...process.env, CARGO_TERM_COLOR: "never" }, | ||
| stdout: "pipe", | ||
| stderr: "pipe", | ||
| }); | ||
| const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); | ||
|
|
||
| expect(stderr).not.toContain("unable to find library"); | ||
| expect({ stdout, stderr, exitCode }).toMatchObject({ exitCode: 0 }); | ||
| }, | ||
| ); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.