Skip to content

Commit

Permalink
feat: Windows support
Browse files Browse the repository at this point in the history
  • Loading branch information
giann committed Jan 27, 2025
1 parent bf36e8f commit 7b8bab3
Show file tree
Hide file tree
Showing 11 changed files with 416 additions and 293 deletions.
45 changes: 44 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,53 @@
on:
push:
branches: [main]
branches: [main, windows]
pull_request:
branches: [main]

jobs:
test-windows:
runs-on: windows-latest
steps:
- name: Checkout project
uses: actions/[email protected]
- name: Checkout submodules
run: git submodule update --init --recursive
- name: Setup nightly Zig
uses: mlugg/setup-zig@v1
with:
version: master
- name: Build test ffi lib
run: zig build-lib -dynamic tests/utils/foreign.zig && mv foreign.* tests/utils/

- name: Build
run: zig build && ls ./zig-out/lib/buzz

# - name: Run tests Debug
# run: zig build test
# - name: Cleanup
# run: rm -rf zig-out zig-cache
# - name: Run tests Debug with JIT always on
# run: zig build -Djit_always_on test
# - name: Cleanup
# run: rm -rf zig-out zig-cache

# - name: Run tests ReleaseSafe
# run: zig build -Doptimize=ReleaseSafe test
# - name: Cleanup
# run: rm -rf zig-out zig-cache
# - name: Run tests ReleaseSafe with JIT always on
# run: zig build -Doptimize=ReleaseSafe -Djit_always_on test
# - name: Cleanup
# run: rm -rf zig-out zig-cache

# - name: Run tests ReleaseFast
# run: zig build -Doptimize=ReleaseFast test
# - name: Cleanup
# run: rm -rf zig-out zig-cache
# - name: Run tests ReleaseFast with JIT always on
# run: zig build -Doptimize=ReleaseFast -Djit_always_on test
# - name: Cleanup
# run: rm -rf zig-out zig-cache
test-macos:
runs-on: macos-latest
steps:
Expand Down
110 changes: 3 additions & 107 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,109 +1,3 @@
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## User settings
xcuserdata/

## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
*.xcscmblueprint
*.xccheckout

## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
build/
DerivedData/
*.moved-aside
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3

## Obj-C/Swift specific
*.hmap

## App packaging
*.ipa
*.dSYM.zip
*.dSYM

## Playgrounds
timeline.xctimeline
playground.xcworkspace

# Swift Package Manager
#
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
# Packages/
# Package.pins
# Package.resolved
# *.xcodeproj
#
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata
# hence it is not needed unless you have added a package configuration file to your project
# .swiftpm

.build/

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# Pods/
#
# Add this line if you want to avoid checking in source code from the Xcode workspace
# *.xcworkspace

# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts

Carthage/Build/

# Accio dependency management
Dependencies/
.accio/

# fastlane
#
# It is recommended to not store the screenshots in the git repo.
# Instead, use fastlane to re-generate the screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/#source-control

fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots/**/*.png
fastlane/test_output

# Code Injection
#
# After new code Injection tools there's a generated folder /iOSInjectionProject
# https://github.com/johnno1962/injectionforxcode

iOSInjectionProject/

# Extension
node_modules/

# Rust
# Generated by Cargo
# will have compiled files and executables
debug/
target/

# These are backup files generated by rustfmt
**/*.rs.bk

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

# zig
zig-cache/
\.zig-cache/
Expand All @@ -118,5 +12,7 @@ dist/
*.so
*.o

tests/utils/libforeign.*
tests/utils/*foreign.*
buzz_history

node_modules
85 changes: 20 additions & 65 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,10 @@ const BuildOptions = struct {
};
};

fn getBuzzPrefix(b: *Build) ![]const u8 {
return std.posix.getenv("BUZZ_PATH") orelse std.fs.path.dirname(b.exe_dir).?;
}

pub fn build(b: *Build) !void {
var envMap = try std.process.getEnvMap(b.allocator);
defer envMap.deinit();

// Check minimum zig version
const current_zig = builtin.zig_version;
const min_zig = std.SemanticVersion.parse("0.14.0-dev.2851+b074fb7dd") catch return;
Expand All @@ -116,8 +115,8 @@ pub fn build(b: *Build) !void {
.target = target,
.version = std.SemanticVersion{ .major = 0, .minor = 6, .patch = 0 },
// Current commit sha
.sha = std.posix.getenv("GIT_SHA") orelse
std.posix.getenv("GITHUB_SHA") orelse std.mem.trim(
.sha = envMap.get("GIT_SHA") orelse
envMap.get("GITHUB_SHA") orelse std.mem.trim(
u8,
b.run(
&.{
Expand Down Expand Up @@ -264,22 +263,6 @@ pub fn build(b: *Build) !void {

const build_option_module = build_options.step(b);

var sys_libs = std.ArrayList([]const u8).init(b.allocator);
defer sys_libs.deinit();
var includes = std.ArrayList([]const u8).init(b.allocator);
defer includes.deinit();
var llibs = std.ArrayList([]const u8).init(b.allocator);
defer llibs.deinit();

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

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

const lib_pcre2 = if (!is_wasm)
try buildPcre2(b, target, build_mode)
else
Expand All @@ -288,7 +271,7 @@ pub fn build(b: *Build) !void {
try buildMimalloc(b, target, build_mode)
else
null;
const lib_linenoise = if (!is_wasm)
const lib_linenoise = if (!is_wasm and target.result.os.tag != .windows)
try buildLinenoise(b, target, build_mode)
else
null;
Expand Down Expand Up @@ -337,20 +320,6 @@ pub fn build(b: *Build) !void {
}
b.step("run", "run buzz").dependOn(&run_exe.step);

for (includes.items) |include| {
exe.addIncludePath(b.path(include));
exe_check.addIncludePath(b.path(include));
}
for (llibs.items) |lib| {
exe.addLibraryPath(b.path(lib));
exe_check.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
// it's better to built it with Zig's build system
exe.linkSystemLibrary(slib);
exe_check.linkSystemLibrary(slib);
}
if (build_options.needLibC()) {
exe.linkLibC();
exe_check.linkLibC();
Expand All @@ -372,15 +341,6 @@ pub fn build(b: *Build) !void {

b.installArtifact(lib);

for (includes.items) |include| {
lib.addIncludePath(b.path(include));
}
for (llibs.items) |llib| {
lib.addLibraryPath(b.path(llib));
}
for (sys_libs.items) |slib| {
lib.linkSystemLibrary(slib);
}
if (build_options.needLibC()) {
lib.linkLibC();
}
Expand All @@ -392,17 +352,23 @@ pub fn build(b: *Build) !void {

if (lib_pcre2) |pcre| {
lib.linkLibrary(pcre);
exe.linkLibrary(pcre);
}

if (lib_mimalloc) |mimalloc| {
lib.addIncludePath(b.path("vendors/mimalloc/include"));
exe.addIncludePath(b.path("vendors/mimalloc/include"));
lib.linkLibrary(mimalloc);
exe.linkLibrary(mimalloc);
if (lib.root_module.resolved_target.?.result.os.tag == .windows) {
lib.linkSystemLibrary("bcrypt");
exe.linkSystemLibrary("bcrypt");
}
}

if (lib_mir) |mir| {
lib.linkLibrary(mir);
exe.linkLibrary(mir);
}

// So that JIT compiled function can reference buzz_api
Expand Down Expand Up @@ -473,15 +439,6 @@ pub fn build(b: *Build) !void {
artifact.dest_dir = .{ .custom = "lib/buzz" };

// No need to link anything when building for wasm since everything is static
for (includes.items) |include| {
std_lib.addIncludePath(b.path(include));
}
for (llibs.items) |llib| {
std_lib.addLibraryPath(b.path(llib));
}
for (sys_libs.items) |slib| {
std_lib.linkSystemLibrary(slib);
}
if (build_options.needLibC()) {
std_lib.linkLibC();
}
Expand All @@ -491,6 +448,7 @@ pub fn build(b: *Build) !void {
}

if (lib_mimalloc) |mimalloc| {
std_lib.addIncludePath(b.path("vendors/mimalloc/include"));
std_lib.linkLibrary(mimalloc);
if (std_lib.root_module.resolved_target.?.result.os.tag == .windows) {
std_lib.linkSystemLibrary("bcrypt");
Expand All @@ -515,22 +473,14 @@ pub fn build(b: *Build) !void {
.target = target,
.optimize = build_mode,
});
for (includes.items) |include| {
tests.addIncludePath(b.path(include));
}
for (llibs.items) |llib| {
tests.addLibraryPath(b.path(llib));
}
for (sys_libs.items) |slib| {
tests.linkSystemLibrary(slib);
}
if (build_options.needLibC()) {
tests.linkLibC();
}
if (lib_pcre2) |pcre| {
tests.linkLibrary(pcre);
}
if (lib_mimalloc) |mimalloc| {
tests.addIncludePath(b.path("vendors/mimalloc/include"));
tests.linkLibrary(mimalloc);
if (tests.root_module.resolved_target.?.result.os.tag == .windows) {
tests.linkSystemLibrary("bcrypt");
Expand All @@ -544,7 +494,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 = b.path(".");
run_tests.setEnvironmentVariable("BUZZ_PATH", try getBuzzPrefix(b));
run_tests.setEnvironmentVariable("BUZZ_PATH", envMap.get("BUZZ_PATH") orelse std.fs.path.dirname(b.exe_dir).?);
run_tests.step.dependOn(install_step); // wait for libraries to be installed
test_step.dependOn(&run_tests.step);
}
Expand Down Expand Up @@ -757,5 +707,10 @@ pub fn buildMir(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.O
},
);

if (target.result.os.tag == .windows) {
lib.linkSystemLibrary("kernel32");
lib.linkSystemLibrary("psapi");
}

return lib;
}
Loading

0 comments on commit 7b8bab3

Please sign in to comment.