VOICEVOX / onnxruntime-rs

Rust wrapper for Microsoft's ONNX Runtime
Apache License 2.0
6 stars 13 forks source link

Windowsでテストを実行するとエラーになる #3

Closed qwerty2501 closed 2 years ago

qwerty2501 commented 2 years ago

現象

Aug 06 14:42:04.073 DEBUG new{name="concurrent_environment_creation" log_level=Warning}: onnxruntime::environment: Environment not yet initialized, creating a new one. thread 'environment::tests::concurrent_environment_creations' panicked at 'assertion failed: (left != right) left: 0x0, right: 0x0: Can not get ort api ptr.', onnxruntime\src\lib.rs:184:5

Windows上でテストを実行するとこのようなエラーが表示されてテストに失敗してしまう エラーメッセージが表示されてるのは このあたり だけど原因となっている場所はもっと奥にありそう dllとうまくリンクできていないことが原因かと思ったが、テストプログラムは起動できているあたり実はリンクできている? しかし target/${config}/deps 配下にonnxruntime.dllを配置するとテストに成功できるのでやはり原因はリンク関係か?

memo: CI test上だと Windows-2019環境だと成功するので新しいWindowsでだけ発生する現象っぽい?

原因の調査

refs https://github.com/VOICEVOX/voicevox_core/issues/213

sevenc-nanashi commented 2 years ago

軽く検証。

voicevox_core on  main via  v3.9.9 via  v1.62.1 
 07:37:06 ❯ cargo test 
...コンパイル関係...
    Finished test [unoptimized + debuginfo] target(s) in 5m 26s
     Running unittests src\lib.rs (target\debug\deps\core-1df1610ef55c3313.exe)
error: test failed, to rerun pass '--lib'

Caused by:
  process didn't exit successfully: `E:\voicevox-project\voicevox_core\target\debug\deps\core-1df1610ef55c3313.exe` (exit code: 0xc000007b)

target/debug/deps on  main took 1m34s
 07:49:14 ❯ .\core-1df1610ef55c3313.exe

target/debug/deps on  main took 3s 
 07:50:31 ❯ $LASTEXITCODE
-1073741701

target/debug/deps on  main 
 07:50:47 ❯ foreach($f in (gci *.dll)) { mv $f ($f -replace ".dll",  "_bak.dll") }  # 全てのdllをxxx_bak.dllにリネーム

target/debug/deps on  main 
 07:51:06 ❯ cp (gci ../build -r onnxruntime.dll)[0] .   # buildディレクトリからonnxruntime.dllを探してコピー

target/debug/deps on  main 
 07:51:09 ❯ .\core-1df1610ef55c3313.exe
...テストが実行される(!)...
test engine::open_jtalk::tests::extract_fullcontext_works::case_2 ... ok

test result: ok. 72 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 15.39s

target/debug/deps on  main took 17s 
 07:51:28 ❯ $LASTEXITCODE
0
qwerty2501 commented 2 years ago

@sevenc-nanashi ありがとうございます。 ちなみにその他のdllをrenameではなく削除した場合って結果どうなりますか?

sevenc-nanashi commented 2 years ago
(cargo testで修復済み)

target/debug/deps on  main via △ v3.21.1 took 2s
 08:39:42 ❯ foreach($f in (gci *.dll)) { rm $f }

target/debug/deps on  main via △ v3.21.1 
 08:39:44 ❯ cp (gci ../build -r onnxruntime.dll)[0] .

target/debug/deps on  main via △ v3.21.1 
 08:39:46 ❯ .\core-1df1610ef55c3313.exe

running 72 tests
...テスト...
test status::tests::status_load_model_works ... ok

test result: ok. 72 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 2.99s

こんな感じになりました

qwerty2501 commented 2 years ago

ありがとうございます。 とりあえずdepsにあるその他のdllがテスト成功する要因ではないことがわかりました

y-chan commented 2 years ago

x86_64-pc-windows-gnuでのビルドですが、VOICEVOXのビルドを通してはOpenJTalkのビルドに失敗してできませんでした(単体でも同じようにすればいい...?)。 ~~原因としては、私の環境にはMinGW64のgcc 7.3.0が導入されているのですが、MinGW64のgccではifstreamconst w_char *を入れられないからのようです。 調べたところ、Mecab周りにdefined(_WIN32) && !defined(__CYGWIN__)で分岐を行っているところがあって、そこに__MINGW64__の分岐を噛ませてあげることで対応できそうですが、そこそこ修正範囲があるようなのと、まだRustに疎いので手が出せていません...~~ ここはonnxruntimeのリポジトリなのでここに書くべきではありませんでしたね...

qwerty2501 commented 2 years ago

@y-chan ちなみにこのリポジトリをcloneして cargo test --target x86_64-pc-windows-gnuした場合結果ってどうなりますか?

y-chan commented 2 years ago

試してみてみましたが、やはりだめそうでした。 lib_dirが有効かどうかも調べてみましたが、問題なさそう(ディレクトリは存在するし、dllも存在する)でした 一応、ビルド時のログを置いておきます

   Compiling onnxruntime-sys v0.0.23 (C:\Users\y-cha\Documents\onnxruntime-rs\onnxruntime-sys)
     Running `set CARGO='\\?\C:\Users\y-cha\.rustup\toolchains\stable-x86_64-pc-windows-msvc\bin\cargo.exe'&& set CARGO_CRATE_NAME=build_script_build&& set CARGO_MANIFEST_DIR='C:\Users\y-cha\Documents\onnxruntime-rs\onnxruntime-sys'&& set CARGO_PKG_AUTHORS='Nicolas Bigaouette <nbigaouette@elementai.com>'&& set CARGO_PKG_DESCRIPTION='Unsafe wrapper around Microsoft'\''s ONNX Runtime'&& set CARGO_PKG_HOMEPAGE='https://github.com/nbigaouette/onnxruntime-rs'&& set CARGO_PKG_LICENSE='MIT OR Apache-2.0'&& set CARGO_PKG_LICENSE_FILE=''&& set CARGO_PKG_NAME=onnxruntime-sys&& set CARGO_PKG_REPOSITORY='https://github.com/nbigaouette/onnxruntime-rs'&& set CARGO_PKG_VERSION=0.0.23&& set CARGO_PKG_VERSION_MAJOR=0&& set CARGO_PKG_VERSION_MINOR=0&& set CARGO_PKG_VERSION_PATCH=23&& set CARGO_PKG_VERSION_PRE=''&& set CARGO_PRIMARY_PACKAGE=1&& set PATH='C:\Users\y-cha\Documents\onnxruntime-rs\target\debug\deps;C:\Users\y-cha\.rustup\toolchains\stable-x86_64-pc-windows-msvc\bin;C:\Users\y-cha\.rustup\toolchains\stable-x86_64-pc-windows-msvc\bin;C:\Users\y-cha\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\local\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\y-cha\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\bin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\libnvvp;C:\Python39\Scripts;C:\Python39;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files\dotnet;C:\Program Files\Docker\Docker\resources\bin;C:\ProgramData\DockerDesktop\version-bin;C:\Program Files\CMake\bin;C:\Program Files\nodejs;C:\ProgramData\chocolatey\bin;C:\Program Files\Go\bin;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\Nsight Compute 2020.2.0;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files\Git\cmd;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Users\y-cha\.cargo\bin;C:\Users\y-cha\AppData\Local\Programs\Python\Python310\Scripts;C:\Users\y-cha\AppData\Local\Programs\Python\Python310;C:\Users\y-cha\AppData\Local\activestate\cache\bin;C:\Users\y-cha\AppData\Local\ActiveState\StateTool\release;C:\Program Files\MySQL\MySQL Shell 8.0\bin;C:\Users\y-cha\AppData\Local\Microsoft\WindowsApps;C:\Users\y-cha\.dotnet\tools;C:\Program Files\heroku\bin;C:\Users\y-cha\AppData\Roaming\npm;C:\Users\y-cha\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\y-cha\go\bin;C:\libtorch\lib;C:\julius-4.6\bin;C:\Program Files (x86)\GitHub CLI;C:\Users\y-cha\AppData\Roaming\Python\Python39\Scripts;C:\lua-5.4.3;C:\Program Files\mingw-w64\mingw64\bin;C:\texlive\2022\bin\win32;C:\Users\y-cha\AppData\Local\JetBrains\Toolbox\scripts;C:\Users\y-cha\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Git\usr\bin\vendor_perl;C:\Program Files\Git\usr\bin\core_perl'&& rustc --crate-name build_script_build --edition=2018 'onnxruntime-sys\build.rs' --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 --cfg 'feature="default"' -C metadata=36e8d836f5b99bf8 -C extra-filename=-36e8d836f5b99bf8 --out-dir 'C:\Users\y-cha\Documents\onnxruntime-rs\target\debug\build\onnxruntime-sys-36e8d836f5b99bf8' -C 'incremental=C:\Users\y-cha\Documents\onnxruntime-rs\target\debug\incremental' -L 'dependency=C:\Users\y-cha\Documents\onnxruntime-rs\target\debug\deps' --extern 'flate2=C:\Users\y-cha\Documents\onnxruntime-rs\target\debug\deps\libflate2-ff945041d781193c.rlib' --extern 'once_cell=C:\Users\y-cha\Documents\onnxruntime-rs\target\debug\deps\libonce_cell-a2479fb968d04ed9.rlib' --extern 'tar=C:\Users\y-cha\Documents\onnxruntime-rs\target\debug\deps\libtar-53f1626234e86c0a.rlib' --extern 'ureq=C:\Users\y-cha\Documents\onnxruntime-rs\target\debug\deps\libureq-30a3be54ac2c14d6.rlib' --extern 'zip=C:\Users\y-cha\Documents\onnxruntime-rs\target\debug\deps\libzip-8209dbd5d5894b50.rlib' -L 'native=C:\Users\y-cha\.cargo\registry\src\github.com-1ecc6299db9ec823\windows_x86_64_msvc-0.36.1\lib' -L 'native=C:\Users\y-cha\Documents\onnxruntime-rs\target\debug\build\ring-ee80b3553d47d0f3\out' -L 'native=C:\Users\y-cha\Documents\onnxruntime-rs\target\debug\build\bzip2-sys-411a50e2c9d2009e\out\lib' -L 'native=C:\Users\y-cha\Documents\onnxruntime-rs\target\debug\build\zstd-sys-68ba687701f0afc5\out'`
     Running `C:\Users\y-cha\Documents\onnxruntime-rs\target\debug\build\onnxruntime-sys-36e8d836f5b99bf8\build-script-build`
[onnxruntime-sys 0.0.23] strategy: "unknown"
[onnxruntime-sys 0.0.23] cargo:rerun-if-changed=C:\Users\y-cha\Documents\onnxruntime-rs\target\x86_64-pc-windows-gnu\debug\build\onnxruntime-sys-c66000ec9de0db62\out\onnxruntime-win-x64-1.11.1.zip
[onnxruntime-sys 0.0.23] Creating directory "C:\\Users\\y-cha\\Documents\\onnxruntime-rs\\target\\x86_64-pc-windows-gnu\\debug\\build\\onnxruntime-sys-c66000ec9de0db62\\out"
[onnxruntime-sys 0.0.23] Downloading https://github.com/microsoft/onnxruntime/releases/download/v1.11.1/onnxruntime-win-x64-1.11.1.zip into C:\Users\y-cha\Documents\onnxruntime-rs\target\x86_64-pc-windows-gnu\debug\build\onnxruntime-sys-c66000ec9de0db62\out\onnxruntime-win-x64-1.11.1.zip
[onnxruntime-sys 0.0.23] Extracting to C:\Users\y-cha\Documents\onnxruntime-rs\target\x86_64-pc-windows-gnu\debug\build\onnxruntime-sys-c66000ec9de0db62\out\onnxruntime_1.11.1...
[onnxruntime-sys 0.0.23] File 1 extracted to "C:\Users\y-cha\Documents\onnxruntime-rs\target\x86_64-pc-windows-gnu\debug\build\onnxruntime-sys-c66000ec9de0db62\out\onnxruntime_1.11.1\onnxruntime-win-x64-1.11.1\CodeSignSummary-64c4b561-f65e-4945-bafe-c797d2d40772.md" (511 bytes)
[onnxruntime-sys 0.0.23] File 2 extracted to "C:\Users\y-cha\Documents\onnxruntime-rs\target\x86_64-pc-windows-gnu\debug\build\onnxruntime-sys-c66000ec9de0db62\out\onnxruntime_1.11.1\onnxruntime-win-x64-1.11.1\GIT_COMMIT_ID" (43 bytes)
[onnxruntime-sys 0.0.23] File 4 extracted to "C:\Users\y-cha\Documents\onnxruntime-rs\target\x86_64-pc-windows-gnu\debug\build\onnxruntime-sys-c66000ec9de0db62\out\onnxruntime_1.11.1\onnxruntime-win-x64-1.11.1\include\cpu_provider_factory.h" (416 bytes)
[onnxruntime-sys 0.0.23] File 5 extracted to "C:\Users\y-cha\Documents\onnxruntime-rs\target\x86_64-pc-windows-gnu\debug\build\onnxruntime-sys-c66000ec9de0db62\out\onnxruntime_1.11.1\onnxruntime-win-x64-1.11.1\include\onnxruntime_cxx_api.h" (53889 bytes)
[onnxruntime-sys 0.0.23] File 6 extracted to "C:\Users\y-cha\Documents\onnxruntime-rs\target\x86_64-pc-windows-gnu\debug\build\onnxruntime-sys-c66000ec9de0db62\out\onnxruntime_1.11.1\onnxruntime-win-x64-1.11.1\include\onnxruntime_cxx_inline.h" (44518 bytes)
[onnxruntime-sys 0.0.23] File 7 extracted to "C:\Users\y-cha\Documents\onnxruntime-rs\target\x86_64-pc-windows-gnu\debug\build\onnxruntime-sys-c66000ec9de0db62\out\onnxruntime_1.11.1\onnxruntime-win-x64-1.11.1\include\onnxruntime_c_api.h" (144558 bytes)
[onnxruntime-sys 0.0.23] File 8 extracted to "C:\Users\y-cha\Documents\onnxruntime-rs\target\x86_64-pc-windows-gnu\debug\build\onnxruntime-sys-c66000ec9de0db62\out\onnxruntime_1.11.1\onnxruntime-win-x64-1.11.1\include\onnxruntime_run_options_config_keys.h" (1298 bytes)
[onnxruntime-sys 0.0.23] File 9 extracted to "C:\Users\y-cha\Documents\onnxruntime-rs\target\x86_64-pc-windows-gnu\debug\build\onnxruntime-sys-c66000ec9de0db62\out\onnxruntime_1.11.1\onnxruntime-win-x64-1.11.1\include\onnxruntime_session_options_config_keys.h" (7707 bytes)
[onnxruntime-sys 0.0.23] File 10 extracted to "C:\Users\y-cha\Documents\onnxruntime-rs\target\x86_64-pc-windows-gnu\debug\build\onnxruntime-sys-c66000ec9de0db62\out\onnxruntime_1.11.1\onnxruntime-win-x64-1.11.1\include\provider_options.h" (498 bytes)
[onnxruntime-sys 0.0.23] File 11 extracted to "C:\Users\y-cha\Documents\onnxruntime-rs\target\x86_64-pc-windows-gnu\debug\build\onnxruntime-sys-c66000ec9de0db62\out\onnxruntime_1.11.1\onnxruntime-win-x64-1.11.1\include\tensorrt_provider_factory.h" (327 bytes)
[onnxruntime-sys 0.0.23] File 13 extracted to "C:\Users\y-cha\Documents\onnxruntime-rs\target\x86_64-pc-windows-gnu\debug\build\onnxruntime-sys-c66000ec9de0db62\out\onnxruntime_1.11.1\onnxruntime-win-x64-1.11.1\lib\onnxruntime.dll" (7900064 bytes)
[onnxruntime-sys 0.0.23] File 14 extracted to "C:\Users\y-cha\Documents\onnxruntime-rs\target\x86_64-pc-windows-gnu\debug\build\onnxruntime-sys-c66000ec9de0db62\out\onnxruntime_1.11.1\onnxruntime-win-x64-1.11.1\lib\onnxruntime.lib" (2124 bytes)
[onnxruntime-sys 0.0.23] File 15 extracted to "C:\Users\y-cha\Documents\onnxruntime-rs\target\x86_64-pc-windows-gnu\debug\build\onnxruntime-sys-c66000ec9de0db62\out\onnxruntime_1.11.1\onnxruntime-win-x64-1.11.1\lib\onnxruntime.pdb" (198750208 bytes)
[onnxruntime-sys 0.0.23] File 16 extracted to "C:\Users\y-cha\Documents\onnxruntime-rs\target\x86_64-pc-windows-gnu\debug\build\onnxruntime-sys-c66000ec9de0db62\out\onnxruntime_1.11.1\onnxruntime-win-x64-1.11.1\lib\onnxruntime_providers_shared.dll" (20896 bytes)
[onnxruntime-sys 0.0.23] File 17 extracted to "C:\Users\y-cha\Documents\onnxruntime-rs\target\x86_64-pc-windows-gnu\debug\build\onnxruntime-sys-c66000ec9de0db62\out\onnxruntime_1.11.1\onnxruntime-win-x64-1.11.1\lib\onnxruntime_providers_shared.lib" (2314 bytes)
[onnxruntime-sys 0.0.23] File 18 extracted to "C:\Users\y-cha\Documents\onnxruntime-rs\target\x86_64-pc-windows-gnu\debug\build\onnxruntime-sys-c66000ec9de0db62\out\onnxruntime_1.11.1\onnxruntime-win-x64-1.11.1\lib\onnxruntime_providers_shared.pdb" (323584 bytes)
[onnxruntime-sys 0.0.23] File 19 extracted to "C:\Users\y-cha\Documents\onnxruntime-rs\target\x86_64-pc-windows-gnu\debug\build\onnxruntime-sys-c66000ec9de0db62\out\onnxruntime_1.11.1\onnxruntime-win-x64-1.11.1\LICENSE" (1094 bytes)
[onnxruntime-sys 0.0.23] File 20 extracted to "C:\Users\y-cha\Documents\onnxruntime-rs\target\x86_64-pc-windows-gnu\debug\build\onnxruntime-sys-c66000ec9de0db62\out\onnxruntime_1.11.1\onnxruntime-win-x64-1.11.1\Privacy.md" (2490 bytes)
[onnxruntime-sys 0.0.23] File 21 extracted to "C:\Users\y-cha\Documents\onnxruntime-rs\target\x86_64-pc-windows-gnu\debug\build\onnxruntime-sys-c66000ec9de0db62\out\onnxruntime_1.11.1\onnxruntime-win-x64-1.11.1\README.md" (6742 bytes)
[onnxruntime-sys 0.0.23] File 22 extracted to "C:\Users\y-cha\Documents\onnxruntime-rs\target\x86_64-pc-windows-gnu\debug\build\onnxruntime-sys-c66000ec9de0db62\out\onnxruntime_1.11.1\onnxruntime-win-x64-1.11.1\ThirdPartyNotices.txt" (247049 bytes)
[onnxruntime-sys 0.0.23] File 23 extracted to "C:\Users\y-cha\Documents\onnxruntime-rs\target\x86_64-pc-windows-gnu\debug\build\onnxruntime-sys-c66000ec9de0db62\out\onnxruntime_1.11.1\onnxruntime-win-x64-1.11.1\VERSION_NUMBER" (8 bytes)
[onnxruntime-sys 0.0.23] Include directory: "C:\\Users\\y-cha\\Documents\\onnxruntime-rs\\target\\x86_64-pc-windows-gnu\\debug\\build\\onnxruntime-sys-c66000ec9de0db62\\out\\onnxruntime_1.11.1\\onnxruntime-win-x64-1.11.1\\include"
[onnxruntime-sys 0.0.23] Lib directory: "C:\\Users\\y-cha\\Documents\\onnxruntime-rs\\target\\x86_64-pc-windows-gnu\\debug\\build\\onnxruntime-sys-c66000ec9de0db62\\out\\onnxruntime_1.11.1\\onnxruntime-win-x64-1.11.1\\lib"
[onnxruntime-sys 0.0.23] cargo:rustc-link-lib=onnxruntime
[onnxruntime-sys 0.0.23] cargo:rustc-link-search=native=C:\Users\y-cha\Documents\onnxruntime-rs\target\x86_64-pc-windows-gnu\debug\build\onnxruntime-sys-c66000ec9de0db62\out\onnxruntime_1.11.1\onnxruntime-win-x64-1.11.1\lib
[onnxruntime-sys 0.0.23] cargo:rerun-if-env-changed=ORT_STRATEGY
[onnxruntime-sys 0.0.23] cargo:rerun-if-env-changed=ORT_USE_CUDA
[onnxruntime-sys 0.0.23] cargo:rerun-if-env-changed=ORT_LIB_LOCATION
[onnxruntime-sys 0.0.23] Bindings not generated automatically, using committed files instead.
[onnxruntime-sys 0.0.23] Enable with the 'generate-bindings' cargo feature.
     Running `set CARGO='\\?\C:\Users\y-cha\.rustup\toolchains\stable-x86_64-pc-windows-msvc\bin\cargo.exe'&& set CARGO_CRATE_NAME=onnxruntime_sys&& set CARGO_MANIFEST_DIR='C:\Users\y-cha\Documents\onnxruntime-rs\onnxruntime-sys'&& set CARGO_PKG_AUTHORS='Nicolas Bigaouette <nbigaouette@elementai.com>'&& set CARGO_PKG_DESCRIPTION='Unsafe wrapper around Microsoft'\''s ONNX Runtime'&& set CARGO_PKG_HOMEPAGE='https://github.com/nbigaouette/onnxruntime-rs'&& set CARGO_PKG_LICENSE='MIT OR Apache-2.0'&& set CARGO_PKG_LICENSE_FILE=''&& set CARGO_PKG_NAME=onnxruntime-sys&& set CARGO_PKG_REPOSITORY='https://github.com/nbigaouette/onnxruntime-rs'&& set CARGO_PKG_VERSION=0.0.23&& set CARGO_PKG_VERSION_MAJOR=0&& set CARGO_PKG_VERSION_MINOR=0&& set CARGO_PKG_VERSION_PATCH=23&& set CARGO_PKG_VERSION_PRE=''&& set CARGO_PRIMARY_PACKAGE=1&& set OUT_DIR='C:\Users\y-cha\Documents\onnxruntime-rs\target\x86_64-pc-windows-gnu\debug\build\onnxruntime-sys-c66000ec9de0db62\out'&& set PATH='C:\Users\y-cha\Documents\onnxruntime-rs\target\debug\deps;C:\Users\y-cha\.rustup\toolchains\stable-x86_64-pc-windows-msvc\bin;C:\Users\y-cha\.rustup\toolchains\stable-x86_64-pc-windows-msvc\bin;C:\Users\y-cha\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\local\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\y-cha\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\bin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\libnvvp;C:\Python39\Scripts;C:\Python39;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files\dotnet;C:\Program Files\Docker\Docker\resources\bin;C:\ProgramData\DockerDesktop\version-bin;C:\Program Files\CMake\bin;C:\Program Files\nodejs;C:\ProgramData\chocolatey\bin;C:\Program Files\Go\bin;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\Nsight Compute 2020.2.0;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files\Git\cmd;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Users\y-cha\.cargo\bin;C:\Users\y-cha\AppData\Local\Programs\Python\Python310\Scripts;C:\Users\y-cha\AppData\Local\Programs\Python\Python310;C:\Users\y-cha\AppData\Local\activestate\cache\bin;C:\Users\y-cha\AppData\Local\ActiveState\StateTool\release;C:\Program Files\MySQL\MySQL Shell 8.0\bin;C:\Users\y-cha\AppData\Local\Microsoft\WindowsApps;C:\Users\y-cha\.dotnet\tools;C:\Program Files\heroku\bin;C:\Users\y-cha\AppData\Roaming\npm;C:\Users\y-cha\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\y-cha\go\bin;C:\libtorch\lib;C:\julius-4.6\bin;C:\Program Files (x86)\GitHub CLI;C:\Users\y-cha\AppData\Roaming\Python\Python39\Scripts;C:\lua-5.4.3;C:\Program Files\mingw-w64\mingw64\bin;C:\texlive\2022\bin\win32;C:\Users\y-cha\AppData\Local\JetBrains\Toolbox\scripts;C:\Users\y-cha\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Git\usr\bin\vendor_perl;C:\Program Files\Git\usr\bin\core_perl'&& rustc --crate-name onnxruntime_sys --edition=2018 'onnxruntime-sys\src\lib.rs' --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 --cfg 'feature="default"' -C metadata=271fc080bb3d9b84 -C extra-filename=-271fc080bb3d9b84 --out-dir 'C:\Users\y-cha\Documents\onnxruntime-rs\target\x86_64-pc-windows-gnu\debug\deps' --target x86_64-pc-windows-gnu -C 'incremental=C:\Users\y-cha\Documents\onnxruntime-rs\target\x86_64-pc-windows-gnu\debug\incremental' -L 'dependency=C:\Users\y-cha\Documents\onnxruntime-rs\target\x86_64-pc-windows-gnu\debug\deps' -L 'dependency=C:\Users\y-cha\Documents\onnxruntime-rs\target\debug\deps' -L 'native=C:\Users\y-cha\Documents\onnxruntime-rs\target\x86_64-pc-windows-gnu\debug\build\onnxruntime-sys-c66000ec9de0db62\out\onnxruntime_1.11.1\onnxruntime-win-x64-1.11.1\lib' -l onnxruntime`
   Compiling onnxruntime v0.0.28 (C:\Users\y-cha\Documents\onnxruntime-rs\onnxruntime)
     Running `set CARGO='\\?\C:\Users\y-cha\.rustup\toolchains\stable-x86_64-pc-windows-msvc\bin\cargo.exe'&& set CARGO_CRATE_NAME=onnxruntime&& set CARGO_MANIFEST_DIR='C:\Users\y-cha\Documents\onnxruntime-rs\onnxruntime'&& set CARGO_PKG_AUTHORS='Nicolas Bigaouette <nbigaouette@gmail.com>'&& set CARGO_PKG_DESCRIPTION='Wrapper around Microsoft'\''s ONNX Runtime'&& set CARGO_PKG_HOMEPAGE='https://github.com/nbigaouette/onnxruntime-rs'&& set CARGO_PKG_LICENSE='MIT OR Apache-2.0'&& set CARGO_PKG_LICENSE_FILE=''&& set CARGO_PKG_NAME=onnxruntime&& set CARGO_PKG_REPOSITORY='https://github.com/nbigaouette/onnxruntime-rs'&& set CARGO_PKG_VERSION=0.0.28&& set CARGO_PKG_VERSION_MAJOR=0&& set CARGO_PKG_VERSION_MINOR=0&& set CARGO_PKG_VERSION_PATCH=28&& set CARGO_PKG_VERSION_PRE=''&& set CARGO_PRIMARY_PACKAGE=1&& set PATH='C:\Users\y-cha\Documents\onnxruntime-rs\target\debug\deps;C:\Users\y-cha\.rustup\toolchains\stable-x86_64-pc-windows-msvc\bin;C:\Users\y-cha\.rustup\toolchains\stable-x86_64-pc-windows-msvc\bin;C:\Users\y-cha\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\local\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\y-cha\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\bin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\libnvvp;C:\Python39\Scripts;C:\Python39;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files\dotnet;C:\Program Files\Docker\Docker\resources\bin;C:\ProgramData\DockerDesktop\version-bin;C:\Program Files\CMake\bin;C:\Program Files\nodejs;C:\ProgramData\chocolatey\bin;C:\Program Files\Go\bin;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\Nsight Compute 2020.2.0;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files\Git\cmd;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Users\y-cha\.cargo\bin;C:\Users\y-cha\AppData\Local\Programs\Python\Python310\Scripts;C:\Users\y-cha\AppData\Local\Programs\Python\Python310;C:\Users\y-cha\AppData\Local\activestate\cache\bin;C:\Users\y-cha\AppData\Local\ActiveState\StateTool\release;C:\Program Files\MySQL\MySQL Shell 8.0\bin;C:\Users\y-cha\AppData\Local\Microsoft\WindowsApps;C:\Users\y-cha\.dotnet\tools;C:\Program Files\heroku\bin;C:\Users\y-cha\AppData\Roaming\npm;C:\Users\y-cha\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\y-cha\go\bin;C:\libtorch\lib;C:\julius-4.6\bin;C:\Program Files (x86)\GitHub CLI;C:\Users\y-cha\AppData\Roaming\Python\Python39\Scripts;C:\lua-5.4.3;C:\Program Files\mingw-w64\mingw64\bin;C:\texlive\2022\bin\win32;C:\Users\y-cha\AppData\Local\JetBrains\Toolbox\scripts;C:\Users\y-cha\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Git\usr\bin\vendor_perl;C:\Program Files\Git\usr\bin\core_perl'&& rustc --crate-name onnxruntime --edition=2018 'onnxruntime\src\lib.rs' --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=95ac62185ad9c876 -C extra-filename=-95ac62185ad9c876 --out-dir 'C:\Users\y-cha\Documents\onnxruntime-rs\target\x86_64-pc-windows-gnu\debug\deps' --target x86_64-pc-windows-gnu -C 'incremental=C:\Users\y-cha\Documents\onnxruntime-rs\target\x86_64-pc-windows-gnu\debug\incremental' -L 'dependency=C:\Users\y-cha\Documents\onnxruntime-rs\target\x86_64-pc-windows-gnu\debug\deps' -L 'dependency=C:\Users\y-cha\Documents\onnxruntime-rs\target\debug\deps' --extern 'lazy_static=C:\Users\y-cha\Documents\onnxruntime-rs\target\x86_64-pc-windows-gnu\debug\deps\liblazy_static-7e7b8af303ef5096.rmeta' --extern 'ndarray=C:\Users\y-cha\Documents\onnxruntime-rs\target\x86_64-pc-windows-gnu\debug\deps\libndarray-4e41f7109966ac8f.rmeta' --extern 'onnxruntime_sys=C:\Users\y-cha\Documents\onnxruntime-rs\target\x86_64-pc-windows-gnu\debug\deps\libonnxruntime_sys-271fc080bb3d9b84.rmeta' --extern 'thiserror=C:\Users\y-cha\Documents\onnxruntime-rs\target\x86_64-pc-windows-gnu\debug\deps\libthiserror-ac314ffd441a7828.rmeta' --extern 'tracing=C:\Users\y-cha\Documents\onnxruntime-rs\target\x86_64-pc-windows-gnu\debug\deps\libtracing-260ccb8104421225.rmeta' -L 'native=C:\Users\y-cha\Documents\onnxruntime-rs\target\x86_64-pc-windows-gnu\debug\build\onnxruntime-sys-c66000ec9de0db62\out\onnxruntime_1.11.1\onnxruntime-win-x64-1.11.1\lib'`
    Finished dev [unoptimized + debuginfo] target(s) in 24.16s
qwerty2501 commented 2 years ago

@y-chan ありがとうございます。 なるほど。dll検索するパスも存在してそうでしたか・・・。ログだと x86_64-pc-windows-msvc を使用されているようですが、 x86_64-pc-windows-gnu でも駄目だったということで良かったでしょうか?

またログを展開していただいたことにより少々興味深いことがわかりました link-searchは各環境のdllの読み込みに必要な環境変数にdirectoryを設定します。Windowsの場合はPATH環境変数。 しかしログでPATHの設定を行っていると思われるところでは lib_dirに相当するdirectoryが設定されていないように見えました。 なのでやはりlinkのためのpath設定がうまく行っていないように見て取れました。

set PATH='C:\Users\y-cha\Documents\onnxruntime-rs\target\debug\deps;C:\Users\y-cha\.rustup\toolchains\stable-x86_64-pc-windows-msvc\bin;C:\Users\y-cha\.rustup\toolchains\stable-x86_64-pc-windows-msvc\bin;C:\Users\y-cha\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\local\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\y-cha\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\bin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\libnvvp;C:\Python39\Scripts;C:\Python39;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files\dotnet;C:\Program Files\Docker\Docker\resources\bin;C:\ProgramData\DockerDesktop\version-bin;C:\Program Files\CMake\bin;C:\Program Files\nodejs;C:\ProgramData\chocolatey\bin;C:\Program Files\Go\bin;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\Nsight Compute 2020.2.0;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files\Git\cmd;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Users\y-cha\.cargo\bin;C:\Users\y-cha\AppData\Local\Programs\Python\Python310\Scripts;C:\Users\y-cha\AppData\Local\Programs\Python\Python310;C:\Users\y-cha\AppData\Local\activestate\cache\bin;C:\Users\y-cha\AppData\Local\ActiveState\StateTool\release;C:\Program Files\MySQL\MySQL Shell 8.0\bin;C:\Users\y-cha\AppData\Local\Microsoft\WindowsApps;C:\Users\y-cha\.dotnet\tools;C:\Program Files\heroku\bin;C:\Users\y-cha\AppData\Roaming\npm;C:\Users\y-cha\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\y-cha\go\bin;C:\libtorch\lib;C:\julius-4.6\bin;C:\Program Files (x86)\GitHub CLI;C:\Users\y-cha\AppData\Roaming\Python\Python39\Scripts;C:\lua-5.4.3;C:\Program Files\mingw-w64\mingw64\bin;C:\texlive\2022\bin\win32;C:\Users\y-cha\AppData\Local\JetBrains\Toolbox\scripts;C:\Users\y-cha\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Git\usr\bin\vendor_perl;C:\Program Files\Git\usr\bin\core_perl'
y-chan commented 2 years ago

私もログにmsvcの文字があって、あれ?となったのでいろいろ調べてみたところ、targetは変えていたのですが、toolchainを変え忘れていました。 ただ、toolchainを変えても同じような結果になりました。

shigobu commented 2 years ago

link-searchは、コンパイルに必要なライブラリのある場所を指定するための仕組みではないでしょうか? であるならば、PATH環境変数に追加されないか、あるいはビルド終了時にPATH環境変数をビルド開始前の状態に戻しているかもです。

DLLは実行時にリンクされます。 DLLの検索順序はWindowsの仕組みで決まっています。検索順序にPATH環境変数は含まれていますが、普通使いません。1番最後ですし、アプリケーションをインストールするたびにPATH環境変数に追加していたら、肥大化してしまいます。 https://docs.microsoft.com/ja-jp/windows/win32/dlls/dynamic-link-library-search-order#search-order-for-desktop-applications

1番簡単なのは、やはり実行ファイル(exe)の有るフォルダにDLLを置くことです。 どうにかして、ビルド完了後にDLLをコピーできれば良いんですけど・・・

sevenc-nanashi commented 2 years ago

自分の環境でもやってみました:

...大量の警告...
warning: `onnxruntime-sys` (lib test) generated 292 warnings
warning: `onnxruntime` (lib test) generated 13 warnings
    Finished test [unoptimized + debuginfo] target(s) in 1m 24s
     Running unittests src\lib.rs (target\x86_64-pc-windows-gnu\debug\deps\onnxruntime-eb3dbcdcdd067517.exe)
error: test failed, to rerun pass '-p onnxruntime --lib'

Caused by:
  process didn't exit successfully: `E:\voicevox-project\onnxruntime-rs\target\x86_64-pc-windows-gnu\debug\deps\onnxruntime-eb3dbcdcdd067517.exe` (exit code: 0xc000007b)
y-chan commented 2 years ago

path周り気になって、手元のMacでも試してみたのですが、生成されたバイナリたちに動的ライブラリは直接的にリンクされている訳ではなさそうで、テストが成功するMacやLinuxではcargo testが勝手に解決しているっぽい...?

スクリーンショット 2022-08-07 13 04 28

で、問題のWindowsはということで、こちらの記事を元に調べたところ、C:/Windows/System32/onnxruntime.dllというところに依存していました。

image image

解決できなかったから怒られているのではなく、誤った解決をしているために怒られている気がします。

qwerty2501 commented 2 years ago

@shigobu link-searchはstatic linkだけでなく、dynamic libraryを探すpathの環境変数としても使用されることが説明で記載されてます https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-searchkindpath

These paths are also added to the dynamic library search path environment variable if they are within the OUT_DIR.

また https://doc.rust-lang.org/cargo/reference/environment-variables.html#dynamic-library-paths によれば Windows環境ではPATH環境変数に設定されるようです。

実際、このテストに実行をして失敗するのはあたらしいバージョンのWIndowsのようで、CI test でいうとWindows-2019環境だとテストに成功しますのでPATH環境変数に lib_dirのpathが設定されてると思います。

issueに CI test のWindows-2019環境だとテストが成功する、新しいWindowsが原因になっていそうなことを記載しました

y-chan commented 2 years ago

なるほどー 両者の意見を合わせて考えると、PATHとして設定はされるが、新しいWindowsではシステム ディレクトリにonnxruntime.dllが存在するために、Windowsの動的ライブラリ解決の順番の関係上そちらが解決されてしまい、最終的に実行に失敗する、といった感じでしょうか? 動的ライブラリ解決においてシステムディレクトリよりも優先順位が高いのがバイナリと同一ディレクトリであるから、現状のworkaroundと同じくそこにonnxruntimeをコピーするしか解決手段はなさそう...?

qwerty2501 commented 2 years ago

@y-chan :thinking: これ、C:/Windows/System32/ にもとから onnxruntime.dll が存在しているということでしょうか? もしかして新しいWindowsにはデフォで onnxruntime.dll がインストールされていたりします?

y-chan commented 2 years ago

@qwerty2501 どうやらWindows 11にはデフォルトで存在するみたいです(と言っても、私の環境は2台ともInsider Previewなので確実性が微妙ですが...w)

普通のWindows 11やWindows 10など、他の方の環境でも確認してもらいたいです...!

sevenc-nanashi commented 2 years ago

image 自分の環境(Windows 10 Pro、21H2 19044.1766)にもありました。Insiderではないです。

qwerty2501 commented 2 years ago

@y-chan なるほど!原因の解像度が上がってきました! ちょっと試してみてほしいのですが、ダウンロードしたほうのonnxruntimeの方をrenameできないでしょうか? たとえば、 onnxruntime.dll -> onnxruntime-for-rs.dll onnxruntime.lib -> onnxruntime-for-rs.dll とし、 cargo:rustc-link-lib の指定を onnxruntime から onnxruntime-for-rs に変えてみて再度 cargo testしてみてもらえますか?

sevenc-nanashi commented 2 years ago

image バージョン見てみたら(左がonnxruntime-sysの方、右がsystem32の方)system32の方が低かった(1.0.1911.2111)ので、そこらへんで問題が起きている説...?

qwerty2501 commented 2 years ago

それでdllは読み込めてるような振る舞いだったけどエラーになっていたのか。。。

y-chan commented 2 years ago

うーん、いろいろ試してましたが、ダメそうでした。 コンパイルは出来るし、onnxruntime-sysには-l onnxruntime_for_rsオプションが渡ってビルドできてるんですが、いざtestを実行すると失敗するし、生成されるexeの依存関係を確認するとonnxruntime_sys-*.exeにはonnxruntime関連の依存関係がなくて、onnxruntime-*.exeではonnxruntime.dllに依存していました。 コイツの依存先をいじれれば変わるかもしれませんが、変え方が分からず...

qwerty2501 commented 2 years ago

:thinking: うーん名前変えれば行けるかと思ったんですが onnxruntime.dll に依存してしまうのは不思議ですね。

とりあえず C:/Windows/System32/onnxruntime.dll があることが良くないということがわかったのは収穫ですね。 私の方でもちょっとこれを糸口に調べてみます

qwerty2501 commented 2 years ago

これは憶測になってしまうんですが、おそらく onnxruntime.libの内部に参照するべき dllのfilenameが入っていて、なのでrenameしただけではonnxruntime.dllを強制的に参照するようになってしまうのではないかと思いました。 そうだとするとcargoで提供されているlink命令だけだと対応できなさそうで非推奨ではありますが、ダウンロードしたonnxruntime.dllを target/${config}/deps にコピーしやすくするアプローチにしたほうが無難そうに感じました

PickledChair commented 2 years ago

おそらく onnxruntime.libの内部に参照するべき dllのfilenameが入っていて、なのでrenameしただけではonnxruntime.dllを強制的に参照するようになってしまうのではないかと思いました。

Windows の dll には詳しくないのですが、この予想はおそらく正しいと感じています。

ダウンロード時に onnxruntime.dllonnxruntime-for-rs.dll, onnxruntime.libonnxruntime-for-rs.lib とリネームするようにして、これらをリンクするように build.rs を書き換えてビルドしてみたのですが、やはり同様に onnxruntime.dll に依存するようになっていました。

dumpbin コマンドで lib ファイルを調査すると、シンボルの情報に、そのシンボルが存在する dll の名前も含まれていて、それが onnxruntime.dll になっていました。この情報が使われているのかどうかはわかりませんが、lib ファイルに元の dll 名が含まれているということはわかりました。

PS C:\path\to\target\debug\build\onnxruntime-sys-6f985c74f2bc63e1\out\onnxruntime_1.11.1\onnxruntime-win-x64-1.11.1\lib> dumpbin /HEADERS onnxruntime-for-rs.lib

... 省略 ...

  Machine      : 8664 (x64)
  TimeDateStamp: CF85821C
  SizeOfData   : 0000001E
  DLL name     : onnxruntime.dll
  Symbol name  : OrtGetApiBase
  Type         : code
  Name type    : ordinal
  Ordinal      : 1

  Version      : 0
  Machine      : 8664 (x64)
  TimeDateStamp: FA25A401
  SizeOfData   : 0000003D
  DLL name     : onnxruntime.dll
  Symbol name  : OrtSessionOptionsAppendExecutionProvider_CPU
  Type         : code
  Name type    : ordinal
  Ordinal      : 2

... 省略 ...
qwerty2501 commented 2 years ago

そうなるとやはりdepsにコピーしてあげる必要がありそうですね。 このリポジトリでは ONNXRUNTIME_LIB_OUT_DIR といったような環境変数を受け取るようにし、その環境変数がセットされていたらそのディレクトリに対してコピーを行うという実装にしてみようかと そしてvoicevox_core側で target/debug/deps ディレクトリを ONNXRUNTIME_LIB_OUT_DIR に設定するようにしてあげればWindowsでもコピー操作を行わなくて済みそうです