Pure-Go PCRE2 port
Go to file
Elara Musayelyan 4ce849193f
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Add riscv64 test
2023-08-04 20:25:57 -07:00
lib Add darwin/{amd,arm}64 to supported systems 2022-05-20 20:13:14 -07:00
.woodpecker.yml Add riscv64 test 2023-08-04 20:25:57 -07:00
error.go Update domain 2023-04-20 20:02:33 -07:00
glob_test.go Run formatter 2023-07-17 06:46:47 -07:00
glob.go Run formatter 2023-07-17 06:46:47 -07:00
go.mod Update domain 2023-04-20 20:02:33 -07:00
go.sum Initial Commit 2022-05-18 16:28:40 -07:00
LICENSE Initial Commit 2022-05-18 16:28:40 -07:00
LICENSE-PCRE2 Initial Commit 2022-05-18 16:28:40 -07:00
pcre_test.go Add Varnish test case 2023-07-27 09:41:27 -07:00
pcre.go Fix panic when pcre2 returns PCRE2_UNSET 2023-07-25 23:35:29 -06:00
README.md Add CI status badge to README 2023-07-27 09:44:57 -07:00
types.go Fix typo 2023-07-26 15:53:58 -07:00

pcre

Go Reference status-badge

This package provides a CGo-free port of the PCRE2 regular expression library. The lib directory contains source code automatically translated from PCRE2's C source. This package wraps that code and provides an interface as close as possible to Go's stdlib regexp package


IMPORTANT NOTE!

Due to the use of PCRE2, this library contains extra features such as lookaheads/lookbehinds. The stdlib regex engine, RE2, left these features out for a reason. It's easy to create regular expressions with this library that have exponential runtime. This creates the possibility of a denial of service attack. Only use this library if the extra features are needed and the user providing the regex is trusted (such as if it's in a config file). Otherwise, use the standard library regexp package.


Supported GOOS/GOARCH:

  • linux/amd64
  • linux/386
  • linux/arm64
  • linux/arm
  • linux/riscv64
  • darwin/amd64
  • darwin/arm64

More OS support is planned.


How to transpile pcre2

In order to transpile pcre2, a Go and C compiler (preferably GCC) will be needed.

  • First, install ccgo

  • Then, download the pcre source code. It can be found here: https://github.com/PCRE2Project/pcre2.

  • Once downloaded, cd into the source directory

  • Run ./configure. If cross-compiling, provide the path to the cross-compiler in the CC variable, and set --target to the target architecture.

  • When it completes, there should be a Makefile in the directory.

  • Run ccgo -compiledb pcre.json make. Do not add -j arguments to the make command.

  • Run the following command (replace items in triangle brackets):

CC=/usr/bin/gcc ccgo -o pcre2_<os>_<arch>.go -pkgname lib -trace-translation-units -export-externs X -export-defines D -export-fields F -export-structs S -export-typedefs T pcre.json .libs/libpcre2-8.a
  • If cross-compiling, set the CCGO_CC variable to to path of the cross-compiler, and the CCGO_AR variable to the path of the cross-compiler's ar binary. Also, set TARGET_GOARCH to the GOARCH you're targeting and TARGET_GOOS to the OS you're targeting.

  • Once the command completes, two go files will be created. One will start with pcre2, the other with capi. Copy both of these to the lib directory in this repo.