Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Enr CI

on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:

env:
ZIG_VERSION: 0.14.1

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Cache Zig
id: cache-zig
uses: actions/cache@v4
with:
path: ~/zig
key: ${{ runner.os }}-zig-${{ env.ZIG_VERSION }}

- name: Install Zig
if: steps.cache-zig.outputs.cache-hit != 'true'
run: |
wget https://ziglang.org/download/${{ env.ZIG_VERSION }}/zig-x86_64-linux-${{ env.ZIG_VERSION }}.tar.xz
tar -xf zig-x86_64-linux-${{ env.ZIG_VERSION }}.tar.xz
mv zig-x86_64-linux-${{ env.ZIG_VERSION }} ~/zig
Comment thread
GrapeBaBa marked this conversation as resolved.
Outdated

- name: Add Zig to PATH
run: echo "${HOME}/zig" >> $GITHUB_PATH

- name: Cache Zig build artifacts
uses: actions/cache@v4 # Updated to v4
with:
path: |
zig-cache
~/.cache/zig
key: ${{ runner.os }}-zig-build-${{ hashFiles('**/*.zig') }}
restore-keys: |
${{ runner.os }}-zig-build-

- name: Formatting
run: zig fmt --check --color on .

- name: Unit testing
run: zig build test --summary all

- name: Building
run: zig build -Doptimize=ReleaseSafe
49 changes: 48 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,49 @@
# enr
About Ethereum Node Records (ENR)
Ethereum Node Records (ENR) utility in Zig.

## Prerequisites

- Zig 0.14.1

## Building

To build the project, run the following command in the root directory of the project:

```bash
zig build -Doptimize=ReleaseSafe
```

## Running Tests

To run the tests, run the following command in the root directory of the project:

```bash
zig build test --summary all
```

## Docs

To generate documentation for the project, run the following command in the root directory of the project:

```bash
zig build docs
```

# Usage

Update `build.zig.zon`:

```sh
zig fetch --save git+https://github.com/blockblaz/enr
```

In your `build.zig`:

```zig
const enr_dep = b.dependency("zig_enr", .{
.target = target,
.optimize = optimize,
});
const enr_module = enr_dep.module("zig-enr");
root_module.addImport("zig-enr", enr_module);
```
73 changes: 73 additions & 0 deletions build.zig
Comment thread
GrapeBaBa marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
const std = @import("std");

// Although this function looks imperative, note that its job is to
// declaratively construct a build graph that will be executed by an external
// runner.
pub fn build(b: *std.Build) void {
Comment thread
GrapeBaBa marked this conversation as resolved.
Outdated
// Standard target options allows the person running `zig build` to choose
// what target to build for. Here we do not override the defaults, which
// means any target is allowed, and the default is native. Other options
// for restricting supported target set are available.
const target = b.standardTargetOptions(.{});

// Standard optimization options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
// set a preferred release mode, allowing the user to decide how to optimize.
const optimize = b.standardOptimizeOption(.{});

const discv5 = b.dependency("discv5", .{});

const enr_mod = discv5.module("enr");

// This creates a "module", which represents a collection of source files alongside
// some compilation options, such as optimization mode and linked system libraries.
// Every executable or library we compile will be based on one or more modules.
const lib_mod = b.createModule(.{
// `root_source_file` is the Zig "entry point" of the module. If a module
// only contains e.g. external object files, you can make this `null`.
// In this case the main source file is merely a path, however, in more
// complicated build scripts, this could be a generated file.
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
});

lib_mod.addImport("enr", enr_mod);

b.modules.put(b.dupe("zig-enr"), lib_mod) catch @panic("OOM");
Comment thread
GrapeBaBa marked this conversation as resolved.
Outdated
// Now, we will create a static library based on the module we created above.
// This creates a `std.Build.Step.Compile`, which is the build step responsible
// for actually invoking the compiler.
const lib = b.addLibrary(.{
.linkage = .static,
.name = "enr",
.root_module = lib_mod,
});

// This declares intent for the library to be installed into the standard
// location when the user invokes the "install" step (the default step when
// running `zig build`).
b.installArtifact(lib);

// Creates a step for unit testing. This only builds the test executable
// but does not run it.
const lib_unit_tests = b.addTest(.{
.root_module = lib_mod,
});

const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);

// Similar to creating the run step earlier, this exposes a `test` step to
// the `zig build --help` menu, providing a way for the user to request
// running the unit tests.
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_lib_unit_tests.step);

const install_docs = b.addInstallDirectory(.{
.source_dir = lib.getEmittedDocs(),
.install_dir = .prefix,
.install_subdir = "docs",
});
const docs_step = b.step("docs", "Generate documentation");
docs_step.dependOn(&install_docs.step);
}
52 changes: 52 additions & 0 deletions build.zig.zon
Comment thread
GrapeBaBa marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
.{
// This is the default name used by packages depending on this one. For
// example, when a user runs `zig fetch --save <url>`, this field is used
// as the key in the `dependencies` table. Although the user can choose a
// different name, most users will stick with this provided value.
//
// It is redundant to include "zig" in this name because it is already
// within the Zig package namespace.
.name = .zig_enr,

// This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication.
.version = "0.0.0",

// Together with name, this represents a globally unique package
// identifier. This field is generated by the Zig toolchain when the
// package is first created, and then *never changes*. This allows
// unambiguous detection of one package being an updated version of
// another.
//
// When forking a Zig project, this id should be regenerated (delete the
// field and run `zig build`) if the upstream project is still maintained.
// Otherwise, the fork is *hostile*, attempting to take control over the
// original project's identity. Thus it is recommended to leave the comment
// on the following line intact, so that it shows up in code reviews that
// modify the field.
.fingerprint = 0x499ae5d25c594f6a, // Changing this has security and trust implications.

// Tracks the earliest Zig version that the package considers to be a
// supported use case.
.minimum_zig_version = "0.14.1",

// This field is optional.
// Each dependency must either provide a `url` and `hash`, or a `path`.
// `zig build --fetch` can be used to fetch all dependencies of a package, recursively.
// Once all dependencies are fetched, `zig build` no longer requires
// internet connectivity.
.dependencies = .{
.discv5 = .{
.url = "git+https://github.com/blockblaz/zig-discv5#bc96ea8e6a8c3ddc5880256a11e19df3afe37870",
.hash = "discv5-0.1.0-fkJduBNjAQCUYP7JVBtZ6A5Y79UYpyC8JHz5kzGnB-K5",
},
},
.paths = .{
"build.zig",
"build.zig.zon",
"src",
// For example...
//"LICENSE",
//"README.md",
},
}
Loading