Skip to content
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

Add CI for macos #180

Merged
merged 5 commits into from
Jul 9, 2024
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
27 changes: 27 additions & 0 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: CI

on: [push, pull_request]

Choose a reason for hiding this comment

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

Suggested change
on: [push, pull_request]
on:
push:
branches:
- main
pull_request:
branches:
- main

Saw your post on mastodon. Thought this might help?

Choose a reason for hiding this comment

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

... nevermind, I misread, sorry. 🤦‍♂️


jobs:
test:
runs-on: ${{ matrix.os }}-latest

Choose a reason for hiding this comment

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

I think the problem is here... macos-14-latest doesn't make sense to me

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, that's what I get for copy/pasting YAML files. I wish GitHub would tell me the "runs-on" doesn't make sense.


strategy:
fail-fast: false
matrix:
os: [macos]
ruby: [ '3.2', '3.3' ]

steps:
- name: icu4c
run: brew install icu4c
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}

- name: Install dependencies
run: bundle install
- name: Run tests ${{ matrix.rubyopt }}
run: bundle exec rake RUBYOPT="${{ matrix.rubyopt }}"
15 changes: 15 additions & 0 deletions ext/charlock_holmes/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,19 @@ static inline VALUE charlock_new_str2(const char *str)
#endif
}


#ifdef __cplusplus
extern "C"
{
#endif

extern void Init_charlock_holmes();
extern void _init_charlock_encoding_detector();
extern void _init_charlock_converter();
extern void _init_charlock_transliterator();

#ifdef __cplusplus
}
#endif

#endif
2 changes: 1 addition & 1 deletion ext/charlock_holmes/converter.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static VALUE rb_converter_convert(VALUE self, VALUE rb_txt, VALUE rb_src_enc, VA
if (status != U_BUFFER_OVERFLOW_ERROR) {
rb_raise(rb_eArgError, "%s", u_errorName(status));
}
out_buf = malloc(out_len);
out_buf = (char *) malloc(out_len);

// now do the actual conversion
status = U_ZERO_ERROR;
Expand Down
2 changes: 1 addition & 1 deletion ext/charlock_holmes/encoding_detector.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ static VALUE rb_encdec__alloc(VALUE klass)
UErrorCode status = U_ZERO_ERROR;
VALUE obj;

detector = calloc(1, sizeof(charlock_detector_t));
detector = (charlock_detector_t *) calloc(1, sizeof(charlock_detector_t));
obj = Data_Wrap_Struct(klass, NULL, rb_encdec__free, (void *)detector);

detector->csd = ucsdet_open(&status);
Expand Down
6 changes: 1 addition & 5 deletions ext/charlock_holmes/ext.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#include "common.h"

extern void _init_charlock_encoding_detector();
extern void _init_charlock_converter();
extern void _init_charlock_transliterator();

VALUE rb_mCharlockHolmes;

void Init_charlock_holmes() {
Expand All @@ -12,4 +8,4 @@ void Init_charlock_holmes() {
_init_charlock_encoding_detector();
_init_charlock_converter();
_init_charlock_transliterator();
}
}
26 changes: 26 additions & 0 deletions ext/charlock_holmes/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,30 @@
$CFLAGS << ' -Wall -funroll-loops'
$CFLAGS << ' -Wextra -O0 -ggdb3' if ENV['DEBUG']

minimal_program = <<~SRC
#include <unicode/translit.h>
int main() { return 0; }
SRC

# Pass -x c++ to force gcc to compile the test program
# as C++ (as it will end in .c by default).
compile_options = +"-x c++"

icu_requires_version_flag = checking_for("icu that requires explicit C++ version flag") do
!try_compile(minimal_program, compile_options)
end

if icu_requires_version_flag
abort "Cannot compile icu with your compiler: recent versions require C++17 support." unless %w[c++20 c++17 c++11 c++0x].any? do |std|
checking_for("icu that compiles with #{std} standard") do
flags = compile_options + " -std=#{std}"
if try_compile(minimal_program, flags)
$CPPFLAGS << flags

true
end
end
end
end

create_makefile 'charlock_holmes/charlock_holmes'
Loading