go.arsenm.dev/pcre@v0.0.0-20220530205550-74594f6c8b0e/README.md (about)

     1  # pcre
     2  
     3  [![Go Reference](https://pkg.go.dev/badge/go.arsenm.dev/pcre.svg)](https://pkg.go.dev/go.arsenm.dev/pcre)
     4  
     5  This package provides a CGo-free port of the PCRE2 regular expression library. The [lib](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](https://pkg.go.dev/regexp) package
     6  
     7  ---
     8  
     9  ## IMPORTANT NOTE!
    10  
    11  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.
    12  
    13  ---
    14  
    15  ## Supported GOOS/GOARCH:
    16  
    17  - linux/amd64
    18  - linux/386
    19  - linux/arm64
    20  - linux/arm
    21  - linux/riscv64
    22  - darwin/amd64
    23  - darwin/arm64
    24  
    25  More OS support is planned.
    26  
    27  ---
    28  
    29  ## How to transpile pcre2
    30  
    31  In order to transpile pcre2, a Go and C compiler (preferably GCC) will be needed.
    32  
    33  - First, install [ccgo](https://pkg.go.dev/modernc.org/ccgo/v3)
    34  
    35  - Then, download the pcre source code. It can be found here: https://github.com/PCRE2Project/pcre2.
    36  
    37  - Once downloaded, `cd` into the source directory
    38  
    39  - Run `./configure`. If cross-compiling, provide the path to the cross-compiler in the `CC` variable, and set `--target` to the target architecture.
    40  
    41  - When it completes, there should be a `Makefile` in the directory.
    42  
    43  - Run `ccgo -compiledb pcre.json make`. Do not add `-j` arguments to the make command.
    44  
    45  - Run the following command (replace items in triangle brackets):
    46  
    47  ```shell
    48  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
    49  ```
    50  
    51  - 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.
    52  
    53  - 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.