Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 8, 2025

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

  • C library: Added JS_BUILD_SHARED CMake option to build shared library (.so/.dylib/.dll) for FFI consumption
  • Binary distribution: Automatic download of platform-specific pre-built binaries from GitHub releases (Linux/macOS/Windows x86_64/arm64)
  • Binary installer: New BinaryInstaller module that handles platform detection and binary downloads
  • FFI bindings: Low-level bindings to C API with proper struct definitions and memory management
  • Ruby wrappers: Idiomatic SchemaValidator and InstanceValidator classes with both result-based and exception-based APIs
  • Tests: 32 RSpec tests covering validation, error handling, and edge cases
  • CI: GitHub Actions workflow testing Ruby 2.7-3.3 on Ubuntu and macOS
  • Fixed: Root .gitignore to allow Ruby lib/ directories while preserving Python exclusions

Installation

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

require 'json_structure'

# Schema validation
result = JsonStructure::SchemaValidator.validate('{"type": "string"}')
puts "Valid!" if result.valid?

# Instance validation with exceptions
begin
  JsonStructure::InstanceValidator.validate!('"hello"', '{"type": "integer"}')
rescue JsonStructure::InstanceValidationError => e
  e.errors.each { |err| puts "#{err.path}: #{err.message}" }
end

Implementation Notes

  • Foreign SDK pattern: Ruby SDK downloads pre-built binaries from GitHub releases, treating the C SDK as an external dependency
  • Platform detection: Automatically detects OS (Linux/macOS/Windows) and architecture (x86_64/arm64) to download the correct binary
  • Development fallback: When developing in this repository, gracefully falls back to local C library builds if binaries aren't available
  • C inline convenience functions (js_validate_schema, js_validate_instance) are not exported in shared libraries; wrapper methods implemented in Ruby FFI module
  • Validator warnings (missing $id, name fields) have severity=1 vs errors with severity=0; tests distinguish appropriately
  • Gem structure follows Ruby conventions with Bundler, RSpec, and standard layout
Original prompt

create a PR for issue 10

Summary of Conversation History

Recent Agent Commands and Tool Results

  1. User Command: "create a PR for issue 11."

    • Context Provided: Instructions for creating a composer.json file for a package, including minimal required fields and validation steps.
    • Expected Outcome: A pull request (PR) should be created to address issue 11 by adding the composer.json file.
  2. User Command: "create a PR for issue 10."

    • Expected Outcome: A pull request (PR) should be created to address issue 10.

Results from Recent Tool Calls

  • No specific tool results were returned for the commands to create PRs for issues 10 and 11, as the commands were primarily instructions for the agent to execute.

Active Work When Token Budget Exceeded

  • The agent was actively working on creating pull requests for issues 10 and 11, specifically focusing on adding necessary files and configurations for PHP package management (Packagist) and ensuring compliance with the required standards.

Connection to Overall User Goals

  • The user is focused on enhancing the SDK repository by ensuring proper package management for PHP through the creation of a composer.json file. This aligns with the broader goal of improving the SDK's usability and accessibility across different programming languages, ensuring that all necessary components are in place for effective package distribution and management.

Conclusion

The conversation has revolved around enhancing the SDK repository, particularly for PHP, by creating necessary configuration files and addressing open issues. The recent commands indicate a push towards finalizing these enhancements through pull requests.
TITLE: Creating a PR for PHP SDK Packagist Integration

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.

Copilot AI and others added 5 commits December 8, 2025 11:08
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>
@clemensv
Copy link
Contributor

clemensv commented Dec 8, 2025

@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

Copilot AI changed the title [WIP] Create pull request for issue 10 Implement Ruby SDK via C FFI bindings Dec 8, 2025
Copilot AI requested a review from clemensv December 8, 2025 11:26
Co-authored-by: clemensv <542030+clemensv@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 8, 2025

@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

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):

  1. New BinaryInstaller - Downloads platform-specific binaries (Linux/macOS/Windows x86_64/arm64) from GitHub releases
  2. Updated FFI loader - Prioritizes downloaded binaries in ext/ directory
  3. Refactored Rakefile:
    • download_binary - Downloads from GitHub (production use)
    • build_c_lib_local - Local build (development only, when C source is available)
    • test - Tries download first, falls back to local build in dev environment
  4. Updated CI - Clarified local builds are for testing; production uses pre-built binaries
  5. Updated docs - Explains binary distribution and development workflow

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.

Copilot AI changed the title Implement Ruby SDK via C FFI bindings Implement Ruby SDK via C FFI bindings with automatic binary downloads Dec 8, 2025
Clemens Vasters added 6 commits December 8, 2025 15:02
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.
@clemensv clemensv marked this pull request as ready for review December 8, 2025 15:39
@clemensv clemensv merged commit be564df into master Dec 8, 2025
4 checks passed
@clemensv clemensv deleted the copilot/create-pr-for-issue-10 branch December 8, 2025 15:39
@clemensv clemensv mentioned this pull request Dec 8, 2025
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants