Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: zig 0.11 #62

Merged
merged 23 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7b2628c
build.zig: enable headerpad_max_install_names on MacOs
iMichka Feb 14, 2023
6594115
Updated for changes to zig build system in version 11
jmlchristensen-post Dec 11, 2023
4f315a9
add back preferred optimize mode
jmlchristensen-post Dec 11, 2023
7602c32
change wasm os target to freestanding to fix missing main symbol error
jmlchristensen-post Dec 12, 2023
66aa897
Merge branch 'fix/headerpad_max_install' into fix/zig
freedmand Feb 25, 2024
1d36fb1
feat: update zig version in github actions workflows
freedmand Feb 25, 2024
bba4ec8
chore: remove jira ticket from template
freedmand Feb 25, 2024
86072bb
chore: std=gnu99
freedmand Feb 25, 2024
d5449af
chore: unistd for isatty
freedmand Feb 25, 2024
995be7d
chore: include unistd always
freedmand Feb 25, 2024
8060984
chore: pin python version, update wheel
freedmand Feb 25, 2024
72586f0
chore: attempt to fix python wheel
freedmand Feb 25, 2024
f28ee47
chore: remove reproducible wheel
freedmand Feb 25, 2024
356c76c
chore: os-specific python setup
freedmand Feb 26, 2024
29bf75c
chore: log lib
freedmand Feb 26, 2024
f6d2bae
chore: blanket ls
freedmand Feb 26, 2024
7716f1f
chore: zig cache ls
freedmand Feb 26, 2024
837658b
chore: add verbosity
freedmand Feb 26, 2024
de22697
fix: update zig in requirements-dev
freedmand Feb 26, 2024
407b975
chore: zig 0.11.0 everywhere else
freedmand Feb 26, 2024
3a46dc2
chore: revert setup change
freedmand Feb 26, 2024
7bb7271
chore: remove test cmds from workflow
freedmand Feb 26, 2024
5744de2
chore: 3.11
freedmand Feb 28, 2024
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
2 changes: 0 additions & 2 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

Information about what you changed for this PR

## Link to Jira Ticket

## Test Steps

## After Screenshot(s)
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/_python-wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: "3.x"
python-version: "3.11"

- name: Install Zig
run: python -m pip install ziglang==0.9.1 wheel==0.37.1
run: python -m pip install ziglang==0.11.0 wheel

- name: Build wheels
run: python python/make_wheels.py ${{ matrix.architecture }}-${{ matrix.os }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- uses: actions/checkout@v2
- uses: goto-bus-stop/setup-zig@v1
with:
version: 0.9.1
version: 0.11.0
- name: Get output paths
uses: kanga333/variable-mapper@master
id: map
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
- uses: actions/checkout@v2
- uses: goto-bus-stop/setup-zig@v1
with:
version: 0.9.1
version: 0.11.0
- name: Run zig test
run: zig build test

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ __pycache__
*.so
*.dylib
*.dll
*.lib
*.pdb

# Distribution / packaging
.Python
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ The following was performed on an M1 Macbook Air:

### Build system

[Zig](https://ziglang.org/) is used to build and compile the project. Download and install the latest version of Zig (>=0.9.1) by following the instructions on the website (you can verify it's working by typing `zig` in the terminal and seeing help commands).
[Zig](https://ziglang.org/) is used to build and compile the project. Download and install the latest version of Zig (>=0.11.0) by following the instructions on the website (you can verify it's working by typing `zig` in the terminal and seeing help commands).

### Dependencies

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.9
0.2.0
67 changes: 47 additions & 20 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@ pub fn linkPcre(vendored_pcre: bool, libExe: *std.build.LibExeObjStep) void {
libExe.linkSystemLibrary("libpcre");
}
}
if (libExe.target.isDarwin()) {
// useful for package maintainers
// see https://github.com/ziglang/zig/issues/13388
libExe.headerpad_max_install_names = true;
}
}

pub fn build(b: *std.build.Builder) !void {
b.setPreferredReleaseMode(.ReleaseFast);
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const mode = b.standardReleaseOptions();
const optimize = b.standardOptimizeOption(.{
.preferred_optimize_mode = .ReleaseFast,
});

const lib_only: bool = b.option(bool, "lib-only", "Only compile the library") orelse false;
const skip_lib: bool = b.option(bool, "skip-lib", "Skip compiling the library") orelse false;
Expand All @@ -26,10 +32,11 @@ pub fn build(b: *std.build.Builder) !void {

// Main build step
if (!lib_only and !wasm) {
const fastfec_cli = b.addExecutable("fastfec", null);
fastfec_cli.setTarget(target);
fastfec_cli.setBuildMode(mode);
fastfec_cli.install();
const fastfec_cli = b.addExecutable(.{
.name = "fastfec",
.target = target,
.optimize = optimize,
});

fastfec_cli.linkLibC();

Expand All @@ -39,40 +46,59 @@ pub fn build(b: *std.build.Builder) !void {
"src/cli.c",
"src/main.c",
}, &buildOptions);
b.installArtifact(fastfec_cli);
}

if (!wasm and !skip_lib) {
// Library build step
const fastfec_lib = b.addSharedLibrary("fastfec", null, .unversioned);
fastfec_lib.setTarget(target);
fastfec_lib.setBuildMode(mode);
fastfec_lib.install();
const fastfec_lib = b.addSharedLibrary(.{
.name = "fastfec",
.target = target,
.optimize = optimize,
.version = null,
});
if (fastfec_lib.target.isDarwin()) {
// useful for package maintainers
// see https://github.com/ziglang/zig/issues/13388
fastfec_lib.headerpad_max_install_names = true;
}
fastfec_lib.linkLibC();
fastfec_lib.addCSourceFiles(&libSources, &buildOptions);
linkPcre(vendored_pcre, fastfec_lib);
b.installArtifact(fastfec_lib);
} else if (wasm) {
// Wasm library build step
const fastfec_wasm = b.addSharedLibrary("fastfec", null, .unversioned);
const wasm_target = CrossTarget{ .cpu_arch = .wasm32, .os_tag = .wasi };
fastfec_wasm.setTarget(wasm_target);
fastfec_wasm.setBuildMode(mode);
fastfec_wasm.install();
const wasm_target = CrossTarget{ .cpu_arch = .wasm32, .os_tag = .freestanding };
const fastfec_wasm = b.addSharedLibrary(.{
.name = "fastfec",
.target = wasm_target,
.optimize = optimize,
.version = null,
});
fastfec_wasm.linkLibC();
fastfec_wasm.addCSourceFiles(&libSources, &buildOptions);
linkPcre(vendored_pcre, fastfec_wasm);
fastfec_wasm.addCSourceFile("src/wasm.c", &buildOptions);
fastfec_wasm.addCSourceFile(.{ .file = .{
.path = "src/wasm.c",
}, .flags = &buildOptions });
b.installArtifact(fastfec_wasm);
}

// Test step
var prev_test_step: ?*std.build.Step = null;
for (tests) |test_file| {
const base_file = std.fs.path.basename(test_file);
const subtest_exe = b.addExecutable(base_file, null);
const subtest_exe = b.addExecutable(.{
.name = base_file,
});
subtest_exe.linkLibC();
subtest_exe.addCSourceFiles(&testIncludes, &buildOptions);
linkPcre(vendored_pcre, subtest_exe);
subtest_exe.addCSourceFile(test_file, &buildOptions);
const subtest_cmd = subtest_exe.run();
subtest_exe.addCSourceFile(.{
.file = .{ .path = test_file },
.flags = &buildOptions,
});
const subtest_cmd = b.addRunArtifact(subtest_exe);
if (prev_test_step != null) {
subtest_cmd.step.dependOn(prev_test_step.?);
}
Expand Down Expand Up @@ -119,6 +145,7 @@ const testIncludes = [_][]const u8{ "src/buffer.c", "src/memory.c", "src/encodin
const buildOptions = [_][]const u8{
"-std=c11",
"-pedantic",
"-std=gnu99",
"-Wall",
"-W",
"-Wno-missing-field-initializers",
Expand Down
21 changes: 5 additions & 16 deletions python/make_wheels.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,6 @@
version = f.read().strip()


class ReproducibleWheelFile(WheelFile):
# Copied from Zig make_wheels.py
def writestr(self, zinfo, *args, **kwargs):
if not isinstance(zinfo, ZipInfo):
raise ValueError("ZipInfo required")
zinfo.date_time = time.gmtime(time.time())[0:6] # Current time
zinfo.create_system = 3
super().writestr(zinfo, *args, **kwargs)


def make_message(headers, payload=None):
# Copied from Zig make_wheels.py
msg = EmailMessage()
Expand All @@ -72,8 +62,7 @@ def make_message(headers, payload=None):


def write_wheel_file(filename, contents):
# Copied from Zig make_wheels.py
with ReproducibleWheelFile(filename, "w") as wheel:
with WheelFile(filename, "w") as wheel:
for member_info, member_source in contents.items():
if not isinstance(member_info, ZipInfo):
member_info = ZipInfo(member_info)
Expand Down Expand Up @@ -118,9 +107,9 @@ def write_wheel(out_dir, *, name, version, tag, metadata, description, contents)
for path in glob(os.path.join(SRC_DIR, "*.py"), recursive=True):
with open(path, "rb") as f:
file_contents = f.read()
base_contents[
os.path.join(PACKAGE_NAME, os.path.relpath(path, SRC_DIR))
] = file_contents
base_contents[os.path.join(PACKAGE_NAME, os.path.relpath(path, SRC_DIR))] = (
file_contents
)

current_platform = platform.system()
for target_platform, zig_target, wheel_platform in matrix:
Expand All @@ -129,7 +118,7 @@ def write_wheel(out_dir, *, name, version, tag, metadata, description, contents)
# First clear the target directory of any stray files
if os.path.exists(LIBRARY_DIR):
shutil.rmtree(LIBRARY_DIR)
# Compile! Requires ziglang==0.9.1 to be installed
# Compile! Requires ziglang==0.11.0 to be installed
subprocess.call(
[
sys.executable,
Expand Down
2 changes: 1 addition & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
requires = [
"setuptools",
"wheel",
"ziglang==0.9.1"
"ziglang==0.11.0"
]
2 changes: 1 addition & 1 deletion python/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ pytest-xdist
pytest-mock
black
isort
ziglang==0.9.1
ziglang==0.11.0
-e .
8 changes: 5 additions & 3 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@


def compile_library():
subprocess.call([sys.executable, "-m", "ziglang", "build", "-Dlib-only=true"], cwd=PARENT_DIR)
subprocess.call(
[sys.executable, "-m", "ziglang", "build", "-Dlib-only=true"], cwd=PARENT_DIR
)


compile_library()
Expand All @@ -33,7 +35,8 @@ def compile_library():
)
# Copy them into the Python project src directory and get their relative paths
library_files = [
os.path.basename(shutil.copy(library_file, os.path.join(CURRENT_DIR, "src"))) for library_file in raw_library_files
os.path.basename(shutil.copy(library_file, os.path.join(CURRENT_DIR, "src")))
for library_file in raw_library_files
]

# Force building a non-pure lib wheel
Expand All @@ -46,7 +49,6 @@ def finalize_options(self):
_bdist_wheel.finalize_options(self)
self.root_is_pure = False


except ImportError:
bdist_wheel = None

Expand Down
15 changes: 13 additions & 2 deletions python/src/fastfec/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@
import logging
import os
import pathlib
from ctypes import CFUNCTYPE, POINTER, c_char, c_char_p, c_int, c_size_t, c_void_p, memmove
from ctypes import (
CFUNCTYPE,
POINTER,
c_char,
c_char_p,
c_int,
c_size_t,
c_void_p,
memmove,
)
from glob import glob

logger = logging.getLogger("fastfec")
Expand Down Expand Up @@ -216,7 +225,9 @@ def write_callback(filename, extension, contents, num_bytes):
file_descriptor = write_cache.file_descriptors.get(path)
if not file_descriptor:
# Open the file
write_cache.file_descriptors[path] = open_function(path.decode("utf8"), mode="wb")
write_cache.file_descriptors[path] = open_function(
path.decode("utf8"), mode="wb"
)
file_descriptor = write_cache.file_descriptors[path]
write_cache.last_filename = filename
write_cache.last_fd = file_descriptor
Expand Down
2 changes: 1 addition & 1 deletion python/tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist=py{3}
envlist=py{3.10}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this want to be py{3.11}?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks!

skipsdist=True

[base]
Expand Down
1 change: 1 addition & 0 deletions src/main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "encoding.h"
#include "fec.h"
#include "cli.h"
#include <unistd.h>

#define BUFFERSIZE 65536

Expand Down
Loading