Skip to content

Commit 9a8763a

Browse files
authored
release static libw2v (#6)
* release static libw2v * GitHub Action for Make * fix CMake for windows * add CPack
1 parent 86d9af7 commit 9a8763a

File tree

6 files changed

+89
-8
lines changed

6 files changed

+89
-8
lines changed

.github/workflows/release.yml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
##
2+
## release static library
3+
##
4+
name: release
5+
on:
6+
push:
7+
tags:
8+
- '*'
9+
10+
jobs:
11+
release:
12+
permissions: write-all
13+
runs-on: ${{ matrix.os }}-latest
14+
strategy:
15+
matrix:
16+
os: [ubuntu, macos]
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- name: build
22+
uses: fogfish/cmake_build_action@master
23+
with:
24+
config: ${{ matrix.configs }}
25+
submodule_update: OFF
26+
run_tests: OFF
27+
cmake_args: -DCMAKE_BUILD_TYPE=Release ./libw2v
28+
create_package: ON
29+
30+
- name: Upload binaries to release
31+
uses: svenstaro/upload-release-action@v2
32+
with:
33+
repo_token: ${{ secrets.GITHUB_TOKEN }}
34+
file: libw2v/build/*.tar.gz
35+
tag: ${{ github.ref }}
36+
overwrite: true
37+
file_glob: true

README.md

+28-3
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ The project offers a solution as both a Golang module and a simple command-line
7272

7373
### Pre-requisites
7474

75-
A dynamically linked library is required for the CGO bridge to integrate with Max Fomichev's word2vec C++ library. Ensure that the necessary C++ libraries are installed and properly configured on your system to use this functionality.
75+
A static linked library is required for the CGO bridge to integrate with Max Fomichev's word2vec C++ library. Ensure that the necessary C++ libraries are installed and properly configured on your system to use this functionality.
7676

77-
To build the required dynamically linked library, use a C++11 compatible compiler and CMake 3.1 or higher. This step is essential before proceeding with the installation and usage of the Golang module.
77+
To build the required static linked library, use a C++11 compatible compiler and CMake 3.10 or higher. This step is essential before proceeding with the installation and usage of the Golang module.
7878

7979
```bash
8080
mkdir _build && cd _build
@@ -84,7 +84,7 @@ make
8484
cp ../libw2v/lib/libw2v.dylib /usr/local/lib/libw2v.dylib
8585
```
8686

87-
**Note**: The project does not currently distribute library binaries, though this feature is planned for a future version. You will need to build the binaries yourself for your target runtime. If you need assistance, please [raise an issue](https://github.com/fogfish/word2vec/issues).
87+
**Note**: The static linked libraries are distributed as binary, download them from [releases](https://github.com/fogfish/word2vec/releases) and extract it to `libw2v` dir.
8888

8989

9090
## Usage Command line utility
@@ -172,6 +172,31 @@ Use `go get` to retrieve the library and add it as dependency to your applicatio
172172
go get -u github.com/fogfish/word2vec
173173
```
174174

175+
However, the availability of static library for the target platform (linux, darwin) is the primary requirement. There are two options finishing the installation the module.
176+
177+
**Option 1: build the library (recommended)**
178+
179+
```bash
180+
go get -u github.com/fogfish/word2vec
181+
182+
git clone --depth=1 --branch=main https://github.com/fogfish/word2vec word2vec
183+
cd word2vec && cmake -DCMAKE_BUILD_TYPE=Release libw2v && make && cd ..
184+
go mod edit -replace github.com/fogfish/word2vec=./word2vec
185+
```
186+
187+
**Option 2: using the pre-build library**
188+
189+
```bash
190+
go get -u github.com/fogfish/word2vec
191+
192+
git clone --depth=1 --branch=main https://github.com/fogfish/word2vec word2vec
193+
cd word2vec/libw2v
194+
curl -L -O https://github.com/fogfish/word2vec/releases/download/v0.0.0/w2v-0.0.0-Darwin.tar.gz
195+
tar -zxf w2v-0.0.0-Darwin.tar.gz --strip-components=1
196+
cd ../..
197+
go mod edit -replace github.com/fogfish/word2vec=./word2vec
198+
```
199+
175200
### Embeddings
176201

177202
Calculate embeddings for either a single word or a bag of words.

libw2v/CMakeLists.txt

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1+
cmake_minimum_required(VERSION 3.10)
12
project (w2v)
2-
cmake_minimum_required(VERSION 3.1)
33

44
set(PROJECT_ROOT_DIR ${CMAKE_SOURCE_DIR})
55
set(LIBRARY_OUTPUT_PATH ${PROJECT_ROOT_DIR}/lib)
66

77
set(CMAKE_CXX_STANDARD 11)
88
set(CMAKE_CXX_STANDARD_REQUIRED ON)
9-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Werror")
109
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -ggdb")
1110
set(CMAKE_CXX_FLAGS_RELEASE "-Ofast -march=native -funroll-loops -ftree-vectorize -DNDEBUG")
1211

1312
set(PROJECT_INCLUDE_DIR ${PROJECT_ROOT_DIR}/include)
1413

14+
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
15+
message("-- Detecting Darwin - done")
16+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Werror")
17+
endif()
18+
1519
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
20+
message("-- Detecting Linux - done")
21+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Werror")
1622
set(LIBS "-pthread")
1723
endif()
1824

@@ -21,3 +27,15 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
2127
endif()
2228

2329
add_subdirectory(src)
30+
31+
set(CPACK_SOURCE_GENERATOR "TGZ")
32+
set(CPACK_PACKAGE_VERSION_MAJOR "0")
33+
set(CPACK_PACKAGE_VERSION_MINOR "0")
34+
set(CPACK_PACKAGE_VERSION_PATCH "0")
35+
set(CPACK_SOURCE_IGNORE_FILES
36+
\\.git/
37+
build/
38+
".*~$"
39+
)
40+
set(CPACK_VERBATIM_VARIABLES YES)
41+
include(CPack)

libw2v/src/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
cmake_minimum_required(VERSION 3.10)
12
project (w2v)
2-
cmake_minimum_required(VERSION 3.1)
33

44
set (PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
55

@@ -37,7 +37,7 @@ set(PRJ_SRCS
3737
${ADD_SRCS}
3838
)
3939

40-
add_library(${PROJECT_NAME} SHARED ${PRJ_SRCS})
40+
add_library(${PROJECT_NAME} STATIC ${PRJ_SRCS})
4141
target_link_libraries(${PROJECT_NAME} ${LIBS})
4242

4343
install(TARGETS ${PROJECT_NAME} DESTINATION lib)

libw2v/src/w2v.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <iostream>
88
#include <iomanip>
9+
#include <cstring>
910
#include <stdexcept>
1011

1112
class H

word2vec.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ package word2vec
1010

1111
/*
1212
#cgo CFLAGS: -Ilibw2v/include
13-
#cgo LDFLAGS: -L . -lw2v
13+
#cgo LDFLAGS: -Llibw2v/lib -lw2v -lstdc++
1414
#include <stdlib.h>
1515
#include "w2v.h"
1616
*/

0 commit comments

Comments
 (0)