Skip to content

fix(cc): preprocessor doesn't emit bin - #20740

Merged
alexrp merged 1 commit into
ziglang:masterfrom
zhylmzr:master
Jan 29, 2025
Merged

alexrp merged 1 commit into
ziglang:masterfrom
zhylmzr:master

Conversation

@zhylmzr

@zhylmzr zhylmzr commented Jul 22, 2024 •

Copy link
Copy Markdown
Contributor

zig cc main.c -o /dev/null emit a.out, zig cc -E main.c emit main.o, this pr modifies the linking and preprocessing generation logic to be more consistent with clang's behavior.

When using clang -E main.c or clang -E main.c -o - outputs directly to standard output, if using clang -E main.c -o a it outputs to a file.

Fix the following issues:
fixed: #20739
fixed: #20689
fixed: #20359
fixed: #20709

@zhylmzr
zhylmzr force-pushed the master branch 2 times, most recently from a48afe0 to cc9d19b Compare July 22, 2024 17:54
@markus-oberhumer

Copy link
Copy Markdown
Contributor

Can we get this merged, please?

Comment thread src/main.zig Resolved
Comment thread src/main.zig Outdated
.link => {
create_module.opts.output_mode = if (is_shared_lib) .Lib else .Exe;
emit_bin = if (out_path) |p| .{ .yes = p } else EmitBin.yes_a_out;
emit_bin = if (out_path) |p| .{ .yes = p } else emit_bin;

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.

yes_a_out looks unused after this and could be deleted.

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.

Ah I was on the wrong branch and was getting the old behavior.

Why was this changed?

@andrewrk andrewrk 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.

Causes the following regression:

andy@bark ~/tmp> ~/src/zig/build-noassert/stage4/bin/zig cc hello.c
andy@bark ~/tmp> ./a.out
./a.out: command not found

Please test before sending patches.

@zhylmzr

zhylmzr commented Aug 28, 2024

Copy link
Copy Markdown
Contributor Author

fixed, sorry for missing this test case.

@zhylmzr

zhylmzr commented Oct 8, 2024

Copy link
Copy Markdown
Contributor Author

Is there any update on the progress?

clang's behavior.

1. `zig cc main.c -o /dev/null` shouldn't emit a.out
2. `zig cc -E main.c` and `zig cc -E main -o -` should output to stdout
@alexrp
alexrp enabled auto-merge (rebase) January 26, 2025 23:01
@alexrp
alexrp merged commit 308ba80 into ziglang:master Jan 29, 2025
oalders added a commit to oalders/clodhopper that referenced this pull request Jun 1, 2026
* ci: bump zig to 0.14.1 to fix darwin CGO cross-compile

zig 0.13.0 fails cross-compiling go-sqlite3 (CGO) to macOS targets with
"unable to create compilation: AccessDenied" (ziglang/zig#20689). The
fix (ziglang/zig#20740) shipped in zig 0.14.0, so pin to 0.14.1.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* ci: bump mlugg/setup-zig to v2

setup-zig@v1 cannot resolve zig 0.14.1 (404 on the download index). v2
handles current ziglang.org/community-mirror version resolution.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* ci: build darwin with clang+SDK on a macOS runner

zig cannot link macOS CGO binaries: Apple's SDK isn't redistributable,
so zig's bundled macos libc lacks libresolv and the system frameworks
that Go's net package and go-sqlite3 require ("unable to find dynamic
system library 'resolv'"). Move the release job to macos-latest and
build darwin natively with clang against the runner's SDK (resolved via
xcrun --show-sdk-path, passed as SDK_PATH). linux and windows still
cross-compile with zig from the same runner.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

---------

Co-authored-by: Claude Opus 4.8 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

6 participants