https://github.com/noprd/example-zig
A hello world example project in zig
https://github.com/noprd/example-zig
hello-world zig
Last synced: 6 months ago
JSON representation
A hello world example project in zig
- Host: GitHub
- URL: https://github.com/noprd/example-zig
- Owner: noprd
- Created: 2024-08-23T10:20:51.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-25T18:25:29.000Z (almost 2 years ago)
- Last Synced: 2025-02-01T18:15:00.651Z (over 1 year ago)
- Topics: hello-world, zig
- Language: Just
- Homepage:
- Size: 28.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://ziglang.org)
[](https://github.com/noprd/example-zig/actions/workflows/manual.yaml)
[](https://github.com/noprd/example-zig/actions/workflows/manual.yaml)
[](https://github.com/noprd/example-zig/actions/workflows/auto.yaml)
[](https://github.com/noprd/example-zig/actions/workflows/auto.yaml)
# Example Zig #
This repository provides a simple Hello-World example for the [zig](https://ziglang.org) language,
which in recent times has become quite a hot option
as a simpler alternative to Rust and C++.
## Installation of Zig ##
- Unpack an appropriate distribution from to an appropriate location on your machine.
- Add the directory in which the zig-binary lies to your system `PATH`:
```bash
touch ${HOME}/.bash_profile # ensures this exists
echo "# path for zig" >> ${HOME}/.bash_profile
echo "export PATH=\"/path/to/your zig binaries:\${PATH}\";" >> ${HOME}/.bash_profile
```
for linux.
Or edit the file directly, adding the lines
```bash
...
# path for zig
export PATH="/path/to/your zig binaries:${PATH}";
```
For windows, do this via the system environment variables (which requires admin access);
or just install [bash for windows](https://gitforwindows.org)
and simply perform the above.
- Clone the **ZLS** (_zig langauge server_) repository and run
```bash
zig build
```
This will generate a folder **zig-out/bin**.
Copy just the binary from here to the same path where your zig-compiler binary is stored.
(Otherwise choose your own location and add this to `PATH`.)
### Intellisense ###
If you are using VSCode, install the [Zig Language](https://marketplace.visualstudio.com/items?itemName=ziglang.vscode-zig) extension.
For this to work, it needs to detect your **ZLS** binary.
Open the _User Settings JSON_ (e.g. via command palette)
and add the following attributes to the dictionary:
```js
{
...
// NOTE: remove the .exe extension for windows
"zig.path": "/path/to/your zig binaries/zig.exe",
"zig.zls.zigLibPath": "/path/to/your zig binaries/lib",
"zig.zls.path": "/path/to/your ZLS binaries/zls.exe",
// optional
"zig.zls.buildOnSaveStep": "",
"zig.checkForUpdate": false,
"zig.zls.checkForUpdate": false,
}
```
## Build and run ##
Install the [justfile](https://github.com/casey/just?tab=readme-ov-file#installation) tool.
Run
```bash
just setup # only needed once - then adjust the created .env file
just build # compiles the binary
just run {args} # runs without the compiled binary
just run-exe {args} # runs the compiled binary
```
NOTE: The hello-world example was taken from