Skip to content

Build: Fix bug causing ReleaseSmall to fail on Windows #15756

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 3 commits into from
Jun 3, 2023

Conversation

xEgoist
Copy link
Contributor

@xEgoist xEgoist commented May 18, 2023

closes: #13405

Due to the change in default behavior of ReleaseSmall (#13067), debug info (pdb here) are stripped by default. However because Compile.create defaults to null, producesPdbFile will report true for
lib/std/Build/Step/InstallArtifact.zig

.pdb_dir = if (artifact.producesPdbFile()) blk: {

Because of this, this only affects zig build and not zig build-exe. After this change, a simple program compiled with ReleaseSmall will successfully compile and won't try to copy/produce the pdb file.

Of course, this still allows the user to choose not to strip the build and will produce a pdb file.

Due to the change in default behavior of ReleaseSmall, debug info are
stripped by default. However because `Compile.create` still defaults to
null, `producesPdbFile` will report true for
`lib/std/Build/Step/InstallArtifact.zig` causing it to fail on copying a
file that does not exist. This commit change the default of strip
depending on `optimize`.
@davidgmbb
Copy link
Contributor

davidgmbb commented May 18, 2023

Couldn't it be possible to imitate the ReleaseFast code path for stripping? As far as I understand, this only happens with ReleaseSmall, but by using ReleaseFast the binary is stripped too and the bug doesn't happen. There has to be some place in the code where the ReleaseFast stripping is handled gracefully. Otherwise we risk introducing here a very hidden branch in an unexpected place that could cause some trouble. That's my opinion and obviously I could be missing some details or misinterpreting something since I am not that aware of the compiler internals.

@xEgoist
Copy link
Contributor Author

xEgoist commented May 18, 2023

Couldn't it be possible to imitate the ReleaseFast code path for stripping? As far as I understand, this only happens with ReleaseSmall, but by using ReleaseFast the binary is stripped too and the bug doesn't happen. There has to be some place in the code where the ReleaseFast stripping is handled gracefully. Otherwise we risk introducing here a very hidden branch in an unexpected place that could cause some trouble. That's my opinion and obviously I could be missing some details or misinterpreting something since I am not that aware of the compiler internals.

I don't think the current/intended behavior of ReleaseFast is to strip the binaries, but i could also be wrong or misinterpreting what you said 😄.

Linux:

~/Projects/zigProjects/bench
Zig-Shell ❯ zig build -Doptimize=ReleaseFast

~/Projects/zigProjects/bench 6s
Zig-Shell ❯ file zig-out/bin/bench          
zig-out/bin/bench: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, with debug_info, not stripped

Windows builds also produces pdb.

@davidgmbb
Copy link
Contributor

Ok I take back what I said then. Apologies :)

@xEgoist
Copy link
Contributor Author

xEgoist commented May 18, 2023

Seems like CI is failing on debug.zig "manage resources correctly" ReleaseSmall test.

zig/lib/std/debug.zig

Lines 2185 to 2197 in 7cf2cbb

test "manage resources correctly" {
if (builtin.os.tag == .wasi) return error.SkipZigTest;
if (builtin.os.tag == .windows and builtin.cpu.arch == .x86_64) {
// https://github.com/ziglang/zig/issues/13963
return error.SkipZigTest;
}
const writer = std.io.null_writer;
var di = try openSelfDebugInfo(testing.allocator);
defer di.deinit();
try printSourceAtAddress(&di, writer, showMyTrace(), detectTTYConfig(std.io.getStdErr()));
}

I assume it's triggered because strip is now set to true on ReleaseSmall, thus failing on the builtin strip check.

I haven't investigated further yet so i could be totally wrong, but does it make sense that this test should have been skipped for ReleaseSmall because there is no debug info?

@davidgmbb
Copy link
Contributor

I guess, if I understood correctly, that one could use @import("builtin").strip_debug_info to conditionally execute this test only in situations where the binary was not stripped.

@xEgoist
Copy link
Contributor Author

xEgoist commented May 18, 2023

I think I have a better understanding of this now. The problem is more specifically because it's stripping the test (addTest in Build.zig). So it depends on the desired behavior of tests. Whether tests should also strip or not.

So there are three options here:

  • Skip this test on strip as specified above.
  • Don't strip tests regardless of release mode unless specified.
  • Don't strip the lang/CI tests.

edit: for now, i am going with the 1st option.

Because tests are also stripped by ReleaseSmall, the test specified in
this commit will fail on ReleaseSmall due to no debug info.
@@ -433,7 +433,7 @@ pub fn create(owner: *std.Build, options: Options) *Compile {

const self = owner.allocator.create(Compile) catch @panic("OOM");
self.* = Compile{
.strip = null,
.strip = if (options.optimize == .ReleaseSmall) true else null,
Copy link
Member

Choose a reason for hiding this comment

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

The previous value was correct. The default is decided by the compiler rather than the build system. null means to use the compiler's default.

Copy link
Contributor Author

@xEgoist xEgoist May 19, 2023

Choose a reason for hiding this comment

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

I think I understand this now, and it does make sense why the CI was initially failing. Thanks for letting me know and sorry for the bad initial commit.

I reverted the commits and modified it to just check inside the producesPdbFile function instead of changing the strip value. Hopefully that's better(?).

This change allows InstallArtifact to not produce a pdb file while
keeping the default strip to the compiler.
@xEgoist xEgoist requested a review from andrewrk May 25, 2023 13:09
@andrewrk andrewrk merged commit ff57a26 into ziglang:master Jun 3, 2023
der-teufel-programming pushed a commit to der-teufel-programming/zig that referenced this pull request Jun 4, 2023
Fixes bug causing ReleaseSmall to fail on Windows.

Due to the change in default behavior of ReleaseSmall, debug info are
stripped by default. However because `Compile.create` still defaults to
null, `producesPdbFile` will report true for
`lib/std/Build/Step/InstallArtifact.zig` causing it to fail on copying a
file that does not exist. This commit change the default of strip
depending on `optimize`.
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.

ReleaseSmall builds fail with FileNotFound error
3 participants