-
Notifications
You must be signed in to change notification settings - Fork 1
Implement Ruby SDK via C FFI bindings with automatic binary downloads #14
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
Conversation
Co-authored-by: clemensv <542030+clemensv@users.noreply.github.com>
Co-authored-by: clemensv <542030+clemensv@users.noreply.github.com>
Co-authored-by: clemensv <542030+clemensv@users.noreply.github.com>
Co-authored-by: clemensv <542030+clemensv@users.noreply.github.com>
Co-authored-by: clemensv <542030+clemensv@users.noreply.github.com>
|
@copilot the ruby wrapper should build on the binaries created by the C SDK as if they were a foreign SDK, i.e. get libraries from github as if they were not in this same repo |
Co-authored-by: clemensv <542030+clemensv@users.noreply.github.com>
Done! The Ruby wrapper now treats the C SDK as a foreign SDK and downloads pre-built binaries from GitHub releases instead of building locally. Key changes (commit d1080a3):
The gem now works like a typical FFI gem that consumes external C libraries, with automatic binary download on install. For development in this repo, it gracefully falls back to local builds. |
Windows shared libraries require __declspec(dllexport) declarations which are not yet implemented. The Ruby SDK workflow explicitly enables JS_BUILD_SHARED=ON for Unix builds where it works without export macros.
Add JS_API macro to all public API functions for proper DLL symbol export/import on Windows. This enables building the C SDK as a shared library (DLL) on Windows for use with FFI bindings (Ruby, etc.). Changes: - Add export.h with JS_API macro using __declspec(dllexport/dllimport) - Add JS_API to all public functions in types.h, schema_validator.h, instance_validator.h, error_codes.h, json_structure.h, and json.h - CMake now defines JS_BUILDING_SHARED when building the shared library - Set visibility to hidden by default on Unix for proper symbol control - Restore JS_BUILD_SHARED=ON as default since exports now work on Windows
When building as shared library, the DLL needs to be in the same directory as the test executable on Windows.
Tests against shared test-assets to ensure Ruby SDK consistency with other SDK implementations: - Invalid schemas (26 files) - all must be rejected - Validation extension schemas (16 files) - all must be accepted - Invalid instances against their schemas - Primer sample schemas - all must be accepted
The js_init, js_init_with_allocator, and js_cleanup functions were declared with JS_API in the header but the source file wasn't including that header, so with -fvisibility=hidden these symbols weren't being exported in the shared library.
Skip minProperties test case until issue #21 is fixed. Tests now pass with 26 invalid schemas rejected, 16 validation schemas accepted, 27 invalid instances rejected (1 skipped), and 12 primer samples accepted.
Adds Ruby SDK wrapping the C library through FFI, providing native-performance JSON Structure schema and instance validation for Ruby applications. The Ruby SDK treats the C library as a foreign dependency, automatically downloading pre-built binaries from GitHub releases.
Changes
JS_BUILD_SHAREDCMake option to build shared library (.so/.dylib/.dll) for FFI consumptionBinaryInstallermodule that handles platform detection and binary downloadsSchemaValidatorandInstanceValidatorclasses with both result-based and exception-based APIs.gitignoreto allow Rubylib/directories while preserving Python exclusionsInstallation
The gem automatically downloads the appropriate pre-built C library binary for your platform during installation. No compilation required - users don't need CMake or a C compiler.
Usage
Implementation Notes
js_validate_schema,js_validate_instance) are not exported in shared libraries; wrapper methods implemented in Ruby FFI module$id,namefields) have severity=1 vs errors with severity=0; tests distinguish appropriatelyOriginal prompt
Created from VS Code via the GitHub Pull Request extension.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.