Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,8 @@ The `/pkg` directory contains the Go files converted by c-for-go and the manuall

- `/opt/mxdriver/lib/libmxsml.so`
- `/opt/maca/lib/libmxsml.so`
- `/opt/mxn100/lib/libmxsml.so`
- `/opt/mxn100/lib/libmxsml.so`

If you need to try multiple SDK mount points, `MXSML_LIBRARY_PATH` can now be a
path list rather than a single entry. Directory entries are expanded to
`libmxsml.so`, and duplicate candidates are removed automatically.
24 changes: 12 additions & 12 deletions gen/License
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
LICENSE
Copyright © 2026 MetaX Integrated Circuits (Shanghai) Co., Ltd.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
LICENSE

Copyright © 2026 MetaX Integrated Circuits (Shanghai) Co., Ltd.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

10 changes: 1 addition & 9 deletions pkg/lib/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import (
// #include <stdlib.h>
import "C"

const mxsmlLibName = "libmxsml.so"

var g_mxsmlLib = newMxsmlLib()

type library struct {
Expand Down Expand Up @@ -56,13 +54,7 @@ func Load() error {
}

var installPath string
// check lib path
libPathList := []string{
"/opt/mxdriver/lib/" + mxsmlLibName,
"/opt/maca/lib/" + mxsmlLibName,
"/opt/mxn100/lib/" + mxsmlLibName,
}
for _, path := range libPathList {
for _, path := range candidateLibraryPaths() {
if _, err := os.Stat(path); err == nil {
installPath = path
break
Expand Down
44 changes: 44 additions & 0 deletions pkg/lib/search_paths.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package lib

import (
"os"
"path/filepath"
"strings"
)

const mxsmlLibName = "libmxsml.so"

func candidateLibraryPaths() []string {
paths := []string{}
appendUnique := func(path string) {
if path == "" {
return
}
for _, existing := range paths {
if existing == path {
return
}
}
paths = append(paths, path)
}

if value := strings.TrimSpace(os.Getenv("MXSML_LIBRARY_PATH")); value != "" {
for _, item := range strings.Split(value, string(os.PathListSeparator)) {
item = strings.TrimSpace(item)
if item == "" {
continue
}
info, err := os.Stat(item)
if err == nil && info.IsDir() {
appendUnique(filepath.Join(item, mxsmlLibName))
} else {
appendUnique(item)
}
}
}

appendUnique("/opt/mxdriver/lib/" + mxsmlLibName)
appendUnique("/opt/maca/lib/" + mxsmlLibName)
appendUnique("/opt/mxn100/lib/" + mxsmlLibName)
return paths
}
40 changes: 40 additions & 0 deletions pkg/lib/search_paths_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package lib

import (
"os"
"path/filepath"
"testing"
)

func TestCandidateLibraryPathsExpandsPathList(t *testing.T) {
dir1 := t.TempDir()
dir2 := t.TempDir()
value := dir1 + string(os.PathListSeparator) + filepath.Join(dir2, mxsmlLibName)
t.Setenv("MXSML_LIBRARY_PATH", value)

paths := candidateLibraryPaths()
if len(paths) < 2 {
t.Fatalf("expected at least 2 paths, got %v", paths)
}
if paths[0] != filepath.Join(dir1, mxsmlLibName) {
t.Fatalf("expected first path to resolve directory entry, got %v", paths)
}
if paths[1] != filepath.Join(dir2, mxsmlLibName) {
t.Fatalf("expected second path to preserve file entry, got %v", paths)
}
}

func TestCandidateLibraryPathsDeduplicatesEntries(t *testing.T) {
dir := t.TempDir()
value := dir + string(os.PathListSeparator) + dir
t.Setenv("MXSML_LIBRARY_PATH", value)

paths := candidateLibraryPaths()
seen := map[string]struct{}{}
for _, path := range paths {
if _, ok := seen[path]; ok {
t.Fatalf("found duplicate path %s in %v", path, paths)
}
seen[path] = struct{}{}
}
}