Full Blog TOC

Full Blog Table Of Content with Keywords Available HERE

Monday, April 21, 2025

Using VectorScan In GO

 

In this post we will review how to prepare the environment to use VectorScan in Go.


VectorScan is a fork of Intel's HyperScan supplying a high-performance multiple regex matching.

Using it in GO, can be quite cumbersome due to need to link with the C library.

Listed below is a Dockerfile displaying the step to do it:

FROM golang:1.23.0

# build the VectorScan
RUN apt update
RUN apt install -y git build-essential cmake ragel pkg-config libsqlite3-dev libpcap-dev libboost-all-dev
WORKDIR /
RUN git clone https://github.com/VectorCamp/vectorscan.git
WORKDIR /vectorscan
RUN git checkout vectorscan/5.4.11
WORKDIR /vectorscan/build
RUN cmake ../ -DBUILD_SHARED_LIBS=On
RUN make -j 6


# Run the gohs example linked with the VectorScan

COPY ./src/go.mod /src/
COPY ./src/go.sum /src/
WORKDIR /src
RUN go mod download

ADD ./src /src
RUN export PKG_CONFIG_PATH=/vectorscan/build/:/vectorscan/build/lib:$PKG_CONFIG_PATH &&CGO_CFLAGS="-g -O2 -I/vectorscan/src -I/vectorscan/build" CGO_LDFLAGS="-lhs -L/vectorscan/build/ -L/vectorscan/build/lib" GOOS=linux go build -o /regex

RUN export LD_LIBRARY_PATH=/vectorscan/build/lib:$LD_LIBRARY_PATH && echo ${LD_LIBRARY_PATH} && /regex


The first step install the VectorScan build related tools, download the VectorScan library GIT, and compiles it.


The second step uses GoHS which is wrapper for the VectorScan library.
The main.go is simply the example in gohs.

I've spent a couple of hours figuring the problems here, so I put in in this post in case it would assist anyone else.





No comments:

Post a Comment