diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index e587092..82e8599 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -2,8 +2,6 @@ Information about what you changed for this PR -## Link to Jira Ticket - ## Test Steps ## After Screenshot(s) diff --git a/.github/workflows/_python-wheels.yml b/.github/workflows/_python-wheels.yml index d85ad9a..09b51ed 100644 --- a/.github/workflows/_python-wheels.yml +++ b/.github/workflows/_python-wheels.yml @@ -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 }} diff --git a/.github/workflows/_release.yml b/.github/workflows/_release.yml index 95be774..9a23f7a 100644 --- a/.github/workflows/_release.yml +++ b/.github/workflows/_release.yml @@ -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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7c5e654..e933b9f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/.gitignore b/.gitignore index 503a502..c3a93b5 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,8 @@ __pycache__ *.so *.dylib *.dll +*.lib +*.pdb # Distribution / packaging .Python diff --git a/README.md b/README.md index a7d03a1..c85c8d9 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/VERSION b/VERSION index 1a03094..0ea3a94 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.9 +0.2.0 diff --git a/build.zig b/build.zig index 4836924..20188da 100644 --- a/build.zig +++ b/build.zig @@ -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; @@ -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(); @@ -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.?); } @@ -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", diff --git a/python/make_wheels.py b/python/make_wheels.py index c21b3db..8e87b45 100644 --- a/python/make_wheels.py +++ b/python/make_wheels.py @@ -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() @@ -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) @@ -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: @@ -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, diff --git a/python/pyproject.toml b/python/pyproject.toml index 6612912..bc31a70 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -2,5 +2,5 @@ requires = [ "setuptools", "wheel", - "ziglang==0.9.1" + "ziglang==0.11.0" ] diff --git a/python/requirements-dev.txt b/python/requirements-dev.txt index 3ffdb58..c5c546a 100644 --- a/python/requirements-dev.txt +++ b/python/requirements-dev.txt @@ -7,5 +7,5 @@ pytest-xdist pytest-mock black isort -ziglang==0.9.1 +ziglang==0.11.0 -e . \ No newline at end of file diff --git a/python/setup.py b/python/setup.py index dbc2459..36371fe 100644 --- a/python/setup.py +++ b/python/setup.py @@ -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() @@ -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 @@ -46,7 +49,6 @@ def finalize_options(self): _bdist_wheel.finalize_options(self) self.root_is_pure = False - except ImportError: bdist_wheel = None diff --git a/python/src/fastfec/utils.py b/python/src/fastfec/utils.py index fca0370..5f32242 100644 --- a/python/src/fastfec/utils.py +++ b/python/src/fastfec/utils.py @@ -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") @@ -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 diff --git a/python/tox.ini b/python/tox.ini index f628607..b7df8cd 100644 --- a/python/tox.ini +++ b/python/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist=py{3} +envlist=py{3.11} skipsdist=True [base] diff --git a/src/main.c b/src/main.c index 2c32d15..972599c 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,7 @@ #include "encoding.h" #include "fec.h" #include "cli.h" +#include #define BUFFERSIZE 65536