forked from libffi/libffi
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add README.md and some Vezel repository scaffolding.
- Loading branch information
Showing
11 changed files
with
335 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
* text | ||
*.verified.* text eol=lf | ||
*.ico binary | ||
*.pdf binary | ||
*.png binary | ||
*.zig eol=lf | ||
*.zon eol=lf |
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* @vezel-dev/graf-maintainers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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": [] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
# 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 libffi version on the | ||
[releases page](https://github.com/vezel-dev/libffi/releases).) | ||
|
||
Then, in your `build.zig`: | ||
|
||
```zig | ||
const ffi = b.dependency("ffi", .{}); | ||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"version": 1, | ||
"isRoot": true, | ||
"tools": { | ||
"dotnet-config": { | ||
"version": "1.0.6", | ||
"commands": [ | ||
"dotnet-config" | ||
] | ||
}, | ||
"dotnet-file": { | ||
"version": "1.4.1", | ||
"commands": [ | ||
"dotnet-file" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/global.json", | ||
"sdk": { | ||
"version": "8.0.302", | ||
"rollForward": "disable", | ||
"allowPrelease": false | ||
} | ||
} |