diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..357fb0bcc --- /dev/null +++ b/.editorconfig @@ -0,0 +1,25 @@ +root = true + +[*] +charset = utf-8 +indent_size = 4 +indent_style = space +insert_final_newline = true +max_line_length = 120 +tab_width = 4 +trim_trailing_whitespace = true + +[*.json] +indent_size = 2 + +[*.jsonc] +indent_size = 2 + +[*.vsconfig] +indent_size = 2 + +[*.yaml] +indent_size = 2 + +[*.yml] +indent_size = 2 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..32eaedaca --- /dev/null +++ b/.gitattributes @@ -0,0 +1,7 @@ +* text +*.verified.* text eol=lf +*.ico binary +*.pdf binary +*.png binary +*.zig eol=lf +*.zon eol=lf diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 000000000..3233e4f3b --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @vezel-dev/graf-maintainers diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 000000000..7238bcd91 --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,12 @@ +# Contributing + +This repository is a fork that only makes build system changes. As such, most +issues and pull requests should be directed +[upstream](https://github.com/libffi/libffi). That said, if your issue or pull +request is related to our fork's build system changes, then please see +[our organization contribution guide](https://github.com/vezel-dev/.github/blob/master/CONTRIBUTING.md). + +Please note that, if you send a pull request and it is merged, it is quite +likely that the record of your contribution will be lost, even though the change +itself is kept. This happens because we rebase the `master` branch periodically +and try to keep the number of commits on top of upstream to a minimum. diff --git a/.github/SECURITY.md b/.github/SECURITY.md new file mode 100644 index 000000000..75b20edb9 --- /dev/null +++ b/.github/SECURITY.md @@ -0,0 +1,7 @@ +# Security + +This repository is a fork that only makes build system changes. As such, most +security issues should be directed [upstream](https://github.com/libffi/libffi). +That said, if you wish to report a security issue that is related to our fork's +build system changes, then please see +[our organization security policy](https://github.com/vezel-dev/.github/security/policy). diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 000000000..82b6d5757 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +# yaml-language-server: $schema=https://json.schemastore.org/dependabot-2.0.json +version: 2 +updates: + - package-ecosystem: nuget + directories: + - / + schedule: + interval: daily + timezone: Europe/Copenhagen + time: "12:00" + open-pull-requests-limit: 25 + labels: [] diff --git a/.markdownlint.json b/.markdownlint.json new file mode 100644 index 000000000..a6b660094 --- /dev/null +++ b/.markdownlint.json @@ -0,0 +1,95 @@ +{ + "$schema": "https://raw.githubusercontent.com/DavidAnson/markdownlint/main/schema/markdownlint-config-schema.json", + "default": true, + "MD001": true, + "MD003": { + "style": "atx" + }, + "MD004": { + "style": "asterisk" + }, + "MD005": true, + "MD007": { + "start_indented": false, + "start_indent": 4, + "indent": 4 + }, + "MD009": { + "br_spaces": 0, + "strict": true + }, + "MD010": { + "spaces_per_tab": 4 + }, + "MD011": true, + "MD012": true, + "MD013": { + "code_blocks": false, + "headings": false, + "tables": false + }, + "MD014": true, + "MD018": true, + "MD019": true, + "MD020": true, + "MD021": true, + "MD022": true, + "MD023": true, + "MD024": true, + "MD025": true, + "MD026": { + "punctuation": "!,.:;?" + }, + "MD027": true, + "MD028": true, + "MD029": { + "style": "ordered" + }, + "MD030": true, + "MD031": true, + "MD032": true, + "MD033": { + "allowed_elements": [ + "div", + "img", + "p", + "strong" + ] + }, + "MD034": true, + "MD035": { + "style": "--------------------------------------------------------------------------------" + }, + "MD036": { + "punctuation": "!,.:;?" + }, + "MD037": true, + "MD038": true, + "MD039": true, + "MD040": { + "language_only": true + }, + "MD041": true, + "MD042": true, + "MD043": false, + "MD044": true, + "MD045": true, + "MD046": { + "style": "fenced" + }, + "MD047": true, + "MD048": { + "style": "backtick" + }, + "MD049": { + "style": "asterisk" + }, + "MD050": { + "style": "asterisk" + }, + "MD051": true, + "MD052": true, + "MD053": { + "ignored_definitions": [] + } +} diff --git a/.netconfig b/.netconfig new file mode 100644 index 000000000..3ebcbcb58 --- /dev/null +++ b/.netconfig @@ -0,0 +1,15 @@ +[file ".editorconfig"] + url = https://github.com/vezel-dev/.github/blob/master/syn/.editorconfig + sha = 25cfbb6a508a9fcf8444ef283ddfe7b2e5121bca + etag = df90691e6bc4d301e82e508fca55eed234028a335c3615cf916db00cb4a053f1 + weak +[file ".gitattributes"] + url = https://github.com/vezel-dev/.github/blob/master/syn/.gitattributes + sha = 0ff05334db6d820dd16428e1aad477ed83ca10ef + etag = 0a6a1f6373760bc1c03e09e1efeeb77109705f11b159afd759e11550b45ee950 + weak +[file ".markdownlint.json"] + url = https://github.com/vezel-dev/.github/blob/master/syn/.markdownlint.json + sha = 7d581ae5eedad5892855cebc673edafad664856b + etag = cf98ac95cf318b52e206b9003e342de9db2ecb7be062eab6edf1681b1f374b3a + weak diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 000000000..315482040 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,14 @@ +{ + "recommendations": [ + "chdsbd.github-code-owners", + "codezombiech.gitignore", + "davidanson.vscode-markdownlint", + "editorconfig.editorconfig", + "github.vscode-github-actions", + "github.vscode-pull-request-github", + "llvm-vs-code-extensions.vscode-clangd", + "redhat.vscode-yaml", + "yy0931.gitconfig-lsp", + "ziglang.vscode-zig" + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..bbe02d0aa --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "files.exclude": { + ".zig-cache": true, + "zig-out": true + } +} diff --git a/README.md b/README.md new file mode 100644 index 000000000..b445a0cb4 --- /dev/null +++ b/README.md @@ -0,0 +1,114 @@ +# Vezel libffi Fork + +This is a friendly fork of [libffi](https://sourceware.org/libffi). The notable +change made in this fork is the addition of a [Zig](https://ziglang.org) build +script, making it easy to integrate libffi into Zig projects using the Zig +package manager. Additionally, to reduce the package download size, we have +removed a large number of files that are unnecessary when using libffi in a Zig +project. Importantly, **all library source code is identical to upstream**, so +in terms of API/ABI compatibility, using this fork is no different from linking +to a system libffi package. + +## Usage + +The minimum Zig version supported by this project can be found in the +`minimum_zig_version` field of the [`build.zig.zon`](build.zig.zon) file. We +generally try to track the latest release of Zig. + +Please note that the `master` branch is rebased on top of upstream periodically. +**You should use a release tag rather than `master`.** For example: + +```bash +zig fetch --save=ffi https://github.com/vezel-dev/libffi/archive/vX.Y.Z-B.tar.gz +# Or, to use Git: +zig fetch --save=ffi git+https://github.com/vezel-dev/libffi.git#vX.Y.Z-B +``` + +(You can find the latest version on the +[releases page](https://github.com/vezel-dev/libffi/releases).) + +Then, consume the library in your `build.zig`: + +```zig +const ffi = b.dependency("ffi", .{ + .target = target, + .optimize = optimize, +}); +exe.linkLibrary(ffi.artifact("ffi")); + +// Or, if you want to be able to integrate with a system package: +if (b.systemIntegrationOption("ffi", .{})) { + exe.linkSystemLibrary("ffi"); +} else { + const ffi = b.dependency("ffi", .{ + .target = target, + .optimize = optimize, + }); + exe.linkLibrary(ffi.artifact("ffi")); +} +``` + +You can then use the C header in your Zig code: + +```zig +const builtin = @import("builtin"); +const std = @import("std"); +const stdio = @cImport(@cInclude("stdio.h")); +const ffi = @cImport(@cInclude("ffi.h")); + +pub fn main() !void { + std.debug.print("Calling C puts() on {s}.\n", .{builtin.cpu.arch.genericName()}); + + var cif: ffi.ffi_cif = undefined; + var params = [_]?*ffi.ffi_type{ + &ffi.ffi_type_pointer, + }; + + switch (ffi.ffi_prep_cif( + &cif, + ffi.FFI_DEFAULT_ABI, + params.len, + &ffi.ffi_type_sint32, + params[0..params.len], + )) { + ffi.FFI_OK => {}, + else => |e| return switch (e) { + ffi.FFI_BAD_TYPEDEF => error.BadTypeDefinition, + ffi.FFI_BAD_ABI => error.BadAbi, + ffi.FFI_BAD_ARGTYPE => error.BadArgumentType, + else => unreachable, + }, + } + + var result: ffi.ffi_arg = undefined; + var args = [params.len]?*anyopaque{ + @ptrCast(@constCast(&"Hello World")), + }; + + ffi.ffi_call(&cif, @ptrCast(&stdio.puts), &result, args[0..args.len]); + + if (result == stdio.EOF) + return error.IOError; +} +``` + +And finally: + +```console +$ zig build run +Calling C puts() on x86. +Hello World +``` + +Cross-compilation works too: + +```console +$ zig build run -fqemu -Dtarget=aarch64-linux +Calling C puts() on aarch64. +Hello World +``` + +## License + +This project is licensed under the terms found in [`LICENSE`](LICENSE); this +file is unchanged from upstream. diff --git a/RELEASE.md b/RELEASE.md new file mode 100644 index 000000000..d5dd4790e --- /dev/null +++ b/RELEASE.md @@ -0,0 +1,36 @@ +# Release + +Every upstream release should have a corresponding release branch and tag here. +The branch should be named `release/vX.Y.Z`; that is, unlike normal Vezel +convention, even a patch release gets a unique branch. The tag should be named +`vX.Y.Z-B`, where B represents our one-based fork version. B is incremented +whenever we make fixes to the Zig build script within the same upstream release +cycle, and is reset for any new X/Y/Z combination. + +This is the procedure for creating a new release from an upstream release: + +1. Run `git checkout -b release/vX.Y.Z vX.Y.Z` to create and switch to the new + release branch. +2. Cherry-pick our fork's commit range from `master` and resolve any conflicts + in the process. +3. Adjust the libffi version in [`build.zig`](build.zig) and + [`build.zig.zon`](build.zig.zon), and then commit the changes. +4. Make sure `zig build` works. Try cross-compiling for any targets that had + changes in the upstream release. +5. Push the release branch. +6. Run `git tag vX.Y.Z-B -m vX.Y.Z-B -s` to create and sign a release tag, then + push it. +7. Go to the [releases page](https://github.com/vezel-dev/libffi/releases) to + create a release from the new tag. The release notes should just be a link to + the upstream release, such as + [this one](https://github.com/libffi/libffi/releases/tag/v3.4.6). + +(Obviously, step 2 will be easier if `master` is not lagging behind upstream.) + +The procedure for creating a release that only includes fixes to the Zig build +script is simpler: Just commit the fix to the release branch and then proceed +from step 4. Remember to increment the B value! + +If something goes wrong, you can run `git tag -d vX.Y.Z-B` and +`git push origin :vX.Y.Z-B` to delete the tag until you resolve the issue(s), +and then repeat whichever steps are necessary. diff --git a/dotnet-tools.json b/dotnet-tools.json new file mode 100644 index 000000000..04c598f66 --- /dev/null +++ b/dotnet-tools.json @@ -0,0 +1,18 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "dotnet-config": { + "version": "1.2.0", + "commands": [ + "dotnet-config" + ] + }, + "dotnet-file": { + "version": "1.6.2", + "commands": [ + "dotnet-file" + ] + } + } +} diff --git a/global.json b/global.json new file mode 100644 index 000000000..34dfab6e3 --- /dev/null +++ b/global.json @@ -0,0 +1,8 @@ +{ + "$schema": "https://json.schemastore.org/global.json", + "sdk": { + "version": "8.0.303", + "rollForward": "disable", + "allowPrelease": false + } +}