Skip to content
Merged
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: 4 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Rake creates or removes this host-specific file when switching platforms.
include = [
{ path = "windows.toml", optional = true },
]
11 changes: 9 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ jobs:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true

- name: Install Windows build dependencies
run: >-
ridk exec pacman -S --needed --noconfirm
mingw-w64-ucrt-x86_64-gcc
mingw-w64-ucrt-x86_64-clang
mingw-w64-ucrt-x86_64-cmake
mingw-w64-ucrt-x86_64-pkgconf
- name: Run tests
shell: pwsh
run: ./script/build_windows_gnu.ps1 -SkipBundleInstall -RunTests
run: bundle exec rake test
30 changes: 27 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,20 @@ jobs:
ruby-version: "3.3"
bundler-cache: true

- name: Install Windows build dependencies for Ruby 3.3
run: >-
ridk exec pacman -S --needed --noconfirm
mingw-w64-ucrt-x86_64-gcc
mingw-w64-ucrt-x86_64-clang
mingw-w64-ucrt-x86_64-cmake
mingw-w64-ucrt-x86_64-pkgconf

- name: Compile for Ruby 3.3
shell: pwsh
env:
RB_SYS_CARGO_PROFILE: release
run: |
./script/build_windows_gnu.ps1 -SkipBundleInstall
bundle exec rake compile
New-Item -ItemType Directory -Force "lib\wreq_ruby\3.3" | Out-Null
Copy-Item "lib\wreq_ruby\wreq_ruby.so" "lib\wreq_ruby\3.3\wreq_ruby.so" -Force

Expand All @@ -154,12 +162,20 @@ jobs:
ruby-version: "3.4"
bundler-cache: true

- name: Install Windows build dependencies for Ruby 3.4
run: >-
ridk exec pacman -S --needed --noconfirm
mingw-w64-ucrt-x86_64-gcc
mingw-w64-ucrt-x86_64-clang
mingw-w64-ucrt-x86_64-cmake
mingw-w64-ucrt-x86_64-pkgconf

- name: Compile for Ruby 3.4
shell: pwsh
env:
RB_SYS_CARGO_PROFILE: release
run: |
./script/build_windows_gnu.ps1 -SkipBundleInstall
bundle exec rake compile
New-Item -ItemType Directory -Force "lib\wreq_ruby\3.4" | Out-Null
Copy-Item "lib\wreq_ruby\wreq_ruby.so" "lib\wreq_ruby\3.4\wreq_ruby.so" -Force

Expand All @@ -168,12 +184,20 @@ jobs:
ruby-version: "4.0"
bundler-cache: true

- name: Install Windows build dependencies for Ruby 4.0
run: >-
ridk exec pacman -S --needed --noconfirm
mingw-w64-ucrt-x86_64-gcc
mingw-w64-ucrt-x86_64-clang
mingw-w64-ucrt-x86_64-cmake
mingw-w64-ucrt-x86_64-pkgconf

- name: Compile for Ruby 4.0
shell: pwsh
env:
RB_SYS_CARGO_PROFILE: release
run: |
./script/build_windows_gnu.ps1 -SkipBundleInstall
bundle exec rake compile
New-Item -ItemType Directory -Force "lib\wreq_ruby\4.0" | Out-Null
Copy-Item "lib\wreq_ruby\wreq_ruby.so" "lib\wreq_ruby\4.0\wreq_ruby.so" -Force

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ test.rb
DATA.md
AGENTS.md
.agents/
.cargo/windows.toml
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = ["SearchApi <support@searchapi.io>"]
homepage = "https://github.com/SearchApi/wreq-ruby"
repository = "https://github.com/SearchApi/wreq-ruby"
edition = "2024"
rust-version = "1.85"
rust-version = "1.97"
version = "1.2.4"

[lib]
Expand Down
6 changes: 6 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# frozen_string_literal: true

require_relative "script/rust_env"

# Cargo needs RubyInstaller's UCRT tools when Rake builds the native extension
# on Windows. Other platforms keep their existing native Cargo environment.
Wreq::RustEnv.activate

require "bundler/gem_tasks"
require "rake/testtask"
require "rb_sys/extensiontask"
Expand Down
52 changes: 49 additions & 3 deletions docs/windows-gnu-tokio-crash.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,60 @@ DLL Name: KERNEL32.dll
problematic `Sleep` reference can come from Rust std, MinGW, or pthread-related
linking paths, not only from `windows-sys`.

Verified with:
Windows builds use the `x86_64-pc-windows-gnu` target and the RubyInstaller
UCRT toolchain. The Rakefile configures that environment automatically, so the
extension and tests can be built with:

```powershell
.\script\build_windows_gnu.ps1 -SkipBundleInstall -SkipToolInstall -RunTests
rustup target add x86_64-pc-windows-gnu
ridk exec pacman -S --needed --noconfirm `
mingw-w64-ucrt-x86_64-gcc `
mingw-w64-ucrt-x86_64-clang `
mingw-w64-ucrt-x86_64-cmake `
mingw-w64-ucrt-x86_64-pkgconf
bundle exec rake test
```

The first Rake invocation also writes a machine-local `.cargo/windows.toml`.
The checked-in `.cargo/config.toml` loads it automatically, so Cargo and Rust
language servers use the same GNU target and RubyInstaller tools without
editor-specific settings.

## RubyInstaller development tools

RubyInstaller adds Ruby itself to `PATH`, but it does not enable the bundled
MSYS2 development environment globally. Running `ridk enable` adds tools such
as GCC, CMake, and Make to the current terminal only. This is normally useful
because it avoids conflicts with other Windows toolchains.

Rust language servers start Cargo directly and do not run `ridk enable` or the
Rakefile first. Add RubyInstaller's `ucrt64\bin` and `usr\bin` directories to
the user `PATH` so Cargo can load GCC, libclang, and their dependent DLLs from
any editor:

```powershell
$rubyRoot = ruby -rrbconfig -e "print RbConfig::CONFIG.fetch('prefix')"
$required = @(
(Join-Path $rubyRoot "msys64\ucrt64\bin"),
(Join-Path $rubyRoot "msys64\usr\bin")
)
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
$entries = @($userPath -split ";" | Where-Object {
$_ -and $_ -notin $required
})
$entries = $required + $entries
[Environment]::SetEnvironmentVariable("Path", ($entries -join ";"), "User")
```

Restart the editor after changing `PATH` so its language server inherits the
updated environment. Run `bundle exec rake compile` once after installing or
switching Ruby so `.cargo/windows.toml` points to the active RubyInstaller.
Run a Rake command after switching the same checkout between Windows and WSL;
Windows generates this local configuration, while other platforms remove it.

Result:

```text
160 runs, 775 assertions, 0 failures, 0 errors
254 runs, 1198 assertions, 0 failures, 0 errors
2 Rust tests passed
```
4 changes: 4 additions & 0 deletions extconf.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
require "mkmf"
require_relative "script/rust_env"

Wreq::RustEnv.activate

# We use rb_sys for makefile generation only.
# We can use `RB_SYS_CARGO_PROFILE` to choose Cargo profile
# Read more https://github.com/oxidize-rb/rb-sys/blob/main/gem/README.md
Expand Down
Loading