Skip to content

Commit

Permalink
chore: zig 0.13.0-dev.211+6a65561e3
Browse files Browse the repository at this point in the history
  • Loading branch information
giann committed May 16, 2024
1 parent 7e2636f commit 90ce7d1
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 114 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ A small/lightweight statically typed scripting language written in Zig

## How to build and install

_Latest zig version supported: 0.13.0-dev.73+db890dbae_
_Latest zig version supported: 0.13.0-dev.211+6a65561e3_

### Requirements
- Since this is built with Zig, you should be able to build buzz on a wide variety of architectures even though this has only been tested on x86/M1.
Expand Down
135 changes: 39 additions & 96 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ fn getBuzzPrefix(b: *Build) ![]const u8 {
pub fn build(b: *Build) !void {
// Check minimum zig version
const current_zig = builtin.zig_version;
const min_zig = std.SemanticVersion.parse("0.13.0-dev.73+db890dbae") catch return;
const min_zig = std.SemanticVersion.parse("0.13.0-dev.211+6a65561e3") catch return;
if (current_zig.order(min_zig).compare(.lt)) {
@panic(b.fmt("Your Zig version v{} does not meet the minimum build requirement of v{}", .{ current_zig, min_zig }));
}
Expand Down Expand Up @@ -273,15 +273,11 @@ pub fn build(b: *Build) !void {
}

includes.appendSlice(&[_][]const u8{
"/usr/local/include",
"/usr/include",
"./vendors/mir",
"./vendors/mimalloc/include",
}) catch unreachable;

llibs.appendSlice(&[_][]const u8{
"/usr/local/lib",
"/usr/lib",
"./vendors/mir",
}) catch unreachable;

Expand All @@ -298,33 +294,9 @@ pub fn build(b: *Build) !void {
else
null;

// If macOS, add homebrew paths
if (builtin.os.tag == .macos) {
const result = std.ChildProcess.run(
.{
.allocator = b.allocator,
.argv = &[_][]const u8{ "brew", "--prefix" },
},
) catch null;

const prefix = if (result) |r|
std.mem.trim(u8, r.stdout, "\n")
else
std.posix.getenv("HOMEBREW_PREFIX") orelse "/opt/homebrew";

var include = std.ArrayList(u8).init(b.allocator);
include.writer().print("{s}{s}include", .{ prefix, std.fs.path.sep_str }) catch unreachable;

var lib = std.ArrayList(u8).init(b.allocator);
lib.writer().print("{s}{s}lib", .{ prefix, std.fs.path.sep_str }) catch unreachable;

includes.append(include.items) catch unreachable;
llibs.append(lib.items) catch unreachable;
}

var exe = b.addExecutable(.{
.name = "buzz",
.root_source_file = .{ .path = "src/main.zig" },
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = build_mode,
});
Expand All @@ -349,10 +321,10 @@ pub fn build(b: *Build) !void {
b.step("run", "run buzz").dependOn(&run_exe.step);

for (includes.items) |include| {
exe.addIncludePath(.{ .path = include });
exe.addIncludePath(b.path(include));
}
for (llibs.items) |lib| {
exe.addLibraryPath(.{ .path = lib });
exe.addLibraryPath(b.path(lib));
}
for (sys_libs.items) |slib| {
// FIXME: if mir is linked as static library (libmir.a), here also need to link libc
Expand All @@ -367,20 +339,22 @@ pub fn build(b: *Build) !void {

if (!is_wasm) {
// Building buzz api library
var lib = b.addSharedLibrary(.{
.name = "buzz",
.root_source_file = .{ .path = "src/buzz_api.zig" },
.target = target,
.optimize = build_mode,
});
var lib = b.addSharedLibrary(
.{
.name = "buzz",
.root_source_file = b.path("src/buzz_api.zig"),
.target = target,
.optimize = build_mode,
},
);

b.installArtifact(lib);

for (includes.items) |include| {
lib.addIncludePath(.{ .path = include });
lib.addIncludePath(b.path(include));
}
for (llibs.items) |llib| {
lib.addLibraryPath(.{ .path = llib });
lib.addLibraryPath(b.path(llib));
}
for (sys_libs.items) |slib| {
lib.linkSystemLibrary(slib);
Expand All @@ -403,6 +377,7 @@ pub fn build(b: *Build) !void {
lib.linkSystemLibrary("bcrypt");
}
}

// So that JIT compiled function can reference buzz_api
exe.linkLibrary(lib);
if (lib_linenoise) |ln| {
Expand Down Expand Up @@ -440,8 +415,16 @@ pub fn build(b: *Build) !void {
for (libraries) |library| {
// Copy buzz definitions
const step = b.addInstallLibFile(
.{ .path = b.fmt("src/lib/{s}.buzz", .{library.name}) },
b.fmt("buzz/{s}.buzz", .{library.name}),
b.path(
b.fmt(
"src/lib/{s}.buzz",
.{library.name},
),
),
b.fmt(
"buzz/{s}.buzz",
.{library.name},
),
);
install_step.dependOn(&step.step);

Expand All @@ -451,7 +434,7 @@ pub fn build(b: *Build) !void {

var std_lib = b.addSharedLibrary(.{
.name = library.name,
.root_source_file = .{ .path = library.path.? },
.root_source_file = b.path(library.path.?),
.target = target,
.optimize = build_mode,
});
Expand All @@ -462,10 +445,10 @@ pub fn build(b: *Build) !void {

// No need to link anything when building for wasm since everything is static
for (includes.items) |include| {
std_lib.addIncludePath(.{ .path = include });
std_lib.addIncludePath(b.path(include));
}
for (llibs.items) |llib| {
std_lib.addLibraryPath(.{ .path = llib });
std_lib.addLibraryPath(b.path(llib));
}
for (sys_libs.items) |slib| {
std_lib.linkSystemLibrary(slib);
Expand All @@ -487,33 +470,22 @@ pub fn build(b: *Build) !void {
std_lib.linkLibrary(lib);
std_lib.root_module.addImport("build_options", build_option_module);

// Adds `$BUZZ_PATH/lib` and `/usr/local/lib/buzz` as search path for other shared lib referenced by this one (libbuzz.dylib most of the time)
std_lib.addRPath(
.{
.path = b.fmt(
"{s}" ++ std.fs.path.sep_str ++ "lib/buzz",
.{try getBuzzPrefix(b)},
),
},
);
std_lib.addRPath(.{ .path = "/usr/local/lib/buzz" });

b.default_step.dependOn(&std_lib.step);

library_steps.append(std_lib) catch unreachable;
}
}

const tests = b.addTest(.{
.root_source_file = .{ .path = "src/main.zig" },
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = build_mode,
});
for (includes.items) |include| {
tests.addIncludePath(.{ .path = include });
tests.addIncludePath(b.path(include));
}
for (llibs.items) |llib| {
tests.addLibraryPath(.{ .path = llib });
tests.addLibraryPath(b.path(llib));
}
for (sys_libs.items) |slib| {
tests.linkSystemLibrary(slib);
Expand All @@ -534,7 +506,7 @@ pub fn build(b: *Build) !void {

const test_step = b.step("test", "Run all the tests");
const run_tests = b.addRunArtifact(tests);
run_tests.cwd = Build.LazyPath{ .path = "." };
run_tests.cwd = b.path(".");
run_tests.setEnvironmentVariable("BUZZ_PATH", try getBuzzPrefix(b));
run_tests.step.dependOn(install_step); // wait for libraries to be installed
test_step.dependOn(&run_tests.step);
Expand All @@ -547,15 +519,15 @@ pub fn build(b: *Build) !void {
pub fn buildPcre2(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) !*Build.Step.Compile {
const copyFiles = b.addWriteFiles();
copyFiles.addCopyFileToSource(
.{ .path = "vendors/pcre2/src/config.h.generic" },
b.path("vendors/pcre2/src/config.h.generic"),
"vendors/pcre2/src/config.h",
);
copyFiles.addCopyFileToSource(
.{ .path = "vendors/pcre2/src/pcre2.h.generic" },
b.path("vendors/pcre2/src/pcre2.h.generic"),
"vendors/pcre2/src/pcre2.h",
);
copyFiles.addCopyFileToSource(
.{ .path = "vendors/pcre2/src/pcre2_chartables.c.dist" },
b.path("vendors/pcre2/src/pcre2_chartables.c.dist"),
"vendors/pcre2/src/pcre2_chartables.c",
);

Expand All @@ -564,7 +536,7 @@ pub fn buildPcre2(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin
.target = target,
.optimize = optimize,
});
lib.addIncludePath(.{ .path = "src" });
lib.addIncludePath(b.path("src"));
lib.addCSourceFiles(
.{
.files = &.{
Expand Down Expand Up @@ -619,38 +591,9 @@ pub fn buildMimalloc(b: *Build, target: Build.ResolvedTarget, optimize: std.buil
},
);

lib.addIncludePath(.{ .path = "./vendors/mimalloc/include" });
lib.addIncludePath(b.path("./vendors/mimalloc/include"));
lib.linkLibC();

if (lib.root_module.resolved_target.?.result.os.tag == .macos) {
var macOS_sdk_path = std.ArrayList(u8).init(b.allocator);
try macOS_sdk_path.writer().print(
"{s}/usr/include",
.{
(std.ChildProcess.run(.{
.allocator = b.allocator,
.argv = &.{
"xcrun",
"--show-sdk-path",
},
.cwd = b.pathFromRoot("."),
.expand_arg0 = .expand,
}) catch {
std.debug.print("Warning: failed to get MacOSX sdk path", .{});
unreachable;
}).stdout,
},
);

lib.addSystemIncludePath(.{ .path = macOS_sdk_path.items });
// Github macos-12 runner (https://github.com/actions/runner-images/blob/main/images/macos/macos-12-Readme.md).
lib.addSystemIncludePath(.{ .path = "/Applications/Xcode_14.0.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include" });
lib.addSystemIncludePath(.{ .path = "/Library/Developer/CommandLineTools/SDKs/MacOSX14.0.sdk/usr/include" });
lib.addSystemIncludePath(.{ .path = "/Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk/usr/include" });
lib.addSystemIncludePath(.{ .path = "/Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk/usr/include" });
lib.addSystemIncludePath(.{ .path = "/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/include" });
}

lib.addCSourceFiles(
.{
.files = &.{
Expand Down Expand Up @@ -690,7 +633,7 @@ pub fn buildLinenoise(b: *Build, target: Build.ResolvedTarget, optimize: std.bui
.optimize = optimize,
});

lib.addIncludePath(.{ .path = "vendors/linenoise" });
lib.addIncludePath(b.path("vendors/linenoise"));
lib.addCSourceFiles(
.{
.files = &.{
Expand Down Expand Up @@ -738,7 +681,7 @@ pub fn buildWasmReplDemo(b: *Build, exe: *Build.Step.Compile) void {
b.getInstallStep().dependOn(&esbuild.step);

const copyRepl = b.addInstallBinFile(
.{ .path = "src/repl.html" },
b.path("src/repl.html"),
"repl.html",
);
b.getInstallStep().dependOn(&copyRepl.step);
Expand Down
31 changes: 14 additions & 17 deletions src/Parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5017,18 +5017,17 @@ fn function(
const generic_identifier_token = self.current_token.? - 1;
const generic_identifier = try self.gc.copyString(self.ast.tokens.items(.lexeme)[generic_identifier_token]);
if ((self.current.?.generics == null or self.current.?.generics.?.get(generic_identifier) == null) and (self.current_object == null or self.current_object.?.generics == null or self.current_object.?.generics.?.get(generic_identifier) == null)) {
const generic = obj.ObjTypeDef.GenericDef{
.origin = self.ast.nodes.items(.type_def)[function_node].?.resolved_type.?.Function.id,
.index = i,
};
const resolved_type = obj.ObjTypeDef.TypeUnion{ .Generic = generic };

try function_typedef.resolved_type.?.Function.generic_types.put(
generic_identifier,
try self.gc.type_registry.getTypeDef(
obj.ObjTypeDef{
.def_type = .Generic,
.resolved_type = resolved_type,
.resolved_type = .{
.Generic = .{
.origin = self.ast.nodes.items(.type_def)[function_node].?.resolved_type.?.Function.id,
.index = i,
},
},
},
),
);
Expand Down Expand Up @@ -6454,19 +6453,17 @@ fn protocolDeclaration(self: *Self) Error!Ast.Node.Index {
const placeholder_index = try self.declarePlaceholder(protocol_name, null);
const protocol_placeholder = self.globals.items[placeholder_index].type_def;

const protocol_def = obj.ObjObject.ProtocolDef.init(
self.gc.allocator,
self.ast.tokens.get(protocol_name),
try self.gc.copyString(self.ast.tokens.items(.lexeme)[protocol_name]),
try self.gc.copyString(qualified_protocol_name.items),
);

const resolved_type = obj.ObjTypeDef.TypeUnion{ .Protocol = protocol_def };

// Create type
var protocol_type: obj.ObjTypeDef = .{
.def_type = .Protocol,
.resolved_type = resolved_type,
.resolved_type = .{
.Protocol = obj.ObjObject.ProtocolDef.init(
self.gc.allocator,
self.ast.tokens.get(protocol_name),
try self.gc.copyString(self.ast.tokens.items(.lexeme)[protocol_name]),
try self.gc.copyString(qualified_protocol_name.items),
),
},
};

try self.beginScope(null);
Expand Down
1 change: 1 addition & 0 deletions src/Token.zig
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ pub const Type = enum {
Range, // range
};

// FIXME if case had the same name as the actual token we could simply use @tagName
pub const keywords = std.StaticStringMap(Type).initComptime(
.{
.{ "and", .And },
Expand Down

0 comments on commit 90ce7d1

Please sign in to comment.