Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add mingw-x64 to test matrix #15

Merged
merged 41 commits into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
6a37140
add mingw-x64 to test matrix
shogo82148 Oct 5, 2020
280ee78
use `msys2_shell.cmd -c`
shogo82148 Oct 5, 2020
7fc7162
shell: bash
shogo82148 Oct 5, 2020
1e1a183
Revert "use `msys2_shell.cmd -c`"
shogo82148 Oct 5, 2020
a15ee62
fix script name
shogo82148 Oct 5, 2020
8d5a721
add -no-start -mingw64 -here option
shogo82148 Oct 5, 2020
53cade2
msys2_shell.cmd -c
shogo82148 Oct 5, 2020
4d70b00
fix syntax error
shogo82148 Oct 5, 2020
8c6ca89
shell: cmd
shogo82148 Oct 5, 2020
c7be91d
-no-start -defterm -mingw64 -here
shogo82148 Oct 5, 2020
be3ade9
shell
shogo82148 Oct 5, 2020
72e652c
uses: msys2/setup-msys2@v2
shogo82148 Oct 5, 2020
9502fee
install libiconv-devel
shogo82148 Oct 5, 2020
5062e49
install mingw-w64-x86_64-libiconv
shogo82148 Oct 5, 2020
e42f645
https://stackoverflow.com/questions/13653287/how-do-i-statically-link…
shogo82148 Oct 5, 2020
a42a80e
make LDFLAGS=libiconv.a
shogo82148 Oct 5, 2020
3f4cadd
bump up mecab v0.996.4
shogo82148 Oct 6, 2020
ea73c1f
remove LDFLAGS=libiconv.a
shogo82148 Oct 6, 2020
6e5838c
build mecab in parallel
shogo82148 Oct 6, 2020
bd3f686
add --host=x86_64-w64-mingw32
shogo82148 Oct 6, 2020
3717996
skip make check
shogo82148 Oct 6, 2020
4aeca9b
sudo in not installed in mingw
shogo82148 Oct 6, 2020
e3c790f
ldconfig: command not found
shogo82148 Oct 6, 2020
b6d24bb
path-type: inherit
shogo82148 Oct 6, 2020
2d9941c
remove --race option
shogo82148 Oct 6, 2020
5cf3dbb
more detail error
shogo82148 Oct 6, 2020
3f9e228
fix comment
shogo82148 Oct 7, 2020
a7f7c9d
set the rcfile option
shogo82148 Oct 7, 2020
450fb49
fix
shogo82148 Oct 7, 2020
f70adc0
fix mecabrc path
shogo82148 Oct 7, 2020
c60db6b
mingw64 prefix is needed
shogo82148 Oct 7, 2020
0c3df48
use mingw-w64-x86_64-go
shogo82148 Oct 8, 2020
d980d0d
fix
shogo82148 Oct 8, 2020
06e9c41
use windows path
shogo82148 Oct 8, 2020
faf8bfb
fix CGO_LDFLAGS
shogo82148 Oct 8, 2020
67e602e
use cygpath
shogo82148 Oct 8, 2020
75d031e
fix include path
shogo82148 Oct 8, 2020
fbbcfd1
cat /mingw64/lib/mecab/dic/ipadic/dicrc
shogo82148 Oct 8, 2020
d852bdb
set dicdir
shogo82148 Oct 8, 2020
34e7113
rewrite mecabrc
shogo82148 Oct 8, 2020
33506bf
mecabrc
shogo82148 Oct 8, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/install-mecab-darwin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ set -uxe
TMPDIR=$(mktemp -d)
trap 'rm -rfv "$TMPDIR"' EXIT

MECAB_VERSION=0.996.2
MECAB_VERSION=0.996.4
IPADIC_VERSION=2.7.0-20070801
# install mecab
cd "$TMPDIR"
curl -o mecab.tar.gz -sSL "https://github.com/shogo82148/mecab/releases/download/v$MECAB_VERSION/mecab-$MECAB_VERSION.tar.gz"
tar zxfv mecab.tar.gz
cd "mecab-$MECAB_VERSION"
./configure --enable-utf8-only
make
make -j2
make check
sudo make install

Expand Down
4 changes: 2 additions & 2 deletions .github/install-mecab-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ set -uxe
TMPDIR=$(mktemp -d)
trap 'rm -rfv "$TMPDIR"' EXIT

MECAB_VERSION=0.996.2
MECAB_VERSION=0.996.4
IPADIC_VERSION=2.7.0-20070801
# install mecab
cd "$TMPDIR"
curl -o mecab.tar.gz -sSL "https://github.com/shogo82148/mecab/releases/download/v$MECAB_VERSION/mecab-$MECAB_VERSION.tar.gz"
tar zxfv mecab.tar.gz
cd "mecab-$MECAB_VERSION"
./configure --enable-utf8-only
make
make -j2
make check
sudo make install
sudo ldconfig
Expand Down
42 changes: 42 additions & 0 deletions .github/install-mecab-mingw.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash
# from https://gist.github.com/dtan4/351d031bec0c3d45cd8f
# see also http://qiita.com/dtan4/items/c6a087666296fbd5fffb

set -uxe

TMPDIR=$(mktemp -d)
trap 'rm -rfv "$TMPDIR"' EXIT

MECAB_VERSION=0.996.4
IPADIC_VERSION=2.7.0-20070801
# install mecab
cd "$TMPDIR"
curl -o mecab.tar.gz -sSL "https://github.com/shogo82148/mecab/releases/download/v$MECAB_VERSION/mecab-$MECAB_VERSION.tar.gz"
tar zxfv mecab.tar.gz
cd "mecab-$MECAB_VERSION"
./configure --enable-utf8-only --host=x86_64-w64-mingw32
make -j2
# make check # it fails :(
make install

cd "$TMPDIR"
curl -o mecab-ipadic.tar.gz -sSL "https://github.com/shogo82148/mecab/releases/download/v$MECAB_VERSION/mecab-ipadic-$IPADIC_VERSION.tar.gz"
tar zxfv mecab-ipadic.tar.gz
cd "mecab-ipadic-$IPADIC_VERSION"
./configure --with-charset=utf8
make
make install

{
echo "CGO_LDFLAGS=-L$(cygpath -w /mingw64/lib) -lmecab -lstdc++"
echo "CGO_CFLAGS=-I$(cygpath -w /mingw64/include)"
} >> "$GITHUB_ENV"

cat << DIC > /mingw64/etc/mecabrc
dicdir = $(cygpath -w /mingw64/lib/mecab/dic/ipadic)
DIC

# The default mecabrc path is "C:\Program Files\mecab\etc\mecabrc" if mecab is built with mingw32-w64.
# but it is not correct in MSYS2 environment.
echo "MECABRC_PATH=$(cygpath -w /mingw64/etc/mecabrc)" >> "$GITHUB_ENV"
cygpath -w /mingw64/bin >> "$GITHUB_PATH"
30 changes: 30 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,33 @@ jobs:
run: |
go version
go test -v -race ./...

mingw:
strategy:
matrix:
go:
- "1"
- "1.15"
- "1.14"
- "1.13"
- "1.12"
fail-fast: false
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: setup Go ${{ matrix.go }}
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}
- uses: msys2/setup-msys2@v2
with:
install: autoconf bison make automake1.16 automake-wrapper mingw-w64-x86_64-gcc mingw-w64-x86_64-libtool mingw-w64-x86_64-libiconv

- name: install mecab
run: |
.github/install-mecab-mingw.sh
shell: msys2 {0}
- name: test
run: |
go version
go test -v ./...
22 changes: 19 additions & 3 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@ package mecab_test

import (
"fmt"
"os"

"github.com/shogo82148/go-mecab"
)

func ExampleMeCab_Parse() {
tagger, err := mecab.New(map[string]string{})
options := map[string]string{}
if path := os.Getenv("MECABRC_PATH"); path != "" {
options["rcfile"] = path
}

tagger, err := mecab.New(options)
if err != nil {
panic(err)
}
Expand All @@ -25,7 +31,12 @@ func ExampleMeCab_Parse() {
}

func ExampleMeCab_ParseLattice() {
tagger, err := mecab.New(map[string]string{})
options := map[string]string{}
if path := os.Getenv("MECABRC_PATH"); path != "" {
options["rcfile"] = path
}

tagger, err := mecab.New(options)
if err != nil {
panic(err)
}
Expand All @@ -49,7 +60,12 @@ func ExampleMeCab_ParseLattice() {
}

func ExampleMeCab_ParseToNode() {
tagger, err := mecab.New(map[string]string{})
options := map[string]string{}
if path := os.Getenv("MECABRC_PATH"); path != "" {
options["rcfile"] = path
}

tagger, err := mecab.New(options)
if err != nil {
panic(err)
}
Expand Down
9 changes: 7 additions & 2 deletions mecab.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"errors"
"fmt"
"reflect"
"unsafe"
"runtime"
"unsafe"
)

// MeCab is a morphological parser.
Expand Down Expand Up @@ -39,10 +39,15 @@ func New(args map[string]string) (MeCab, error) {
opts = append(opts, opt)
}

// C.mecab_new sets an error in the thread local storage.
// so C.mecab_new and C.mecab_strerror must be call in same thread.
runtime.LockOSThread()
defer runtime.UnlockOSThread()

// create new MeCab
mecab := C.mecab_new(C.int(len(opts)), (**C.char)(&opts[0]))
if mecab == nil {
return MeCab{}, errors.New("mecab: mecab is not created")
return MeCab{}, errors.New(C.GoString(C.mecab_strerror(nil)))
}

return MeCab{
Expand Down
48 changes: 40 additions & 8 deletions mecab_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
package mecab

import "testing"
import (
"os"
"testing"
)

var mecabrcPath string

func init() {
// get mecabrc path from mecab-config from the environment value.
if path := os.Getenv("MECABRC_PATH"); path != "" {
mecabrcPath = path
}
}

func rcfile(config map[string]string) map[string]string {
if mecabrcPath != "" {
config["rcfile"] = mecabrcPath
}
return config
}

func TestNewMeCab(t *testing.T) {
mecab, err := New(map[string]string{"output-format-type": "wakati", "all-morphs": ""})
mecab, err := New(rcfile(map[string]string{
"output-format-type": "wakati",
"all-morphs": "",
}))
if err != nil {
t.Errorf("unexpected error: %v", err)
return
Expand All @@ -12,7 +34,9 @@ func TestNewMeCab(t *testing.T) {
}

func TestParse(t *testing.T) {
mecab, err := New(map[string]string{"output-format-type": "wakati"})
mecab, err := New(rcfile(map[string]string{
"output-format-type": "wakati",
}))
if err != nil {
t.Errorf("unexpected error: %v", err)
return
Expand All @@ -31,7 +55,9 @@ func TestParse(t *testing.T) {
}

func BenchmarkParse(b *testing.B) {
mecab, _ := New(map[string]string{"output-format-type": "wakati"})
mecab, _ := New(rcfile(map[string]string{
"output-format-type": "wakati",
}))
defer mecab.Destroy()

for i := 0; i < b.N; i++ {
Expand All @@ -40,7 +66,9 @@ func BenchmarkParse(b *testing.B) {
}

func TestParseLattice(t *testing.T) {
mecab, err := New(map[string]string{"output-format-type": "wakati"})
mecab, err := New(rcfile(map[string]string{
"output-format-type": "wakati",
}))
if err != nil {
t.Errorf("unexpected error: %v", err)
return
Expand Down Expand Up @@ -69,7 +97,9 @@ func TestParseLattice(t *testing.T) {
}

func BenchmarkParseLattice(b *testing.B) {
mecab, _ := New(map[string]string{"output-format-type": "wakati"})
mecab, _ := New(rcfile(map[string]string{
"output-format-type": "wakati",
}))
defer mecab.Destroy()

lattice, _ := NewLattice()
Expand All @@ -83,7 +113,8 @@ func BenchmarkParseLattice(b *testing.B) {
}

func TestParseToNode(t *testing.T) {
mecab, err := New(map[string]string{})
mecab, err := New(rcfile(map[string]string{
}))
if err != nil {
t.Errorf("unexpected error: %v", err)
return
Expand All @@ -109,7 +140,8 @@ func TestParseToNode(t *testing.T) {
}

func BenchmarkParseToNode(b *testing.B) {
mecab, _ := New(map[string]string{})
mecab, _ := New(rcfile(map[string]string{
}))
defer mecab.Destroy()

// XXX: avoid GC, MeCab 0.996 has GC problem (see https://github.com/taku910/mecab/pull/24)
Expand Down
8 changes: 7 additions & 1 deletion model.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "C"
import (
"errors"
"fmt"
"runtime"
"unsafe"
)

Expand Down Expand Up @@ -36,10 +37,15 @@ func NewModel(args map[string]string) (Model, error) {
opts = append(opts, opt)
}

// C.mecab_model_new sets an error in the thread local storage.
// so C.mecab_model_new and C.mecab_strerror must be call in same thread.
runtime.LockOSThread()
defer runtime.UnlockOSThread()

// create new MeCab model
model := C.mecab_model_new(C.int(len(opts)), (**C.char)(&opts[0]))
if model == nil {
return Model{}, errors.New("mecab: mecab_model is not created")
return Model{}, errors.New(C.GoString(C.mecab_strerror(nil)))
}

return Model{
Expand Down
4 changes: 3 additions & 1 deletion model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package mecab
import "testing"

func TestModel(t *testing.T) {
model, err := NewModel(map[string]string{"output-format-type": "wakati"})
model, err := NewModel(rcfile(map[string]string{
"output-format-type": "wakati",
}))
if err != nil {
t.Errorf("unexpected error: %v", err)
return
Expand Down