Skip to content

Commit

Permalink
try to fix windows
Browse files Browse the repository at this point in the history
  • Loading branch information
cocoa-xu committed Feb 13, 2024
1 parent 28d61e5 commit 7f1bb40
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 10 deletions.
21 changes: 19 additions & 2 deletions .github/workflows/windows-x86_64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ jobs:
MAKE: "nmake"

steps:
- uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v4

- uses: erlef/setup-beam@v1
with:
Expand Down Expand Up @@ -119,14 +120,17 @@ jobs:
run: |
rm -f Makefile
rm -f "_build/${MIX_ENV}/lib/evision/priv/evision.dll"
rm -f "_build/${MIX_ENV}/lib/evision/priv/windows_fix.dll"
rm -rf lib/generated && rm -rf src/generated
mkdir -p lib/generated && mkdir -p src/generated
mix compile
- name: Compile once again but without optional deps
run: mix compile --force --warnings-as-errors --no-optional-deps
shell: bash
run: |
mix compile --force --warnings-as-errors --no-optional-deps
- name: Cache testdata
id: cache-mix-testdata
Expand All @@ -140,3 +144,16 @@ jobs:
shell: bash
run: |
mix test --include require_downloading --include require_ffmpeg --exclude may_crash
- name: Create tarball
if: always()
shell: bash
run: |
tar -czf evision-x86_64-windows-msvc.tar.gz -C "_build/${MIX_ENV}/lib/evision" .
- name: Upload build artifacts
if: always()
uses: actions/[email protected]
with:
name: evision-x86_64-windows-msvc.tar.gz
path: evision-x86_64-windows-msvc.tar.gz
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Evision.MixProject.Metadata do
@moduledoc false

def app, do: :evision
def version, do: "0.1.34"
def version, do: "0.1.35-alpha"
def github_url, do: "https://github.com/cocoa-xu/evision"
def opencv_version, do: "4.9.0"
# only means compatible. need to write more tests
Expand Down
8 changes: 2 additions & 6 deletions py_src/evision_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def load_nif do
nif_file = '#{:code.priv_dir(:evision)}/evision'
case :evision_windows_fix.run_once() do
:ok -> :ok
{:error, reason} -> Logger.warning("Failed to load nif: #{inspect(reason)}")
{:error, reason} -> Logger.warning("Failed to run windows fix: #{inspect(reason)}")
end
case :erlang.load_nif(nif_file, 0) do
Expand Down Expand Up @@ -215,11 +215,7 @@ def load_nif do
Dir ->
filename:join(Dir, ?LIBNAME)
end,
case os:type() of
{win32, _} ->
dll_loader_helper:add_dll_directory(filename:join[filename:dirname(SoName), %s]);
_ -> true
end,
evision_windows_fix:run_once(),
erlang:load_nif(SoName, 0).
not_loaded(Line) ->
Expand Down
2 changes: 1 addition & 1 deletion src/evision.app.src
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{application, evision,
[{description, "OpenCV-Erlang/Elixir binding."},
{vsn, "0.1.32"},
{vsn, "0.1.35-alpha"},
{registered, []},
{applications,
[kernel,
Expand Down
28 changes: 28 additions & 0 deletions src/evision_windows_fix.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-module(evision_windows_fix).
-compile(nowarn_export_all).
-compile([export_all]).

-on_load(init/0).

-define(APPNAME, evision).
-define(LIBNAME, windows_fix).

init() ->
SoName = case code:priv_dir(?APPNAME) of
{error, bad_name} ->
case filelib:is_dir(filename:join(["..", priv])) of
true ->
filename:join(["..", priv, ?LIBNAME]);
_ ->
filename:join([priv, ?LIBNAME])
end;
Dir ->
filename:join(Dir, ?LIBNAME)
end,
erlang:load_nif(SoName, 0).

not_loaded(Line) ->
erlang:nif_error({not_loaded, [{module, ?MODULE}, {line, Line}]}).

run_once() ->
not_loaded(?LINE).

0 comments on commit 7f1bb40

Please sign in to comment.