Skip to content

Commit

Permalink
updated to zig v0.14.0-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
kassane committed Jun 15, 2024
1 parent ba81b8b commit 315be3e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
build/
zig-*/
*zig-*/
.vscode/
.cache/
sdkconfig
Expand Down
66 changes: 33 additions & 33 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn build(b: *std.Build) !void {
const lib = b.addStaticLibrary(.{
.name = "zig",
// comment or remove .root_source_file, make null value for module detection
.root_source_file = .{ .path = "main/lib.zig" },
.root_source_file = b.path("main/lib.zig"),
.target = target,
.optimize = optimize,
});
Expand Down Expand Up @@ -56,9 +56,9 @@ pub fn build(b: *std.Build) !void {
fn includeDeps(b: *std.Build, lib: *std.Build.Step.Compile) !void {
const include_dirs = std.process.getEnvVarOwned(b.allocator, "INCLUDE_DIRS") catch "";
if (!std.mem.eql(u8, include_dirs, "")) {
var it_inc = std.mem.tokenize(u8, include_dirs, ";");
var it_inc = std.mem.tokenizeAny(u8, include_dirs, ";");
while (it_inc.next()) |dir| {
lib.addIncludePath(.{ .path = dir });
lib.addIncludePath(.{ .cwd_relative = dir });
}
}

Expand All @@ -74,7 +74,7 @@ fn includeDeps(b: *std.Build, lib: *std.Build.Step.Compile) !void {
@tagName(lib.rootModuleTarget().cpu.arch),
});

lib.addIncludePath(.{ .path = b.pathJoin(&.{
lib.addIncludePath(.{ .cwd_relative = b.pathJoin(&.{
home_dir,
".espressif",
"tools",
Expand All @@ -83,7 +83,7 @@ fn includeDeps(b: *std.Build, lib: *std.Build.Step.Compile) !void {
archtools,
"include",
}) });
lib.addIncludePath(.{ .path = b.pathJoin(&.{
lib.addIncludePath(.{ .cwd_relative = b.pathJoin(&.{
home_dir,
".espressif",
"tools",
Expand All @@ -94,7 +94,7 @@ fn includeDeps(b: *std.Build, lib: *std.Build.Step.Compile) !void {
"sys-include",
}) });
lib.addIncludePath(.{
.path = b.pathJoin(&.{
.cwd_relative = b.pathJoin(&.{
home_dir,
".espressif",
"tools",
Expand All @@ -106,7 +106,7 @@ fn includeDeps(b: *std.Build, lib: *std.Build.Step.Compile) !void {
}),
});
}
lib.addIncludePath(.{ .path = "include" });
lib.addIncludePath(b.path("include"));
}

fn led_strip_component(lib: *std.Build.Step.Compile) void {
Expand Down Expand Up @@ -145,7 +145,7 @@ pub fn searched_idf_libs(b: *std.Build, lib: *std.Build.Step.Compile) !void {
if (lib_ext) {
const src_path = std.fs.path.dirname(@src().file).?;
const cwd_path = b.pathJoin(&.{ src_path, "build", b.dupe(entry.path) });
const lib_file: std.Build.LazyPath = .{ .path = cwd_path };
const lib_file: std.Build.LazyPath = .{ .cwd_relative = cwd_path };
lib.addObjectFile(lib_file);
}
}
Expand All @@ -168,7 +168,7 @@ pub fn searched_idf_include(b: *std.Build, lib: *std.Build.Step.Compile, idf_pat
} else false;
if (include_file) {
const include_dir = b.pathJoin(&.{ comp, std.fs.path.dirname(b.dupe(entry.path)).? });
lib.addIncludePath(.{ .path = include_dir });
lib.addIncludePath(.{ .cwd_relative = include_dir });
}
}
}
Expand All @@ -177,12 +177,12 @@ pub fn idf_wrapped_modules(b: *std.Build) *std.Build.Module {
const src_path = std.fs.path.dirname(@src().file).?;
const sys = b.addModule("sys", .{
.root_source_file = .{
.path = b.pathJoin(&.{ src_path, "imports", "idf-sys.zig" }),
.cwd_relative = b.pathJoin(&.{ src_path, "imports", "idf-sys.zig" }),
},
});
const rtos = b.addModule("rtos", .{
.root_source_file = .{
.path = b.pathJoin(&.{ src_path, "imports", "rtos.zig" }),
.cwd_relative = b.pathJoin(&.{ src_path, "imports", "rtos.zig" }),
},
.imports = &.{
.{
Expand All @@ -193,7 +193,7 @@ pub fn idf_wrapped_modules(b: *std.Build) *std.Build.Module {
});
const version = b.addModule("ver", .{
.root_source_file = .{
.path = b.pathJoin(&.{ src_path, "imports", "version.zig" }),
.cwd_relative = b.pathJoin(&.{ src_path, "imports", "version.zig" }),
},
.imports = &.{
.{
Expand All @@ -204,7 +204,7 @@ pub fn idf_wrapped_modules(b: *std.Build) *std.Build.Module {
});
const log = b.addModule("log", .{
.root_source_file = .{
.path = b.pathJoin(&.{ src_path, "imports", "logger.zig" }),
.cwd_relative = b.pathJoin(&.{ src_path, "imports", "logger.zig" }),
},
.imports = &.{
.{
Expand All @@ -215,7 +215,7 @@ pub fn idf_wrapped_modules(b: *std.Build) *std.Build.Module {
});
const panic = b.addModule("panic", .{
.root_source_file = .{
.path = b.pathJoin(&.{ src_path, "imports", "panic.zig" }),
.cwd_relative = b.pathJoin(&.{ src_path, "imports", "panic.zig" }),
},
.imports = &.{
.{
Expand All @@ -230,7 +230,7 @@ pub fn idf_wrapped_modules(b: *std.Build) *std.Build.Module {
});
const led = b.addModule("led", .{
.root_source_file = .{
.path = b.pathJoin(&.{ src_path, "imports", "led-strip.zig" }),
.cwd_relative = b.pathJoin(&.{ src_path, "imports", "led-strip.zig" }),
},
.imports = &.{
.{
Expand All @@ -241,7 +241,7 @@ pub fn idf_wrapped_modules(b: *std.Build) *std.Build.Module {
});
const bootloader = b.addModule("bootloader", .{
.root_source_file = .{
.path = b.pathJoin(&.{ src_path, "imports", "bootloader.zig" }),
.cwd_relative = b.pathJoin(&.{ src_path, "imports", "bootloader.zig" }),
},
.imports = &.{
.{
Expand All @@ -252,7 +252,7 @@ pub fn idf_wrapped_modules(b: *std.Build) *std.Build.Module {
});
const errors = b.addModule("error", .{
.root_source_file = .{
.path = b.pathJoin(&.{ src_path, "imports", "error.zig" }),
.cwd_relative = b.pathJoin(&.{ src_path, "imports", "error.zig" }),
},
.imports = &.{
.{
Expand All @@ -263,7 +263,7 @@ pub fn idf_wrapped_modules(b: *std.Build) *std.Build.Module {
});
const lwip = b.addModule("lwip", .{
.root_source_file = .{
.path = b.pathJoin(&.{ src_path, "imports", "lwip.zig" }),
.cwd_relative = b.pathJoin(&.{ src_path, "imports", "lwip.zig" }),
},
.imports = &.{
.{
Expand All @@ -274,7 +274,7 @@ pub fn idf_wrapped_modules(b: *std.Build) *std.Build.Module {
});
const mqtt = b.addModule("mqtt", .{
.root_source_file = .{
.path = b.pathJoin(&.{ src_path, "imports", "mqtt.zig" }),
.cwd_relative = b.pathJoin(&.{ src_path, "imports", "mqtt.zig" }),
},
.imports = &.{
.{
Expand All @@ -285,7 +285,7 @@ pub fn idf_wrapped_modules(b: *std.Build) *std.Build.Module {
});
const heap = b.addModule("heap", .{
.root_source_file = .{
.path = b.pathJoin(&.{ src_path, "imports", "heap.zig" }),
.cwd_relative = b.pathJoin(&.{ src_path, "imports", "heap.zig" }),
},
.imports = &.{
.{
Expand All @@ -296,7 +296,7 @@ pub fn idf_wrapped_modules(b: *std.Build) *std.Build.Module {
});
const http = b.addModule("http", .{
.root_source_file = .{
.path = b.pathJoin(&.{ src_path, "imports", "http.zig" }),
.cwd_relative = b.pathJoin(&.{ src_path, "imports", "http.zig" }),
},
.imports = &.{
.{
Expand All @@ -311,7 +311,7 @@ pub fn idf_wrapped_modules(b: *std.Build) *std.Build.Module {
});
const bt = b.addModule("bluetooth", .{
.root_source_file = .{
.path = b.pathJoin(&.{ src_path, "imports", "bluetooth.zig" }),
.cwd_relative = b.pathJoin(&.{ src_path, "imports", "bluetooth.zig" }),
},
.imports = &.{
.{
Expand All @@ -322,7 +322,7 @@ pub fn idf_wrapped_modules(b: *std.Build) *std.Build.Module {
});
const wifi = b.addModule("wifi", .{
.root_source_file = .{
.path = b.pathJoin(&.{ src_path, "imports", "wifi.zig" }),
.cwd_relative = b.pathJoin(&.{ src_path, "imports", "wifi.zig" }),
},
.imports = &.{
.{
Expand All @@ -333,7 +333,7 @@ pub fn idf_wrapped_modules(b: *std.Build) *std.Build.Module {
});
const gpio = b.addModule("gpio", .{
.root_source_file = .{
.path = b.pathJoin(&.{ src_path, "imports", "gpio.zig" }),
.cwd_relative = b.pathJoin(&.{ src_path, "imports", "gpio.zig" }),
},
.imports = &.{
.{
Expand All @@ -348,7 +348,7 @@ pub fn idf_wrapped_modules(b: *std.Build) *std.Build.Module {
});
const uart = b.addModule("uart", .{
.root_source_file = .{
.path = b.pathJoin(&.{ src_path, "imports", "uart.zig" }),
.cwd_relative = b.pathJoin(&.{ src_path, "imports", "uart.zig" }),
},
.imports = &.{
.{
Expand All @@ -363,7 +363,7 @@ pub fn idf_wrapped_modules(b: *std.Build) *std.Build.Module {
});
const i2c = b.addModule("i2c", .{
.root_source_file = .{
.path = b.pathJoin(&.{ src_path, "imports", "i2c.zig" }),
.cwd_relative = b.pathJoin(&.{ src_path, "imports", "i2c.zig" }),
},
.imports = &.{
.{
Expand All @@ -378,7 +378,7 @@ pub fn idf_wrapped_modules(b: *std.Build) *std.Build.Module {
});
const i2s = b.addModule("i2s", .{
.root_source_file = .{
.path = b.pathJoin(&.{ src_path, "imports", "i2s.zig" }),
.cwd_relative = b.pathJoin(&.{ src_path, "imports", "i2s.zig" }),
},
.imports = &.{
.{
Expand All @@ -393,7 +393,7 @@ pub fn idf_wrapped_modules(b: *std.Build) *std.Build.Module {
});
const spi = b.addModule("spi", .{
.root_source_file = .{
.path = b.pathJoin(&.{ src_path, "imports", "spi.zig" }),
.cwd_relative = b.pathJoin(&.{ src_path, "imports", "spi.zig" }),
},
.imports = &.{
.{
Expand All @@ -408,7 +408,7 @@ pub fn idf_wrapped_modules(b: *std.Build) *std.Build.Module {
});
const phy = b.addModule("phy", .{
.root_source_file = .{
.path = b.pathJoin(&.{ src_path, "imports", "phy.zig" }),
.cwd_relative = b.pathJoin(&.{ src_path, "imports", "phy.zig" }),
},
.imports = &.{
.{
Expand All @@ -419,7 +419,7 @@ pub fn idf_wrapped_modules(b: *std.Build) *std.Build.Module {
});
const segger = b.addModule("segger", .{
.root_source_file = .{
.path = b.pathJoin(&.{ src_path, "imports", "segger.zig" }),
.cwd_relative = b.pathJoin(&.{ src_path, "imports", "segger.zig" }),
},
.imports = &.{
.{
Expand All @@ -430,7 +430,7 @@ pub fn idf_wrapped_modules(b: *std.Build) *std.Build.Module {
});
const dsp = b.addModule("dsp", .{
.root_source_file = .{
.path = b.pathJoin(&.{ src_path, "imports", "dsp.zig" }),
.cwd_relative = b.pathJoin(&.{ src_path, "imports", "dsp.zig" }),
},
.imports = &.{
.{
Expand All @@ -441,7 +441,7 @@ pub fn idf_wrapped_modules(b: *std.Build) *std.Build.Module {
});
const crc = b.addModule("crc", .{
.root_source_file = .{
.path = b.pathJoin(&.{ src_path, "imports", "crc.zig" }),
.cwd_relative = b.pathJoin(&.{ src_path, "imports", "crc.zig" }),
},
.imports = &.{
.{
Expand All @@ -452,7 +452,7 @@ pub fn idf_wrapped_modules(b: *std.Build) *std.Build.Module {
});
return b.addModule("esp_idf", .{
.root_source_file = .{
.path = b.pathJoin(&.{ src_path, "imports", "idf.zig" }),
.cwd_relative = b.pathJoin(&.{ src_path, "imports", "idf.zig" }),
},
.imports = &.{
.{
Expand Down
16 changes: 8 additions & 8 deletions imports/version.zig
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
const std = @import("std");

pub const Version = struct {
major: ?u32 = null,
minor: ?u32 = null,
patch: ?u32 = null,
major: ?u32 = 0,
minor: ?u32 = 0,
patch: ?u32 = 0,
pub fn get() Version {
var final_version: Version = .{};
const idf_version = std.mem.span(@import("sys").esp_get_idf_version());

if (!std.mem.startsWith(u8, idf_version, "v"))
return final_version;

var strip = std.mem.split(u8, idf_version, "-");
var it = std.mem.tokenize(u8, strip.first(), ".");
var strip = std.mem.splitScalar(u8, idf_version, '-');
var it = std.mem.tokenizeScalar(u8, strip.first(), '.');

while (it.next()) |token| {
// skip [0] == 'v'
Expand All @@ -23,11 +23,11 @@ pub const Version = struct {
std.fmt.parseUnsigned(u32, token, 10) catch |err|
@panic(@errorName(err));

if (final_version.major == null) {
if (final_version.major == 0) {
final_version.major = digit;
} else if (final_version.minor == null) {
} else if (final_version.minor == 0) {
final_version.minor = digit;
} else if (final_version.patch == null) {
} else if (final_version.patch == 0) {
final_version.patch = digit;
}
}
Expand Down
6 changes: 3 additions & 3 deletions main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ else()
message(FATAL_ERROR "Unsupported platform")
endif()

if(NOT EXISTS "${CMAKE_BINARY_DIR}/zig-${TARGET_ARCH}-relsafe-espressif-${TARGET_PLATFORM}-baseline")
file(DOWNLOAD "https://github.com/kassane/zig-espressif-bootstrap/releases/download/0.12.0-xtensa/zig-${TARGET_ARCH}-espressif-relsafe-${TARGET_PLATFORM}-baseline.${EXT}"
if(NOT EXISTS "${CMAKE_BINARY_DIR}/zig-relsafe-espressif-${TARGET_ARCH}-${TARGET_PLATFORM}-baseline")
file(DOWNLOAD "https://github.com/kassane/zig-espressif-bootstrap/releases/download/0.14.0-xtensa-dev/zig-relsafe-espressif-${TARGET_ARCH}-${TARGET_PLATFORM}-baseline.${EXT}"
"${CMAKE_BINARY_DIR}/zig.${EXT}")

if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
Expand All @@ -60,7 +60,7 @@ if(NOT EXISTS "${CMAKE_BINARY_DIR}/zig-${TARGET_ARCH}-relsafe-espressif-${TARGET
else()
message(STATUS "Zig already downloaded. Skipping zig install.")
endif()
set(ZIG_INSTALL ${CMAKE_BINARY_DIR}/zig-${TARGET_ARCH}-${TARGET_PLATFORM}-baseline)
set(ZIG_INSTALL ${CMAKE_BINARY_DIR}/zig-relsafe-espressif-${TARGET_ARCH}-${TARGET_PLATFORM}-baseline)

if(CONFIG_IDF_TARGET_ARCH_RISCV)
set(ZIG_TARGET "riscv32-freestanding-none")
Expand Down

0 comments on commit 315be3e

Please sign in to comment.