├── README.md ├── src ├── zigcc.nim ├── zigcc │ └── utils.nim └── zigcpp.nim └── zigcc.nimble /README.md: -------------------------------------------------------------------------------- 1 | installs 2 | 3 | - `zigcc` 4 | - `zigcpp` 5 | 6 | to your nimble dir. 7 | Both are wrappers for calling zig: 8 | 9 | - `zig cc` 10 | - `zig c++` 11 | 12 | also see this https://stackoverflow.com/questions/73345643/how-to-use-the-zig-compiler-in-order-to-compile-nim-code 13 | 14 | # Installation 15 | ``` 16 | nimble install zigcc 17 | ``` 18 | 19 | # windows 20 | 21 | ``` 22 | nim c --cc:clang --clang.exe="zigcc.cmd" --clang.linkerexe="zigcc.cmd" --forceBuild:on --opt:speed hello.nim 23 | ``` 24 | 25 | # linux and rest 26 | 27 | ``` 28 | nim c --cc:clang --clang.exe="zigcc" --clang.linkerexe="zigcc" --forceBuild:on --opt:speed hello.nim 29 | ``` 30 | 31 | # cross compilation example 32 | 33 | build linux executables from windows: 34 | 35 | ``` 36 | nim c --cc:clang --clang.exe="zigcc.cmd" --clang.linkerexe="zigcc.cmd" --passc:"-target x86_64-linux-gnu" --passl:"-target x86_64-linux-gnu" --forceBuild:on --os:linux --opt:speed --out:hellolinux hello.nim 37 | ``` 38 | 39 | build windows executables from linux: 40 | 41 | ``` 42 | nim c --cc:clang --clang.exe="zigcc" --clang.linkerexe="zigcc" --passc:"-target x86_64-windows" --passl:"-target x86_64-windows" --forceBuild:on --os:windows --opt:speed foo.nim 43 | ``` 44 | -------------------------------------------------------------------------------- /src/zigcc.nim: -------------------------------------------------------------------------------- 1 | import zigcc/utils 2 | 3 | callZig("cc") 4 | -------------------------------------------------------------------------------- /src/zigcc/utils.nim: -------------------------------------------------------------------------------- 1 | import os, osproc 2 | export os, osproc 3 | 4 | template callZig*(zigCmd: string) = 5 | # Set the zig compiler to call and append args 6 | var args = @[zigCmd] 7 | args &= commandLineParams() 8 | # Start process 9 | let process = startProcess( 10 | "zig", 11 | args = args, 12 | options = {poStdErrToStdOut, poUsePath, poParentStreams} 13 | ) 14 | # Get the code so we can carry across the exit code 15 | let exitCode = process.waitForExit() 16 | # Clean up 17 | close process 18 | quit exitCode 19 | -------------------------------------------------------------------------------- /src/zigcpp.nim: -------------------------------------------------------------------------------- 1 | import zigcc/utils 2 | 3 | callZig("c++") 4 | -------------------------------------------------------------------------------- /zigcc.nimble: -------------------------------------------------------------------------------- 1 | # Package 2 | 3 | version = "3.0.0" 4 | author = "David Krause" 5 | description = "wraps `zig cc` to be able to be called by the nim compiler" 6 | license = "MIT" 7 | srcDir = "src" 8 | bin = @["zigcc", "zigcpp"] 9 | 10 | 11 | # Dependencies 12 | 13 | requires "nim >= 1.6.4" 14 | --------------------------------------------------------------------------------