{"id":13344073,"url":"https://github.com/daneelsan/ZigLink","last_synced_at":"2025-03-12T06:31:11.303Z","repository":{"id":133848844,"uuid":"477246743","full_name":"daneelsan/ZigLink","owner":"daneelsan","description":"Call Zig code from Wolfram Language via the LibraryLink interface.","archived":false,"fork":false,"pushed_at":"2022-10-22T19:08:57.000Z","size":281,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-04T12:46:25.470Z","etag":null,"topics":["wolfram-language","zig"],"latest_commit_sha":null,"homepage":"","language":"Mathematica","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/daneelsan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-03T05:26:27.000Z","updated_at":"2025-01-15T17:57:05.000Z","dependencies_parsed_at":"2023-08-31T22:49:19.302Z","dependency_job_id":null,"html_url":"https://github.com/daneelsan/ZigLink","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daneelsan%2FZigLink","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daneelsan%2FZigLink/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daneelsan%2FZigLink/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daneelsan%2FZigLink/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/daneelsan","download_url":"https://codeload.github.com/daneelsan/ZigLink/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243171627,"owners_count":20247878,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["wolfram-language","zig"],"created_at":"2024-07-29T19:32:20.111Z","updated_at":"2025-03-12T06:31:11.297Z","avatar_url":"https://github.com/daneelsan.png","language":"Mathematica","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ZigLink\n\nCall Zig code from Wolfram Language via the LibraryLink interface.\n\n## Objectives\n\nThere are three objectives:\n\n1. Translate the Wolfram LibraryLink C headers (WolframLibrary.h, WolframNumericArrayLibrary.h) to zig and use\n   zig code to generate dynamic libraries callable from Wolfram Language.\n\n2. Write a WolframLibraryLink.zig package that uses the translated libraries from 1) but using a more zig-like style, i.e. following the style from the zig standard library.\n\n3. Write Wolfram Language paclet that allows to call the zig built-in compiler/linker, in a similar vein to how CCompilerDriver`CreateLibrary compiles C code.\n\nObjective 1) is underway. Objectives 2) and 3) are TODO.\n\n## Directory layout\n\n```\n├── demos                               # LibraryLink demos written in zig\n├── LibraryLink                         # LibraryLink C headers translated to zig\n    ├── WolframLibrary.zig\n    ├── WolframNumericArrayLibrary.zig\n├── LibraryResources                    # Directory containing all libraries\n    ├── Linux-x86-64\n    ├── MacOSX-ARM64\n    ├── MacOSX-x86-64\n    ├── Windows-x86-64\n├── Tests\n    ├── demos                           # Tests for the demos in zig\n        ├── demo_XXXX.nb                # Notebook testing the demo_XXXX\n        ├── demo_XXXX.wlt               # Automatic file generated from its .nb counterpart\n        ├── ...\n├── WolframResources                    # Resources that come from your standard Mathematica installation\n    ├── LibraryLink                     # Wolfram LibraryLink files\n        ├── demos\n        ├── headers\n├── build.zig                           # Zig build \"script\"\n└── README.md\n```\n\n## LibraryLink header and demo translation\n\n### demo_XXXX.zig\n\nThese are zig translated versions of the C LibraryLink demos found in WolframResources/LibraryLink/demos.\n\n#### building\n\nTo build these libraries we will use the zig building system, which is all contained in `build.zig`.\n\nFirst, make sure you have zig version 0.9.1 (or later):\n\n```shell\n$ zig version\n0.9.1\n```\n\nNext, build all the demos:\n\n```shell\n$ zig build demos\n```\n\nThe amazing thing about the zig build system is it that allows simple cross-platform compilation.\nNot only did the previous command created libraries for all the demos, but it also did so for all\nthe major supported Wolfram platforms:\n\n```shell\n$ ls LibraryResources/\nLinux-x86-64   MacOSX-ARM64   MacOSX-x86-64  Windows-x86-64\n```\n\n```shell\n$ find LibraryResources/ -maxdepth 2  -type f\nLibraryResources/MacOSX-x86-64/demo.dylib\nLibraryResources/MacOSX-x86-64/demo_string.dylib\n...\nLibraryResources/MacOSX-ARM64/demo.dylib\nLibraryResources/MacOSX-ARM64/demo_string.dylib\n...\nLibraryResources/Linux-x86-64/demo.so\nLibraryResources/Linux-x86-64/demo_managed.so\n...\nLibraryResources/Windows-x86-64/demo_numericarray.pdb\nLibraryResources/Windows-x86-64/demo_string.lib\n```\n\nNote: The current paths to Mathematica's headers and libraries is hardcoded in `build.zig`:\n\n```zig\n    const mathematica_path = \"/Applications/Mathematica.app\";\n```\n\nso modify these as appropriate.\n\n#### testing\n\nFirst add the demo libraries to the `$LibraryPath` so that these libraries can be found via `FindLibrary`:\n\n```Mathematica\n$LibraryPath = PrependTo[$LibraryPath, FileNameJoin[{$ZigLinkDirectory, \"LibraryResources\", $SystemID}]]\n```\n\nNext, run the .wlt tests found in Tests/demos:\n\n```Mathematica\nIn[]:= TestReport[FileNames[\"*.wlt\", FileNameJoin[{$ZigLinkDirectory, \"Tests\", \"demos\"}]]]\nOut[]= TestReportObject[\u003c...\u003e]\n```\n\n`$ZigLinkDirectory` is the directory where the ZigLink repository is located.\n\n### How?\n\nThe .zig packages where first generated using translate-c. However, many of the macros present in these headers where not translated correctly (or at all) by zig or types where not the most suitable, so they had to be manually tweaked after being translated by zig.\nThis is mentioned in zig's documentation:\n\n\u003e [...] if you would like to edit the translated code, it is recommended to use zig translate-c and save the results to a file. Common reasons for editing the generated code include: changing anytype parameters in function-like macros to more specific types; changing [*c]T pointers to [*]T or \\*T pointers for improved type safety [...]\n\nThe .zig demos where manually translated from the C demos. They mostly follow the C style of coding, minus some uses of the zig standard library.\n\n### Progress\n\nHere is a list of the files that need to be translated (and the ones that already have).\n\n#### headers:\n\n-   [ ] WolframCompileLibrary.h\n-   [ ] WolframImageLibrary.h\n-   [ ] WolframIOLibraryFunctions.h\n-   [x] WolframLibrary.h\n-   [x] WolframNumericArrayLibrary.h\n-   [ ] WolframRawArrayLibrary.h\n-   [ ] WolframRTL.h\n-   [ ] WolframSparseLibrary.h\n-   [ ] WolframStreamsLibrary.h\n\n#### demos:\n\n-   [ ] arbitraryTensor.c\n-   [ ] async-examples-libmain.c\n-   [ ] async-examples.h\n-   [ ] async-tasks-oneshot.c\n-   [ ] async-tasks-repeating.c\n-   [ ] async-tasks-timing.c\n-   [ ] async-tasks-without-thread.c\n-   [ ] demo_callback.c\n-   [x] demo_error.c\n-   [ ] demo_eval.c\n-   [ ] demo_image.cxx\n-   [x] demo_LinkObject.c\n-   [x] demo_managed.cxx\n-   [ ] demo_numerical.c\n-   [x] demo_numericarray.cxx\n-   [x] demo_shared.c\n-   [ ] demo_sparse.c\n-   [x] demo_string.c\n-   [ ] demo.c\n-   [ ] image_external.c\n-   [ ] image_video.cxx\n\n## References\n\nLibraryLink:\n\n-   https://reference.wolfram.com/language/LibraryLink/tutorial/Overview.html\n-   https://reference.wolfram.com/language/guide/LibraryLink.html\n\nZig:\n\n-   https://ziglearn.org\n-   https://ziglang.org\n-   https://github.com/ziglang/zig\n-   https://ziglang.org/documentation/\n-   https://www.lagerdata.com/articles/an-intro-to-zigs-integer-casting-for-c-programmers\n-   https://zig.news/xq/zig-build-explained-part-1-59lf\n\nOther:\n\n-   https://github.com/WolframResearch/wolfram-library-link-rs\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaneelsan%2FZigLink","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaneelsan%2FZigLink","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaneelsan%2FZigLink/lists"}