Skip to content

Commit

Permalink
OCaml 5.0 compatibility (HaxeFoundation#11272)
Browse files Browse the repository at this point in the history
* OCaml 5 compatibility
* [eval] Disable StdThread.kill which has been removed in ocaml 5
* [ci] Build and test with both ocaml 4 and 5 on linux
  • Loading branch information
kLabz authored and 0b1kn00b committed Jan 25, 2024
1 parent b0d2143 commit 5c11fa3
Show file tree
Hide file tree
Showing 37 changed files with 184 additions and 141 deletions.
15 changes: 11 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ jobs:
env:
PLATFORM: linux64
OPAMYES: 1
strategy:
fail-fast: false
matrix:
ocaml: ["4.08.1", "5.0.0"]
steps:
- uses: actions/checkout@main
with:
Expand All @@ -269,7 +273,7 @@ jobs:
uses: actions/[email protected]
with:
path: ~/.opam/
key: ${{ runner.os }}-${{ hashFiles('./haxe.opam', './libs/') }}-2
key: ${{ runner.os }}-${{ matrix.ocaml }}-${{ hashFiles('./haxe.opam', './libs/') }}

- name: Install Neko from S3
run: |
Expand Down Expand Up @@ -303,6 +307,7 @@ jobs:
set -ex
opam init # --disable-sandboxing
opam update
opam switch create ${{ matrix.ocaml }}
opam pin add haxe . --no-action
opam install haxe --deps-only --assume-depexts
opam list
Expand Down Expand Up @@ -343,11 +348,12 @@ jobs:
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: linuxBinaries
name: linuxBinaries${{ (matrix.ocaml == '5.0.0' && '_ocaml5') || '' }}
path: out

- name: Upload xmldoc artifact
uses: actions/upload-artifact@v3
if: matrix.ocaml == '4.08.1'
with:
name: xmldoc
path: extra/doc
Expand All @@ -363,6 +369,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ocaml: ["4.08.1", "5.0.0"]
target: [macro, js, hl, cpp, 'java,jvm', cs, php, python, lua, flash, neko]
include:
- target: hl
Expand All @@ -379,7 +386,7 @@ jobs:
submodules: recursive
- uses: actions/download-artifact@v3
with:
name: linuxBinaries
name: linuxBinaries${{ (matrix.ocaml == '5.0.0' && '_ocaml5') || '' }}
path: linuxBinaries

- name: Install Neko from S3
Expand Down Expand Up @@ -586,7 +593,7 @@ jobs:
uses: actions/[email protected]
with:
path: ~/.opam/
key: ${{ runner.os }}-${{ hashFiles('./haxe.opam', './libs/') }}-2
key: ${{ runner.os }}-${{ hashFiles('./haxe.opam', './libs/') }}

- name: Install Neko from S3
run: |
Expand Down
3 changes: 3 additions & 0 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ devcontainer:
# Install OCaml libraries
COPY haxe.opam .
RUN opam init --disable-sandboxing
RUN opam switch create 4.08.1
RUN eval $(opam env)
RUN opam env
RUN opam install . --yes --deps-only --no-depexts
RUN opam list
RUN ocamlopt -v
Expand Down
6 changes: 0 additions & 6 deletions extra/github-actions/cache-opam-windows.yml

This file was deleted.

6 changes: 0 additions & 6 deletions extra/github-actions/cache-opam.yml

This file was deleted.

27 changes: 23 additions & 4 deletions extra/github-actions/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,22 @@ jobs:
env:
PLATFORM: linux64
OPAMYES: 1
strategy:
fail-fast: false
matrix:
ocaml: ["4.08.1", "5.0.0"]
steps:
- uses: actions/checkout@main
with:
submodules: recursive

@import cache-opam.yml
- name: Cache opam
id: cache-opam
uses: actions/[email protected]
with:
path: ~/.opam/
key: ${{ runner.os }}-${{ matrix.ocaml }}-${{ hashFiles('./haxe.opam', './libs/') }}

@import install-neko-unix.yml

- name: Install dependencies
Expand All @@ -79,6 +89,7 @@ jobs:
set -ex
opam init # --disable-sandboxing
opam update
opam switch create ${{ matrix.ocaml }}
opam pin add haxe . --no-action
opam install haxe --deps-only --assume-depexts
opam list
Expand Down Expand Up @@ -119,11 +130,12 @@ jobs:
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: linuxBinaries
name: linuxBinaries${{ (matrix.ocaml == '5.0.0' && '_ocaml5') || '' }}
path: out

- name: Upload xmldoc artifact
uses: actions/upload-artifact@v3
if: matrix.ocaml == '4.08.1'
with:
name: xmldoc
path: extra/doc
Expand All @@ -139,6 +151,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ocaml: ["4.08.1", "5.0.0"]
target: [macro, js, hl, cpp, 'java,jvm', cs, php, python, lua, flash, neko]
include:
- target: hl
Expand All @@ -155,7 +168,7 @@ jobs:
submodules: recursive
- uses: actions/download-artifact@v3
with:
name: linuxBinaries
name: linuxBinaries${{ (matrix.ocaml == '5.0.0' && '_ocaml5') || '' }}
path: linuxBinaries

@import install-neko-unix.yml
Expand Down Expand Up @@ -325,7 +338,13 @@ jobs:
with:
submodules: recursive

@import cache-opam.yml
- name: Cache opam
id: cache-opam
uses: actions/[email protected]
with:
path: ~/.opam/
key: ${{ runner.os }}-${{ hashFiles('./haxe.opam', './libs/') }}

@import install-neko-unix.yml
@import build-mac.yml

Expand Down
5 changes: 3 additions & 2 deletions haxe.opam
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ build: [
install: [make "install" "INSTALL_DIR=%{prefix}%"]
remove: [make "uninstall" "INSTALL_DIR=%{prefix}%"]
depends: [
"ocaml" {>= "4.08"}
("ocaml" {>= "5.0"} & ("camlp5" {build}))
| ("ocaml" {>= "4.08" & < "5.0"} & ("camlp5" {build & = "8.00"}))
"ocamlfind" {build}
"dune" {>= "1.11"}
"camlp5" {build & = "8.00"}
"sedlex" {>= "2.0"}
"xml-light"
"extlib" {>= "1.7.8"}
"sha"
"camlp-streams"
"conf-libpcre2-8"
"conf-zlib"
"conf-neko"
Expand Down
42 changes: 21 additions & 21 deletions libs/extc/extc_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ int Zflush_val(value zflush_val) {
case 4: return Z_FINISH;
// TODO: support Z_BLOCK and Z_TREE
// TODO: append the received value
default: failwith("Error in `Zflush_val` (extc_stubs.c): Unknown zflush value");
default: caml_failwith("Error in `Zflush_val` (extc_stubs.c): Unknown zflush value");
}
assert(0);
}
Expand Down Expand Up @@ -222,14 +222,14 @@ CAMLprim value zlib_deflate_init2(value level_val, value window_bits_val) {
break;
case Z_STREAM_ERROR:
// TODO: use stream->msg to get _zlib_'s text message
failwith("Error in `zlib_deflate_init2` (extc_stubs.c): call to `deflateInit2` failed: Z_STREAM_ERROR");
caml_failwith("Error in `zlib_deflate_init2` (extc_stubs.c): call to `deflateInit2` failed: Z_STREAM_ERROR");
break;
case Z_VERSION_ERROR:
// TODO: use stream->msg to get _zlib_'s text message
failwith("Error in `zlib_deflate_init2` (extc_stubs.c): call to `deflateInit2` failed: Z_VERSION_ERROR");
caml_failwith("Error in `zlib_deflate_init2` (extc_stubs.c): call to `deflateInit2` failed: Z_VERSION_ERROR");
break;
default:
failwith("Error in `zlib_deflate_init2` (extc_stubs.c): unknown return code from `deflateInit2`");
caml_failwith("Error in `zlib_deflate_init2` (extc_stubs.c): unknown return code from `deflateInit2`");
}
assert(0);
}
Expand Down Expand Up @@ -275,7 +275,7 @@ CAMLprim value zlib_deflate(value stream_val, value src, value spos, value slen,
if (deflate_result == Z_OK || deflate_result == Z_STREAM_END) {
stream->next_in = NULL;
stream->next_out = NULL;
value zresult = alloc_small(3, 0);
value zresult = caml_alloc_small(3, 0);
// z_finish
Field(zresult, 0) = Val_bool(deflate_result == Z_STREAM_END);
// z_read
Expand All @@ -291,14 +291,14 @@ CAMLprim value zlib_deflate(value stream_val, value src, value spos, value slen,
break;
case Z_STREAM_ERROR:
// TODO: use stream->msg to get _zlib_'s text message
failwith("Error in `zlib_deflate` (extc_stubs.c): call to `deflate` failed: Z_STREAM_ERROR");
caml_failwith("Error in `zlib_deflate` (extc_stubs.c): call to `deflate` failed: Z_STREAM_ERROR");
break;
case Z_BUF_ERROR:
// TODO: use stream->msg to get _zlib_'s text message
failwith("Error in `zlib_deflate` (extc_stubs.c): call to `deflate` failed: Z_BUF_ERROR");
caml_failwith("Error in `zlib_deflate` (extc_stubs.c): call to `deflate` failed: Z_BUF_ERROR");
break;
default:
failwith("Error in `zlib_deflate` (extc_stubs.c): unknown return code from `deflate`");
caml_failwith("Error in `zlib_deflate` (extc_stubs.c): unknown return code from `deflate`");
}
assert(0);
}
Expand All @@ -309,14 +309,14 @@ CAMLprim value zlib_deflate_bytecode(value *arg, int nargs) {

CAMLprim value zlib_deflate_end(value zv) {
if( deflateEnd(ZStreamP_val(zv)) != 0 )
failwith("zlib_deflate_end");
caml_failwith("zlib_deflate_end");
return Val_unit;
}

CAMLprim value zlib_inflate_init(value wbits) {
value z = zlib_new_stream();
if( inflateInit2(ZStreamP_val(z),Int_val(wbits)) != Z_OK )
failwith("zlib_inflate_init");
caml_failwith("zlib_inflate_init");
return z;
}

Expand All @@ -330,12 +330,12 @@ CAMLprim value zlib_inflate( value zv, value src, value spos, value slen, value
z->avail_in = Int_val(slen);
z->avail_out = Int_val(dlen);
if( (r = inflate(z,Int_val(flush))) < 0 )
failwith("zlib_inflate");
caml_failwith("zlib_inflate");

z->next_in = NULL;
z->next_out = NULL;

res = alloc_small(3, 0);
res = caml_alloc_small(3, 0);
Field(res, 0) = Val_bool(r == Z_STREAM_END);
Field(res, 1) = Val_int(Int_val(slen) - z->avail_in);
Field(res, 2) = Val_int(Int_val(dlen) - z->avail_out);
Expand All @@ -348,7 +348,7 @@ CAMLprim value zlib_inflate_bytecode(value * arg, int nargs) {

CAMLprim value zlib_inflate_end(value zv) {
if( inflateEnd(ZStreamP_val(zv)) != 0 )
failwith("zlib_inflate_end");
caml_failwith("zlib_inflate_end");
return Val_unit;
}

Expand All @@ -368,13 +368,13 @@ CAMLprim value executable_path(value u) {
#ifdef _WIN32
char path[MAX_PATH];
if( GetModuleFileName(NULL,path,MAX_PATH) == 0 )
failwith("executable_path");
caml_failwith("executable_path");
return caml_copy_string(path);
#elif __APPLE__
char path[MAXPATHLEN+1];
uint32_t path_len = MAXPATHLEN;
if ( _NSGetExecutablePath(path, &path_len) )
failwith("executable_path");
caml_failwith("executable_path");
return caml_copy_string(path);
#elif __FreeBSD__
char path[PATH_MAX];
Expand All @@ -387,7 +387,7 @@ CAMLprim value executable_path(value u) {
len = sizeof(path);
error = sysctl(name, 4, path, &len, NULL, 0);
if( error < 0 )
failwith("executable_path");
caml_failwith("executable_path");
return caml_copy_string(path);
#else
char path[PATH_MAX];
Expand All @@ -397,7 +397,7 @@ CAMLprim value executable_path(value u) {
if( p != NULL )
return caml_copy_string(p);
else
failwith("executable_path");
caml_failwith("executable_path");
}
path[length] = '\0';
return caml_copy_string(path);
Expand All @@ -408,12 +408,12 @@ CAMLprim value get_full_path( value f ) {
#ifdef _WIN32
char path[MAX_PATH];
if( GetFullPathName(String_val(f),MAX_PATH,path,NULL) == 0 )
failwith("get_full_path");
caml_failwith("get_full_path");
return caml_copy_string(path);
#else
char path[4096];
if( realpath(String_val(f),path) == NULL )
failwith("get_full_path");
caml_failwith("get_full_path");
return caml_copy_string(path);
#endif
}
Expand All @@ -428,7 +428,7 @@ CAMLprim value get_real_path( value path ) {

// this will ensure the full class path with proper casing
if( GetFullPathName(String_val(path),MAX_PATH,out,NULL) == 0 )
failwith("get_real_path");
caml_failwith("get_real_path");

len = strlen(out);
i = 0;
Expand Down Expand Up @@ -501,7 +501,7 @@ CAMLprim value sys_time() {
ULARGE_INTEGER ui;
GetSystemTime(&t);
if( !SystemTimeToFileTime(&t,&ft) )
failwith("sys_cpu_time");
caml_failwith("sys_cpu_time");
ui.LowPart = ft.dwLowDateTime;
ui.HighPart = ft.dwHighDateTime;
return caml_copy_double( ((double)ui.QuadPart) / 10000000.0 - EPOCH_DIFF );
Expand Down
4 changes: 2 additions & 2 deletions libs/extc/process_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@
#define val_null Val_int(0)
#define val_some(v) Field(v,0)
#define val_int(v) Int_val(v)
#define neko_error() failwith(__FUNCTION__)
#define neko_error() caml_failwith(__FUNCTION__)

static value alloc_private( int size ) {
return alloc((size + sizeof(value) - 1) / sizeof(value), Abstract_tag);
return caml_alloc((size + sizeof(value) - 1) / sizeof(value), Abstract_tag);
}

// --- buffer api
Expand Down
2 changes: 1 addition & 1 deletion libs/extlib-leftovers/uTF8.ml
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ let rec iter_aux proc s i =

let iter proc s = iter_aux proc s 0

let compare s1 s2 = Pervasives.compare s1 s2
let compare s1 s2 = Stdlib.compare s1 s2

exception Malformed_code

Expand Down
4 changes: 2 additions & 2 deletions libs/ilib/peReader.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ open ExtList;;
exception Error_message of string

type reader_ctx = {
ch : Pervasives.in_channel;
ch : Stdlib.in_channel;
i : IO.input;
verbose : bool;
}
Expand All @@ -42,7 +42,7 @@ let seek r pos =
seek_in r.ch pos

let pos r =
Pervasives.pos_in r.ch
Stdlib.pos_in r.ch

let info r msg =
if r.verbose then
Expand Down
Loading

0 comments on commit 5c11fa3

Please sign in to comment.