Skip to content

Commit

Permalink
Update README.md with new installation instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
4kills authored Jan 18, 2024
1 parent b59ac8d commit 0906e01
Showing 1 changed file with 18 additions and 48 deletions.
66 changes: 18 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ For a better user experience right from the start use V2 via `go get github.com/

# Installation

## Prerequisites (working [cgo](https://golang.org/cmd/cgo/))
For the library to work, you need cgo, libedflate (which is used by this library under the hood), and pkg-config (linker):

## Install [cgo](https://golang.org/cmd/cgo/)

**TL;DR**: Get **[cgo](https://golang.org/cmd/cgo/)** working.

In order to use this library with your Go source code, you must be able to use the Go tool **[cgo](https://golang.org/cmd/cgo/)**, which, in turn, requires a **GCC compiler**.

Expand All @@ -60,58 +64,24 @@ off of MinGW. Please note that [cgo](https://golang.org/cmd/cgo/) requires the 6

For **any other** the procedure should be about the same. Just google.

**TL;DR**: Get **[cgo](https://golang.org/cmd/cgo/)** working.

## Download and Installation

If you want to build for `$GOARCH=amd64` and either **Windows, Linux** or **MacOS** just Go get this library and everything will work right away.

(You may also use Go modules (available since Go 1.11) to get the version of a specific branch or tag if you want to try out or use experimental features. However, beware that these versions are not necessarily guaranteed to be stable or thoroughly tested.)

<details>

<summary> Instructions for building for different GOOS,GOARCH </summary>
## Install [pkg-config](https://www.freedesktop.org/wiki/Software/pkg-config/) and [libdeflate](https://github.com/ebiggers/libdeflate)

This SDK uses [libdeflate](https://github.com/ebiggers/libdeflate) under the hood. For the SDK to work, you need to install `libdeflate` on your system which is super easy!
Additionally we require [pkg-config](https://www.freedesktop.org/wiki/Software/pkg-config/) which facilitates linking `libdeflate` with this (cgo) SDK.
How exactly you install these two packages depends on your operating system.

First of all, it is not encouraged to build for non-64-bit archs, as this library works best for 64-bit systems.

A list of possible GOOS,GOARCH combinations can be viewed [here](https://golang.org/doc/install/source#environment).

**Instructions:**

1. You will need to compile and build the C [libdeflate](https://github.com/ebiggers/libdeflate) library for your target system by cloning the [repository](https://github.com/ebiggers/libdeflate) and executing the Makefile (specifying the build). *You should always use GCC for compilation as this produces the fastest libraries.*

2. Step 1 will yield compiled library files. You are going to want to use the static library (usually ending with .a \[in case of windows, rename .lib to .a\]), give it an adequate name (like `libdeflate_GOOS_GOARCH.a`) and copy it to the native/libs folder of this library.

3. Go to the native/cgo.go file, which should roughly look like this:
```go
package native

/*
#cgo CFLAGS: -I${SRCDIR}/libs/
#cgo windows,amd64 LDFLAGS: ${SRCDIR}/libs/libdeflate_windows_amd64.a
#cgo linux,amd64 LDFLAGS: ${SRCDIR}/libs/libdeflate_linux_amd64.a
#cgo darwin,amd64 LDFLAGS: ${SRCDIR}/libs/libdeflate_darwin_amd64.a
*/
import "C"
```
Now you want to add your build of libdeflate to the cgo directives, more specifically, to the linker flags, like this (omit the '+'):
```diff
package native

/*
#cgo CFLAGS: -I${SRCDIR}/libs/
+#cgo GOOS,GOARCH LDFLAGS: ${SRCDIR}/libs/libdeflate_GOOS_GOARCH.a
#cgo windows,amd64 LDFLAGS: ${SRCDIR}/libs/libdeflate_windows_amd64.a
#cgo linux,amd64 LDFLAGS: ${SRCDIR}/libs/libdeflate_linux_amd64.a
#cgo darwin,amd64 LDFLAGS: ${SRCDIR}/libs/libdeflate_darwin_amd64.a
*/
import "C"
#### MacOS (HomeBrew):
```sh
brew install libdeflate
brew install pkg-config
```

That's it! It should work now!
#### Linux:
Use the package manager available on your distro to install the required packages.

</details>
#### Windows (MinGW/WSL2):
Here, you can either use [WSL2](https://learn.microsoft.com/en-us/windows/wsl/install)
or [MinGW](https://www.mingw-w64.org/) and from there install the required packages.

# Usage

Expand Down

0 comments on commit 0906e01

Please sign in to comment.