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

"zig cc a.c" produces no output file, which breaks autoconf (probably an LLVM 15.0.0 regression) #12858

Closed
williamstein opened this issue Sep 15, 2022 · 1 comment · Fixed by #12905
Labels
bug Observed behavior contradicts documented or intended behavior regression It worked in a previous version of Zig, but stopped working. zig cc Zig as a drop-in C compiler feature
Milestone

Comments

@williamstein
Copy link
Contributor

williamstein commented Sep 15, 2022

Zig Version

0.10.0-dev.4060+61aaef0b0

Steps to Reproduce

  1. Create a file a.c with contents int main() { return 0; }
  2. Type zig cc a.c
  3. NO FILE IS CREATED

Expected Behavior

The file a.out should be created.

Actual Behavior

No output file at all is created.

I noticed this when trying to use autoconf to build a simple C program (lzma in this case), but it would immediately break pretty much all use of autoconf, whose most basic test is to build a trivialconftest.c and check for one of the following output files (copied from autoconf source code);

# The possible output files:
ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*"

Anyway, this is a really serious bug. I've rarely hit a bug I couldn't work around, but this would be painful, and require writing wrapper scripts to replace zig cc a.c with zig cc a.c -o a.out, etc. That is a bit too much to get right.

@williamstein williamstein added the bug Observed behavior contradicts documented or intended behavior label Sep 15, 2022
@motiejus
Copy link
Contributor

motiejus commented Sep 19, 2022

This was caused by fda6d44 ; rolling it back brings our precious a.out back.

motiejus referenced this issue Sep 19, 2022
This commit makes `zig cc` match the equivalent behavior of
`zig build-exe` with regards to caching. That is - it will cache
individual .c to .o compilations (with the usual exceptions), but will
always repeat the linking process so that incremental linking has a
chance to happen.

Perhaps a future enhancement will provide a way to get the old behavior,
but I suspect this new behavior will be preferred by everyone, because
it is closer to what C compilers do. Note that the old behavior can be
obtained by switching to `zig build-exe` instead of `zig cc` and using
the `--enable-cache` parameter.

Closes #12317
motiejus added a commit to motiejus/zig that referenced this issue Sep 19, 2022
If `-o` is not specified for `zig cc` for linking, it should emit the
`a.out` (or equivalent) to the current directory. So then this:

    $ zig cc test.c

Should result in `./a.out`.

If directory is omitted from `Compilation.EmitLoc`, it will default to
the cache directory later in the compilation chain, which will result
in `a.out` missing in the current directory.

If we specify the directory to `Compilation.EmitLoc`, it will be
handled, allegedly, correctly.

Fixes ziglang#12858
@andrewrk andrewrk added the regression It worked in a previous version of Zig, but stopped working. label Sep 19, 2022
@andrewrk andrewrk added this to the 0.10.0 milestone Sep 19, 2022
andrewrk pushed a commit that referenced this issue Sep 19, 2022
If `-o` is not specified for `zig cc` for linking, it should emit the
`a.out` (or equivalent) to the current directory. So then this:

    $ zig cc test.c

Should result in `./a.out`.

If directory is omitted from `Compilation.EmitLoc`, it will default to
the cache directory later in the compilation chain, which will result
in `a.out` missing in the current directory.

If we specify the directory to `Compilation.EmitLoc`, it will be
handled, allegedly, correctly.

Fixes #12858
@andrewrk andrewrk added the zig cc Zig as a drop-in C compiler feature label Sep 19, 2022
FabianHahn pushed a commit to FabianHahn/bazel-zig-cc that referenced this issue Sep 28, 2022
This reverts commit f161caf.

This version has a bug that's been fixed upstream, but a new nightly did
not come out yet: ziglang/zig#12858
Vexu pushed a commit to Vexu/zig that referenced this issue Oct 10, 2022
If `-o` is not specified for `zig cc` for linking, it should emit the
`a.out` (or equivalent) to the current directory. So then this:

    $ zig cc test.c

Should result in `./a.out`.

If directory is omitted from `Compilation.EmitLoc`, it will default to
the cache directory later in the compilation chain, which will result
in `a.out` missing in the current directory.

If we specify the directory to `Compilation.EmitLoc`, it will be
handled, allegedly, correctly.

Fixes ziglang#12858
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior regression It worked in a previous version of Zig, but stopped working. zig cc Zig as a drop-in C compiler feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants