diff --git a/.github/workflows/regex-engine.yml b/.github/workflows/regex-engine.yml index c75093d01378..ac3ac7c52fb0 100644 --- a/.github/workflows/regex-engine.yml +++ b/.github/workflows/regex-engine.yml @@ -24,8 +24,8 @@ jobs: - name: Install PCRE2 run: apk add pcre2-dev - name: Assert using PCRE2 - run: bin/crystal eval -Duse_pcre2 'abort unless Regex::Engine == Regex::PCRE2' + run: bin/crystal eval 'abort unless Regex::Engine == Regex::PCRE2' - name: Assert select PCRE run: bin/crystal eval -Duse_pcre 'abort unless Regex::Engine == Regex::PCRE' - name: Run Regex specs - run: bin/crystal spec -Duse_pcre2 --order=random spec/std/regex* + run: bin/crystal spec --order=random spec/std/regex* diff --git a/.github/workflows/win.yml b/.github/workflows/win.yml index e06a0ef88f03..8957e98963f2 100644 --- a/.github/workflows/win.yml +++ b/.github/workflows/win.yml @@ -15,7 +15,7 @@ jobs: make deps - name: Cross-compile Crystal run: | - LLVM_TARGETS=X86 bin/crystal build --cross-compile --target x86_64-pc-windows-msvc src/compiler/crystal.cr -Dwithout_playground -Dwithout_iconv -Dwithout_interpreter + LLVM_TARGETS=X86 bin/crystal build --cross-compile --target x86_64-pc-windows-msvc src/compiler/crystal.cr -Dwithout_playground -Dwithout_iconv -Dwithout_interpreter -Duse_pcre - name: Upload Crystal object file uses: actions/upload-artifact@v3 diff --git a/Makefile b/Makefile index 7db99f0be775..7eadaf4e9f3d 100644 --- a/Makefile +++ b/Makefile @@ -197,7 +197,7 @@ $(O)/primitives_spec: $(O)/crystal $(DEPS) $(SOURCES) $(SPEC_SOURCES) $(O)/crystal: $(DEPS) $(SOURCES) $(call check_llvm_config) @mkdir -p $(O) - $(EXPORTS) $(EXPORTS_BUILD) ./bin/crystal build $(FLAGS) -o $@ src/compiler/crystal.cr -D without_openssl -D without_zlib + $(EXPORTS) $(EXPORTS_BUILD) ./bin/crystal build $(FLAGS) -o $@ src/compiler/crystal.cr -D without_openssl -D without_zlib -D use_pcre $(LLVM_EXT_OBJ): $(LLVM_EXT_DIR)/llvm_ext.cc $(call check_llvm_config) diff --git a/Makefile.win b/Makefile.win index 7c10931ef1d3..dc89bcc74a8c 100644 --- a/Makefile.win +++ b/Makefile.win @@ -190,7 +190,7 @@ $(O)\crystal.exe: $(DEPS) $(SOURCES) $(O)\crystal.res @$(call MKDIR,"$(O)") $(call export_vars) $(call export_build_vars) - .\bin\crystal build $(FLAGS) -o "$(O)\crystal-next.exe" src\compiler\crystal.cr -D without_openssl -D without_zlib -D without_playground --link-flags=/PDBALTPATH:crystal.pdb "--link-flags=$(realpath $(O)\crystal.res)" + .\bin\crystal build $(FLAGS) -o "$(O)\crystal-next.exe" src\compiler\crystal.cr -D without_openssl -D without_zlib -D without_playground -D use_pcre --link-flags=/PDBALTPATH:crystal.pdb "--link-flags=$(realpath $(O)\crystal.res)" $(call MV,"$(O)\crystal-next.exe","$@") $(call MV,"$(O)\crystal-next.pdb","$(O)\crystal.pdb") diff --git a/src/regex/engine.cr b/src/regex/engine.cr index c2a336accd0d..6c0fdc2e6217 100644 --- a/src/regex/engine.cr +++ b/src/regex/engine.cr @@ -1,4 +1,8 @@ -{% if flag?(:use_pcre2) %} +# The following condition ensures that the engine selection respects `-Duse_pcre2`/`-Duse_pcre`, +# and if none is given it tries to check for availability of `libpcre2` with `pkg-config`. +# If `pkg-config` is unavailable, the default is PCRE2. If `pkg-config` is available but +# has no information about a `libpcre2` package, it falls back to PCRE. +{% if flag?(:use_pcre2) || (!flag?(:use_pcre) && (flag?(:win32) || `hash pkg-config 2> /dev/null && (pkg-config --silence-errors --modversion libpcre2-8 || printf %s false) || true` != "false")) %} require "./pcre2" # :nodoc: