crystal-lang / distribution-scripts

40 stars 23 forks source link

Build PCRE2 with JIT mode enabled on mac #232

Closed Blacksmoke16 closed 1 year ago

Blacksmoke16 commented 1 year ago
$ ruby --version
ruby 2.7.7p221 (2022-11-24 revision 168ec2b1e5) [x86_64-darwin22]

Omnibus successfully built PCRE2 on my mac with this change:

[Builder: pcre2] I | 2023-03-17T13:13:05-04:00 |   PKG_CONFIG_PATH="/opt/crystal/embedded/lib/pkgconfig"
[Builder: pcre2] I | 2023-03-17T13:13:05-04:00 | $ ./configure --prefix=/opt/crystal/embedded --disable-cpp --disable-shared --enable-unicode-properties --enable-utf --enable-jit
[Builder: pcre2] I | 2023-03-17T13:13:33-04:00 | Execute: `./configure --prefix=/opt/crystal/embedded --disable-cpp --disable-shared --enable-unicode-properties --enable-utf --enable-jit': 27.8581s
[Builder: pcre2] I | 2023-03-17T13:13:33-04:00 | Environment:
[Builder: pcre2] I | 2023-03-17T13:13:33-04:00 |   CFLAGS="-I/opt/crystal/embedded/include -O3 -D_FORTIFY_SOURCE=2 -fstack-protector -DMAC_OS_X_VERSION_MIN_REQUIRED=110000 -fPIC -arch arm64 -arch x86_64"
[Builder: pcre2] I | 2023-03-17T13:13:33-04:00 |   CPPFLAGS="-I/opt/crystal/embedded/include -O3 -D_FORTIFY_SOURCE=2 -fstack-protector -DMAC_OS_X_VERSION_MIN_REQUIRED=110000 -fPIC "
[Builder: pcre2] I | 2023-03-17T13:13:33-04:00 |   CXXFLAGS="-I/opt/crystal/embedded/include -O3 -D_FORTIFY_SOURCE=2 -fstack-protector -DMAC_OS_X_VERSION_MIN_REQUIRED=110000 -fPIC -arch arm64 -arch x86_64"
[Builder: pcre2] I | 2023-03-17T13:13:33-04:00 |   LDFLAGS="-Wl,-rpath,/opt/crystal/embedded/lib -L/opt/crystal/embedded/lib"
[Builder: pcre2] I | 2023-03-17T13:13:33-04:00 |   LD_RUN_PATH="/opt/crystal/embedded/lib"
[Builder: pcre2] I | 2023-03-17T13:13:33-04:00 |   OMNIBUS_INSTALL_DIR="/opt/crystal"
[Builder: pcre2] I | 2023-03-17T13:13:33-04:00 |   PATH="<redacted>"
[Builder: pcre2] I | 2023-03-17T13:13:33-04:00 |   PKG_CONFIG_PATH="/opt/crystal/embedded/lib/pkgconfig"
[Builder: pcre2] I | 2023-03-17T13:13:33-04:00 | $ make -j 17
[Builder: pcre2] I | 2023-03-17T13:13:58-04:00 | Execute: `make -j 17': 24.9378s
[Builder: pcre2] I | 2023-03-17T13:13:58-04:00 | Environment:
[Builder: pcre2] I | 2023-03-17T13:13:58-04:00 |   CFLAGS="-I/opt/crystal/embedded/include -O3 -D_FORTIFY_SOURCE=2 -fstack-protector -DMAC_OS_X_VERSION_MIN_REQUIRED=110000 -fPIC -arch arm64 -arch x86_64"
[Builder: pcre2] I | 2023-03-17T13:13:58-04:00 |   CPPFLAGS="-I/opt/crystal/embedded/include -O3 -D_FORTIFY_SOURCE=2 -fstack-protector -DMAC_OS_X_VERSION_MIN_REQUIRED=110000 -fPIC "
[Builder: pcre2] I | 2023-03-17T13:13:58-04:00 |   CXXFLAGS="-I/opt/crystal/embedded/include -O3 -D_FORTIFY_SOURCE=2 -fstack-protector -DMAC_OS_X_VERSION_MIN_REQUIRED=110000 -fPIC -arch arm64 -arch x86_64"
[Builder: pcre2] I | 2023-03-17T13:13:58-04:00 |   LDFLAGS="-Wl,-rpath,/opt/crystal/embedded/lib -L/opt/crystal/embedded/lib"
[Builder: pcre2] I | 2023-03-17T13:13:58-04:00 |   LD_RUN_PATH="/opt/crystal/embedded/lib"
[Builder: pcre2] I | 2023-03-17T13:13:58-04:00 |   OMNIBUS_INSTALL_DIR="/opt/crystal"
[Builder: pcre2] I | 2023-03-17T13:13:58-04:00 |   PATH="<redacted>"
[Builder: pcre2] I | 2023-03-17T13:13:58-04:00 |   PKG_CONFIG_PATH="/opt/crystal/embedded/lib/pkgconfig"
[Builder: pcre2] I | 2023-03-17T13:13:58-04:00 | $ make install
[Builder: pcre2] I | 2023-03-17T13:13:58-04:00 | Execute: `make install': 0.5981s
[Builder: pcre2] I | 2023-03-17T13:13:58-04:00 | Build pcre2: 53.3974s
[Builder: pcre2] I | 2023-03-17T13:13:58-04:00 | Finished build

But the build ultimately failed, for I'd assume due to an unrelated/known issue:

Output:

    ./bin/crystal --release --stats -o /opt/crystal/embedded/bin/crystal src/compiler/crystal.cr
Using compiled compiler at .build/crystal

Error:

    Error: unknown command: --release
make[1]: *** [/opt/crystal/embedded/bin/crystal] Error 1

Resolves #228

straight-shoota commented 1 year ago

CI workflow run: https://app.circleci.com/pipelines/github/crystal-lang/crystal/11511/workflows/7b791aaa-73cf-4e89-be65-5b25bb3d10ec

straight-shoota commented 1 year ago

@Blacksmoke16 Have you tested the artifacts from the CI workflow to ensure JIT compilation is working?

Blacksmoke16 commented 1 year ago

Seems like it is:

jit_enabled = uninitialized UInt32

LibPCRE2.config LibPCRE2::CONFIG_JIT, pointerof(jit_enabled)

pp jit_enabled
$ ./crystal-ci-update-distribution-scripts-pcre2-jit-dev-1/bin/crystal run -Duse_pcre2 test.cr
1

While before from https://app.circleci.com/pipelines/github/crystal-lang/crystal/11516/workflows/1be479c4-9fa7-4c5c-bed0-6cc779c784c6/jobs/75135, it is:

$ ./crystal-1.8.0-dev-1/bin/crystal run test.cr
0

Also I can't remember if its expected or not, but none of the 1.7.x tarballs have pcre2-8 within the embedded/lib directory so it fails when using -Duse_pcre2, so technically you couldn't use it to test at all.

straight-shoota commented 1 year ago

Thanks, then we can merge this.

Also I can't remember if its expected or not, but none of the 1.7.x tarballs have pcre2-8 within the embedded/lib directory so it fails when using -Duse_pcre2, so technically you couldn't use it to test at all.

Yes, that's expected. You need to install it explicitly.

Blacksmoke16 commented 1 year ago

Yes, that's expected. You need to install it explicitly.

But the catch is I do have pcre2 installed explicitly, but won't it not be able to find it due to the lib path pointing at that single directly that doesn't have it?

straight-shoota commented 1 year ago

CRYSTAL_LIBRARY_PATH is not exclusive. It goes on top of any other library paths configured with the system/linker. As long as ld is able to find the library somewhere, you should be good.