Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/rake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
push:
branches: [ main ]
tags: [ v* ]
pull_request:
# pull_request:

jobs:
rake:
Expand All @@ -19,5 +19,7 @@ jobs:
mkdir -p .bundle 2>&1 || true
echo "---" > .bundle/config 2>&1 || true
echo 'BUNDLE_BUILD__LIBXML___RUBY: "--with-xml2-dir=C:/vcpkg/installed/x64-windows --with-xml2-include=C:/vcpkg/installed/x64-windows/include/libxml2 --with-xml2-lib=C:/vcpkg/installed/x64-windows/lib"' >> .bundle/config 2>&1 || true
after-setup-ruby: |
bundle exec ruby debug.rb 2>&1 || true
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The after-setup-ruby step runs the debug script but always succeeds due to || true. This masks failures and defeats the purpose of running it in CI. Either:

  1. Remove || true to catch failures, or
  2. Remove this debug step entirely if it's not needed for CI validation
Suggested change
bundle exec ruby debug.rb 2>&1 || true
bundle exec ruby debug.rb 2>&1

Copilot uses AI. Check for mistakes.
secrets:
pat_token: ${{ secrets.GITHUB_TOKEN }}
209 changes: 209 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
name: windows

on:
push:
branches: [ main ]
pull_request:
workflow_dispatch:

jobs:
test-windows-scripts:
name: Test Windows Setup Scripts
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
ruby: ['3.2']

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: false

- name: Verify MSYS2 Installation
shell: pwsh
run: |
if (Test-Path "C:\msys64") {
Write-Host "✓ MSYS2 found at C:\msys64"
} else {
Write-Host "✗ MSYS2 not found"
exit 1
}

- name: Install libxml2 via MSYS2
shell: cmd
run: |
# C:\msys64\usr\bin\pacman.exe -S --needed --noconfirm mingw-w64-x86_64-libxml2 mingw-w64-x86_64-libiconv mingw-w64-x86_64-zlib

C:\msys64\usr\bin\pacman.exe -S --needed --noconfirm mingw-w64-ucrt-x86_64-libxml2 mingw-w64-ucrt-x86_64-libiconv mingw-w64-ucrt-x86_64-zlib

- name: Set Environment Variables
shell: pwsh
run: |
$rubyPlatform = ruby -e "puts RUBY_PLATFORM"
Write-Host "Ruby platform: $rubyPlatform"

# $envPath = "C:\msys64\mingw64"
$envPath = "C:\msys64\ucrt64"

echo "ICONV_INCLUDE=$envPath\include" >> $env:GITHUB_ENV
echo "WINDOWS_XML2_INCLUDE=$envPath\include\libxml2" >> $env:GITHUB_ENV
echo "WINDOWS_XML2_LIB=$envPath\lib" >> $env:GITHUB_ENV
echo "MSYS2_PATH=$envPath" >> $env:GITHUB_ENV

# Set PATH to include MSYS2 bin directory for DLL resolution
$rubyBin = ruby -e "puts RbConfig::CONFIG['bindir']"
Write-Host "Ruby bin directory: $rubyBin"
Write-Host "PATH environment variable: $env:Path"
$env:Path += ";$envPath;$envPath\lib;$envPath\include;$envPath\include\libxml2;$rubyBin"
echo "PATH=$env:Path" >> $env:GITHUB_ENV
Write-Host "PATH environment variable: $env:Path"

Write-Host "Environment variables set:"
Write-Host " ICONV_INCLUDE=$envPath\include"
Write-Host " WINDOWS_XML2_INCLUDE=$envPath\include\libxml2"
Write-Host " WINDOWS_XML2_LIB=$envPath\lib"
Write-Host " PATH=$env:Path"

- name: Install libxml-ruby
shell: pwsh
run: |
Write-Host "ICONV_INCLUDE=$env:ICONV_INCLUDE"
Write-Host "WINDOWS_XML2_INCLUDE=$env:WINDOWS_XML2_INCLUDE"
Write-Host "WINDOWS_XML2_LIB=$env:WINDOWS_XML2_LIB"
Write-Host "MSYS2_PATH=$env:MSYS2_PATH"

Write-Host "Files in $env:ICONV_INCLUDE are"
dir -Path $env:ICONV_INCLUDE | ForEach-Object {
Write-Host $_.Name
}

Write-Host "Files in $env:WINDOWS_XML2_INCLUDE are"
dir -Path $env:WINDOWS_XML2_INCLUDE | ForEach-Object {
Write-Host $_.Name
}

Write-Host "Files in $env:WINDOWS_XML2_LIB are"
dir -Path $env:WINDOWS_XML2_LIB | ForEach-Object {
Write-Host $_.Name
}

Write-Host "Files in $env:MSYS2_PATH are"
dir -Path $env:MSYS2_PATH | ForEach-Object {
Write-Host $_.Name
}

$rubyPlatform = ruby -e "puts RUBY_PLATFORM"
Write-Host "Installing libxml-ruby for $rubyPlatform..."

gem install libxml-ruby --version 5.0.3 -- --with-xml2-include=$env:WINDOWS_XML2_INCLUDE --with-xml2-lib=$env:WINDOWS_XML2_LIB --with-xml2-dir=$env:MSYS2_PATH --with-iconv-include=$env:ICONV_INCLUDE

if ($LASTEXITCODE -eq 0) {
Write-Host "✓ libxml-ruby installed successfully"
} else {
Write-Host "✗ Failed to install libxml-ruby"
exit 1
}

- name: Copy Required DLLs
shell: pwsh
run: |
$msys2Path = $env:MSYS2_PATH
$rubyBin = ruby -e "puts RbConfig::CONFIG['bindir']"

$libxmlrubyfilepath = gem which libxml-ruby
$libxmlrubyfolder = Split-Path -Path $libxmlrubyfilepath -Parent
Write-Host "Folder of libxml-ruby is $libxmlrubyfolder"

$sourcedir = "$msys2Path\bin"
Write-Host "Files in $sourcedir are:"
dir -Path $sourcedir -File | ForEach-Object {
Write-Host $_.Name
}

Write-Host "Copying DLLs from $msys2Path\bin to $rubyBin..."
$dlls = @("libxml2-16.dll", "libiconv-2.dll", "zlib1.dll")
foreach ($dll in $dlls) {
$source = "$msys2Path\bin\$dll"
$dest = "$rubyBin\$dll"
$dest2 = "$libxmlrubyfolder\$dll"

if (Test-Path $source) {
Copy-Item $source $dest -Force
Copy-Item $source $dest2 -Force
Write-Host "✓ Copied $dll"
} else {
Write-Host "✗ $dll not found at $source"
}
}

Write-Host "Files in $libxmlrubyfolder\${{ matrix.ruby }} are"
dir -Path "$libxmlrubyfolder\${{ matrix.ruby }}" | ForEach-Object {
Write-Host $_.Name
}
Write-Host "Copying SO from $libxmlrubyfolder\${{ matrix.ruby }} to $rubyBin..."
$source = "$libxmlrubyfolder\${{ matrix.ruby }}\libxml_ruby.so"
$dest = "$rubyBin\libxml_ruby.so"

if (Test-Path $source) {
Copy-Item $source $dest -Force
Copy-Item $source "$libxmlrubyfolder\libxml_ruby.so" -Force
Write-Host "✓ Copied libxml_ruby.so"
} else {
Write-Host "✗ libxml_ruby.so not found at $source"
}

- name: Test libxml-ruby Installation
shell: pwsh
run: |
Write-Host "Inspec PATH environment variable: $env:Path"

ruby -e @"
require 'libxml'
puts "libxml-ruby version: #{LibXML::XML::VERSION}"
puts "libxml2 version: #{LibXML::XML::LIBXML_VERSION}"

# Test basic parsing
doc = LibXML::XML::Document.string('<root><child attr="value"/></root>')
puts "Root element: #{doc.root.name}"
puts "Child element: #{doc.root.child.name}"
puts "Attribute value: #{doc.root.child['attr']}"
puts ""
puts "✓ libxml-ruby is working correctly!"
"@

- name: Test Moxml with LibXML Adapter
shell: pwsh
run: |
bundle install

ruby -e @"
require 'moxml'

# Configure to use LibXML adapter
Moxml.configure do |config|
config.adapter = :libxml
end

# Create a document
doc = Moxml.new.create_document
root = doc.create_element('root')
doc.add_child(root)

child = doc.create_element('child')
child['attr'] = 'value'
child.text = 'Hello from Windows!'
root.add_child(child)

puts "Document created with LibXML adapter:"
puts doc.to_xml(indent: 2)
puts ""
puts "✓ Moxml with LibXML adapter is working on Windows!"
"@

bundle exec rake
12 changes: 10 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,26 @@ gemspec

gem "byebug"
gem "get_process_mem"
gem "libxml-ruby", "~> 5.0"
gem "nokogiri", "~> 1.18"
gem "oga", "~> 3.4"
gem "ox", "~> 2.14"
gem "rake"
gem "rexml"
gem "rspec"
gem "simplecov", require: false
gem "rubocop"
gem "rubocop-performance"
gem "rubocop-rake"
gem "rubocop-rspec"
gem "simplecov", require: false
gem "tempfile"
# Provides iteration per second benchmarking for Ruby
gem "benchmark-ips"

# Needed by get_process_mem on Windows
gem "sys-proctable" if Gem.win_platform?

if Gem.win_platform?
gem "libxml-ruby", "5.0.4"
else
gem "libxml-ruby"
end
Comment on lines +28 to +32
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The libxml-ruby version is pinned to exactly "5.0.4" on Windows but allows any version on other platforms. This inconsistency could lead to different behavior across platforms. Consider:

  1. Documenting why Windows requires this specific version
  2. Using the same version constraint across platforms if possible
  3. Adding a comment explaining the platform-specific versioning
Suggested change
if Gem.win_platform?
gem "libxml-ruby", "5.0.4"
else
gem "libxml-ruby"
end
# Pinning libxml-ruby to 5.0.4 for all platforms to ensure consistent behavior.
# If a newer version is required, update this constraint after verifying cross-platform compatibility.
gem "libxml-ruby", "5.0.4"

Copilot uses AI. Check for mistakes.
39 changes: 39 additions & 0 deletions debug.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env ruby

require "rubygems"
# spec = Gem::Specification.find_by_name("libxml-ruby")
spec = Gem::Specification.find_by_name("moxml")
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hardcoded gem name "moxml" appears to be incorrect or test-specific. If this is a debug script intended to remain in the repository, it should use a configurable or correct gem name. If this is only for temporary debugging, it should not be committed.

Suggested change
spec = Gem::Specification.find_by_name("moxml")
gem_name = ENV["GEM_NAME"] || ARGV[0] || "libxml-ruby"
spec = Gem::Specification.find_by_name(gem_name)

Copilot uses AI. Check for mistakes.
puts spec.full_gem_path

# all_files = Dir.glob("#{spec.full_gem_path}/**/*").select { |f| File.file?(f) }

# all_files.each do |file|
# puts file
# end

# check PATH
puts ENV.fetch("PATH", nil)

# patch lib/libxml-ruby.rb
# filepath = "a.txt"
filepath = File.expand_path("#{spec.full_gem_path}/dlls")
ENV["PATH"] = "#{ENV.fetch("PATH", nil)};#{filepath}"

puts "Patched PATH:"
puts ENV.fetch("PATH", nil)

# original_content = File.read(filepath)

# line_to_add = "ENV['PATH'] = ENV['PATH'] + ';' + File.expand_path(File.dirname(__FILE__))\nputs 'Patched PATH: ' + ENV['PATH']"

# # Combine the new line with the original content
# new_content = line_to_add + "\n" + original_content

# # Overwrite the file with the new content
# File.write(filepath, new_content)

# puts "new_content================"
# puts new_content
# puts "==========================="

Comment on lines +8 to +38
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This debug script contains extensive commented-out code (lines 8-12, 17-37) that should be removed before merging. Commented code clutters the codebase and can be retrieved from version control history if needed.

Suggested change
# all_files = Dir.glob("#{spec.full_gem_path}/**/*").select { |f| File.file?(f) }
# all_files.each do |file|
# puts file
# end
# check PATH
puts ENV.fetch("PATH", nil)
# patch lib/libxml-ruby.rb
# filepath = "a.txt"
filepath = File.expand_path("#{spec.full_gem_path}/dlls")
ENV["PATH"] = "#{ENV.fetch("PATH", nil)};#{filepath}"
puts "Patched PATH:"
puts ENV.fetch("PATH", nil)
# original_content = File.read(filepath)
# line_to_add = "ENV['PATH'] = ENV['PATH'] + ';' + File.expand_path(File.dirname(__FILE__))\nputs 'Patched PATH: ' + ENV['PATH']"
# # Combine the new line with the original content
# new_content = line_to_add + "\n" + original_content
# # Overwrite the file with the new content
# File.write(filepath, new_content)
# puts "new_content================"
# puts new_content
# puts "==========================="
# check PATH
puts ENV.fetch("PATH", nil)
filepath = File.expand_path("#{spec.full_gem_path}/dlls")
ENV["PATH"] = "#{ENV.fetch("PATH", nil)};#{filepath}"
puts "Patched PATH:"
puts ENV.fetch("PATH", nil)

Copilot uses AI. Check for mistakes.
# LD_LIBRARY_PATH
Binary file added dlls/libiconv-2.dll
Binary file not shown.
Binary file added dlls/libxml2-2.dll
Binary file not shown.
Binary file added dlls/zlib1.dll
Binary file not shown.
Loading
Loading