Skip to content

Commit

Permalink
feat: support Ruby 3.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
maxirmx committed Jan 1, 2025
1 parent 1443df9 commit 6ba5162
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 13 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/alpine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ jobs:
env:
- { CC: gcc, CXX: g++, ALPINE_VER: "3.17" }
- { CC: clang, CXX: clang++, ALPINE_VER: "3.17" }
package_ruby_ver: [ '3.1.6', '3.2.6', '3.3.6' ]
package_ruby_ver: [ '3.1.6', '3.2.6', '3.3.6', '3.4.1' ]
env: ${{ matrix.env }}
steps:
- name: Install packages
Expand Down Expand Up @@ -178,7 +178,7 @@ jobs:
env:
- { CC: gcc, CXX: g++, ALPINE_VER: "3.17" }
- { CC: clang, CXX: clang++, ALPINE_VER: "3.17" }
package_ruby_ver: [ '3.1.6', '3.2.6', '3.3.6' ]
package_ruby_ver: [ '3.1.6', '3.2.6', '3.3.6', '3.4.1' ]
env: ${{ matrix.env }}
steps:
- name: Install packages
Expand Down Expand Up @@ -234,7 +234,7 @@ jobs:
env:
- { CC: gcc, CXX: g++, ALPINE_VER: "3.17" }
- { CC: clang, CXX: clang++, ALPINE_VER: "3.17" }
package_ruby_ver: [ '3.1.6', '3.2.6', '3.3.6']
package_ruby_ver: [ '3.1.6', '3.2.6', '3.3.6', '3.4.1']
env: ${{ matrix.env }}
steps:
- name: Install packages
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ jobs:
- { os: macos-14, xcode: 15.4 }
- { os: macos-15, xcode: 16.1 }

package_ruby_ver: [ '3.1.6', '3.2.6', '3.3.6' ]
package_ruby_ver: [ '3.1.6', '3.2.6', '3.3.6', '3.4.1' ]
ruby_ver: ['3.2.6']
steps:
- name: Checkout tebako packaging environment
Expand Down Expand Up @@ -167,7 +167,7 @@ jobs:
- { os: macos-14, xcode: 15.4 }
- { os: macos-15, xcode: 16.1 }

package_ruby_ver: [ '3.3.6' ]
package_ruby_ver: [ '3.3.6', '3.4.1' ]
ruby_ver: ['3.2.6']
steps:
- name: Checkout tebako packaging environment
Expand Down Expand Up @@ -218,7 +218,7 @@ jobs:
- { os: macos-14, xcode: 15.0.1, LG_VADDR: 39}
- { os: macos-14, xcode: 15.4 }
- { os: macos-15, xcode: 16.1 }
package_ruby_ver: [ '3.1.6', '3.2.6', '3.3.6' ]
package_ruby_ver: [ '3.1.6', '3.2.6', '3.3.6', '3.4.1' ]
ruby_ver: ['3.2.6']
steps:
- name: Checkout tebako packaging environment
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ jobs:
strategy:
fail-fast: false
matrix:
package_ruby_ver: [ '2.7.8', '3.0.7', '3.1.6', '3.2.4', '3.2.5', '3.2.6', '3.3.3', '3.3.4', '3.3.5', '3.3.6' ]
package_ruby_ver: [ '2.7.8', '3.0.7', '3.1.6', '3.2.4', '3.2.5', '3.2.6', '3.3.3', '3.3.4', '3.3.5', '3.3.6', '3.4.1' ]
env:
- { os: ubuntu-20.04, CC: gcc-10, CXX: g++-10 }
- { os: ubuntu-20.04, CC: clang-12, CXX: clang++-12 }
Expand Down Expand Up @@ -162,7 +162,7 @@ jobs:
strategy:
fail-fast: false
matrix:
package_ruby_ver: [ '2.7.8', '3.0.7', '3.1.6', '3.2.4', '3.2.5', '3.2.6', '3.3.3', '3.3.4', '3.3.5', '3.3.6' ]
package_ruby_ver: [ '2.7.8', '3.0.7', '3.1.6', '3.2.4', '3.2.5', '3.2.6', '3.3.3', '3.3.4', '3.3.5', '3.3.6', '3.4.1' ]
env:
- { os: ubuntu-20.04, CC: gcc-10, CXX: g++-10 }
- { os: ubuntu-20.04, CC: clang-12, CXX: clang++-12 }
Expand Down Expand Up @@ -211,7 +211,7 @@ jobs:
strategy:
fail-fast: false
matrix:
package_ruby_ver: [ '2.7.8', '3.0.7', '3.1.6', '3.2.4', '3.2.5', '3.2.6', '3.3.3', '3.3.4', '3.3.5', '3.3.6' ]
package_ruby_ver: [ '2.7.8', '3.0.7', '3.1.6', '3.2.4', '3.2.5', '3.2.6', '3.3.3', '3.3.4', '3.3.5', '3.3.6', '3.4.1' ]
env:
- { os: ubuntu-20.04, CC: gcc-10, CXX: g++-10 }
- { os: ubuntu-20.04, CC: clang-12, CXX: clang++-12 }
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/windows-msys.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ jobs:
- sys: ucrt64
CC: gcc
CXX: g++
package_ruby_ver: [ '3.1.6', '3.2.6', '3.3.6' ]
package_ruby_ver: [ '3.1.6', '3.2.6', '3.3.6', '3.4.1' ]
script: ['bundle', 'app']
env: ${{ matrix.env }}

Expand Down Expand Up @@ -232,7 +232,7 @@ jobs:
- sys: ucrt64
CC: gcc
CXX: g++
package_ruby_ver: [ '3.1.6', '3.2.6', '3.3.6' ]
package_ruby_ver: [ '3.1.6', '3.2.6', '3.3.6', '3.4.1' ]
env: ${{ matrix.env }}

defaults:
Expand Down
49 changes: 49 additions & 0 deletions include/tebako/tebako-prism.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
static pm_string_init_result_t
tebako_string_file_init(pm_string_t *string, const char *filepath) {

// Open the file for reading
int fd = open(filepath, O_RDONLY);
if (fd == -1) {
return PM_STRING_INIT_ERROR_GENERIC;
}

// Stat the file to get the file size
struct stat sb;
if (fstat(fd, &sb) == -1) {
close(fd);
return PM_STRING_INIT_ERROR_GENERIC;
}

// Ensure it is a file and not a directory
if (S_ISDIR(sb.st_mode)) {
close(fd);
return PM_STRING_INIT_ERROR_DIRECTORY;
}

// Check the size to see if it's empty
size_t size = (size_t) sb.st_size;
if (size == 0) {
close(fd);
const uint8_t source[] = "";
*string = (pm_string_t) { .type = PM_STRING_CONSTANT, .source = source, .length = 0 };
return PM_STRING_INIT_SUCCESS;
}

size_t length = (size_t) size;
uint8_t *source = xmalloc(length);
if (source == NULL) {
close(fd);
return PM_STRING_INIT_ERROR_GENERIC;
}

long bytes_read = (long) read(fd, source, length);
close(fd);

if (bytes_read == -1) {
xfree(source);
return PM_STRING_INIT_ERROR_GENERIC;
}

*string = (pm_string_t) { .type = PM_STRING_OWNED, .source = source, .length = length };
return PM_STRING_INIT_SUCCESS;
}
2 changes: 1 addition & 1 deletion lib/tebako/packager/pass1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def get_patch_map(ostype, mount_point, ruby_ver)

private

include Tebako::Packager::PatchLiterals
# include Tebako::Packager::PatchLiterals
include Tebako::Packager::PatchBuildsystem

def get_gnumakefile_in_patch_p1(ruby_ver) # rubocop:disable Metrics/MethodLength
Expand Down
2 changes: 2 additions & 0 deletions lib/tebako/packager/pass2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def get_patch_map(ostype, deps_lib_dir, ruby_ver)
patch_map.store("common.mk", COMMON_MK_PATCH)
end
extend_patch_map_r33(patch_map, ostype, deps_lib_dir, ruby_ver)
patch_map.store("prism_compile.c", PRISM_PATCHES) if ruby_ver.ruby34?
patch_map

Check warning on line 50 in lib/tebako/packager/pass2.rb

View check run for this annotation

Codecov / codecov/patch

lib/tebako/packager/pass2.rb#L49-L50

Added lines #L49 - L50 were not covered by tests
end

private
Expand Down
36 changes: 35 additions & 1 deletion lib/tebako/packager/patch_literals.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
module Tebako
module Packager
# Ruby patching literals (pass2)
module PatchLiterals
module PatchLiterals # rubocop:disable Metrics/ModuleLength
TOOL_MKCONFIG_RB_SUBST = <<~SUBST
# -- Start of tebako patch --
v_head_comp = " CONFIG[\\"prefix\\"] \#{eq} "
Expand Down Expand Up @@ -332,6 +332,40 @@ module PatchLiterals
"mf.macro \"EXTLIBS\", $extlibs" => "# mf.macro \"EXTLIBS\", $extlibs tebako patched"
}
}.freeze

PRISM_PATTERN_1 = "pm_string_init_result_t init_result = pm_read_file(&result->input, RSTRING_PTR(filepath));"

PRISM_SUBST_1 = <<~SUBST
/* -- Start of tebako patch -- */
pm_string_init_result_t init_result;
if (within_tebako_memfs(RSTRING_PTR(filepath)))
{
init_result = tebako_string_file_init(&result->input, RSTRING_PTR(filepath));
}
else
{
init_result = pm_read_file(&result->input, RSTRING_PTR(filepath));
}
/* -- End of tebako patch -- */
SUBST

PRISM_PATTERN_2 = "#include \"prism.h\""
PRISM_SUBST_2 = <<~SUBST
#{PRISM_PATTERN_2}
/* -- Start of tebako patch -- */
#include <tebako/tebako-config.h>
#include <tebako/tebako-defines.h>
#include <tebako/tebako-io.h>
#include <tebako/tebako-prism.h>
/* -- End of tebako patch -- */
SUBST

PRISM_PATCHES = {
PRISM_PATTERN_1 => PRISM_SUBST_1,
PRISM_PATTERN_2 => PRISM_SUBST_2
}.freeze
end
end
end
52 changes: 52 additions & 0 deletions spec/ruby_version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@
expect(version.ruby33?).to be false
end

it "returns false for ruby34?" do
expect(version.ruby34?).to be false
end

it "returns '3.1.0' for api_version" do
expect(version.api_version).to eq("3.1.0")
end
Expand Down Expand Up @@ -111,6 +115,10 @@
expect(version.ruby33?).to be false
end

it "returns false for ruby34?" do
expect(version.ruby34?).to be false
end

it "returns '3.2.0' for api_version" do
expect(version.api_version).to eq("3.2.0")
end
Expand Down Expand Up @@ -143,6 +151,10 @@
expect(version.ruby33?).to be true
end

it "returns false for ruby34?" do
expect(version.ruby34?).to be false
end

it "returns '3.3.0' for api_version" do
expect(version.api_version).to eq("3.3.0")
end
Expand All @@ -152,6 +164,42 @@
end
end

context "with version 3.4.1" do
let(:version) { Tebako::RubyVersion.new("3.4.1") }

it "returns true for ruby3x?" do
expect(version.ruby3x?).to be true
end

it "returns true for ruby31?" do
expect(version.ruby31?).to be true
end

it "returns true for ruby32?" do
expect(version.ruby32?).to be true
end

it "returns false for ruby32only?" do
expect(version.ruby32only?).to be false
end

it "returns true for ruby33?" do
expect(version.ruby33?).to be true
end

it "returns true for ruby34?" do
expect(version.ruby34?).to be true
end

it "returns '3.4.0' for api_version" do
expect(version.api_version).to eq("3.4.0")
end

it "returns '340' for lib_version" do
expect(version.lib_version).to eq("340")
end
end

context "with version 2.7.0" do
unless RUBY_PLATFORM =~ /msys|mingw|cygwin/

Expand All @@ -177,6 +225,10 @@
expect(version.ruby33?).to be false
end

it "returns false for ruby34?" do
expect(version.ruby34?).to be false
end

it "returns '2.7.0' for api_version" do
expect(version.api_version).to eq("2.7.0")
end
Expand Down

0 comments on commit 6ba5162

Please sign in to comment.