-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
compiling zig on windows without visual studio #528
Comments
Glad to hear that because I've been doing a lot of work on windows in the past couple weeks.
It is possible to work without them. These are needed if you want to include libc .h files such as stdlib.h or if you want to link against libc (which you almost certainly will have to if you depend on any C libraries). If you wanted to run the zig compiler tests you would need a working libc as well since some of the tests test libc integration.
If you want artifacts to have the mingw C ABI instead of msvc, change I think we need to update the linker code in zig for However you can always use zig to create a mingw compatible .o file using We do have zig building successfully with mingw and it looks like most tests are passing, so you should be able to play with this. |
Are those cmake arguments? If those are zig arguments, I need to get zig itself first. I asked you to modify ci/appveyor/build_script.bat , so that it doesn't have that weird bash magic. and just compiles. Can you at least upload compiled zig for windows somewhere?
I don't depend on any C libraries. That's the whole point of freestanding exe files: only system provided dll. I'm a fan of demoscene, you see. Size matters, and all. I'll probably actually rewrite most of the libraries in zig, or at least those that I need.
Can't care less about those tests, don't want to wait for them to pass. These are probably not necessary for me. When I say "freestanding", I mean exe file that doesn't depend on C runtime, and only interacts with system provided dll directly. Is that the right use of that word? Or "freestanding" actually means just some object code that can't be even run by itself? |
I'm working on it as we speak. Here's the checklist I'm going through: #302
Right. This is one of the main use cases of zig, so I am excited for you to try it out. In this case you do not need the Can you try building with mingw without those configure arguments? It should work fine and then panic if you try to do anything with libc. "freestanding" in zig lingo means that you are either compiling your own OS or targeting an OS that zig doesn't know about. (See the list output by You're targeting Windows so you'll want to either compile natively (no If you're doing demoscene stuff I'm guessing you want to avoid (actually now that I think of it, we should figure out how to tell LLVM to turn off And probably your own compiler-rt and memcpy/memset implementations instead of zig's compiler-rt and zig's memcpy/memset. In this case I think you're right that freestanding is what you want. I've used freestanding to build an OS but I haven't tried to run freestanding code on windows yet and I'd like to do that before recommending something to you. Perhaps you could live with zig's startup code and target windows for a little bit, then when you want to really optimize the last 1% we can move forward on this? Or play around with freestanding, hack on zig, sounds like you know what you're doing. I'm on IRC if you want to chat. Don't forget to build with |
One more thing. We currently have these build modes:
I'm considering adding
Is this something you would be interested in? |
Ideally ReleaseFast and ReleaseSmall should be the same, don't see much reason in separating those. But until we get there, sure, why not. I'll set CodeGen.libc_static_lib_dir to empty string and see if anything breaks. I'll also start rewriting build system in bat and makefiles, because I'm having troubles with understanding cmake. |
Here are a couple reasons:
This is the same reason GCC/clang have
ok. feel free to post an error log, I can probably tell you how to fix whatever happened. |
It sounds like it will also make simplier assembly. Then yes, it's a good idea, make ReleaseSmall. |
Issue to track it: #531 |
How do you think, will zig build as a 32bit app? Or I must have it 64bit? |
Currently the zig compiler only works as 64-bit. We'll make it work as a 32-bit application when we self-host (See #89) |
Ok, zig got built, and it actually works. Except it deadlocks on exit. Really weird. I create this use @import("std").os.windows;
and type this to compile it:
It works nicely, result works, but zig itself never exits. I tried to get callstack with x64dbg, here it is. Ignore everything that's not "Comment", read from bottom to top:
What I understood from it, is that I guess |
It doesn't happen with the msvc build, so it seems like a bug in mingw. Can probably work around by patching zig to call |
Replaced I replaced this one: https://github.com/zig-lang/zig/blob/8cfb0cfbcee8161c52f71bccc3cf1b8d988f83b0/src/main.cpp#L793 Linking is so slow here. |
Deadlock on application exit is often caused by invocation of user code in DllMain when the DLL is unloaded. Such code is subject of restrictions but few care. This is the hammer to exit w/o notifying DLLs:
Alternatively, one may try to unload suspected DLL manually (by repeated calling |
I think we want to do this on Windows anyway. There is no point in calling a DLL unload code. |
I'm new to git, how can I keep TerminateProcess in the code, but still get updates? TerminateProcess worked nicely, now I don't have to open task manager every time. |
When you want an update:
Can you send me the diff so that I can merge it upstream? GitHub pull request is easiest for me but I don't mind if you just want to paste a diff. |
It's a terrible thing to merge, it only works on windows, it only works for one combination of console commands. But it works for now. Probably should recompile llvm instead, maybe they fixed it by now. Also don't know how to make diff here. |
ok |
It takes 6 minutes to link zig.exe together. I need to decrease that time somehow if I want to get anywhere. I suspect that adding https://stackoverflow.com/questions/16596876/object-file-has-too-many-sections |
|
Built lld as dll, it worked, linking only takes 10 seconds. Object files were so odd, they had thousands of sections. I replaced this:
with this:
And to free myself from
to this:
|
Ah if that improved link time, you night also improve link time by linking against libLLVM.so instead of individual libraries and the .so versions of clang libraries instead of .a |
You would edit cmake/Findllvm.cmake and cmake/Find clang.cmake |
Yeah, I'm already linking to LLVM.dll that came with msys2, I didn't compile it myself. It's probably the reason why it deadlocks. It worked like that out of the box, without me editing findcmake files. |
Uploaded everything I said in this thread as a mingw.patch, since I now know how to do those. In a zip, github doesn't support A few notes for me: To create: To apply (made To reverse (made I guess I'll just keep unapplying and applying this patch every time I need to get newest version from git. To actually compile, use this:
To get a short beep once it's done compiling, use this:
|
I'd like to log progress on it somewhere. Can't wait to try out zig on windows.
Author intends to get zig working with visual studio first, and only then work on other compilers. But I can't get visual studio to work here, so I have to wait. But let's try working in parallel...
First, ci/appveyor/build_script.bat is pretty confusing. The most confusing part is getting three vars, which evaluate to this on my system:
ZIG_LIBC_LIB_DIR
C:/msys64/mingw32/i686-w64-mingw32/lib
ZIG_LIBC_INCLUDE_DIR
C:/msys64/mingw32/i686-w64-mingw32/include
ZIG_LIBC_STATIC_LIB_DIR
C:/msys64/mingw32/lib/gcc/i686-w64-mingw32/6.3.0
It looks like their purpose is locating crt1.o and crtbegin.o. Shouldn't it be possible to work without them? Support table says that compiling freestanding exe on windows already works.
Is it possible to make 4 build targets for windows instead of one?
32bit
32bit-freestanding
64bit
64bit-freestanding
The text was updated successfully, but these errors were encountered: