-
Notifications
You must be signed in to change notification settings - Fork 13
[dargon2] Unable to load dynamic libraries with compiled native Dart project #17
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
Comments
@jagandeepbrar Hi, currently there isn't another way to do this. I'm thinking of adding an env variable lookup to get the path from there first then rely on the dart package, but I haven't decided on that route for sure |
Hi, The error message is "libgcc_s.so.1 must be installed for pthread_cancel to work" Do you have any ideas?
|
@hasimyerlikaya I have not yet tried running this within a Docker container, but presumably you need to install the
|
@jagandeepbrar Thank you. I did it, but it didn't work. Here is my Docker file. It has been built successfully. But I got the same error. I guess I can't use the Dargon2 package, and I need to find another solution.
|
@jagandeepbrar @hasimyerlikaya I have the same exception, it only works when I launch the executable using the absolute path. Could be related to dart-lang/sdk#32901. I think it was working with relative paths for me before, but I'm not too sure. 🤔 Edit 1: of course this is begging for a solution, but until then I am using the following workaround: have your script call itself via an absolute path with necessary arguments supplied for an argon2 call. Edit 2: knowing that the dargon2 is searching for the libraries within itself this won't work, see #17 (comment) and #17 (comment) instead. |
@GleammerRay Unfortunately, I will be looking for a different package. I don't have enough experience to solve this issue. |
@hasimyerlikaya @GleammerRay I was able to get this working without issue utilizing Docker, here is a minimum working version of my Dockerfile: # <-- Libraries -->
FROM --platform=$TARGETPLATFORM ubuntu:latest as libraries
WORKDIR /app
RUN apt update && apt install curl git gcc make -y
RUN git clone https://github.com/P-H-C/phc-winner-argon2.git
RUN cd phc-winner-argon2 && git checkout 20190702 -b 20190702
RUN cd phc-winner-argon2 && make
# <-- Build -->
FROM --platform=$TARGETPLATFORM dart:stable as build
WORKDIR /app
COPY pubspec.yaml pubspec.lock ./
RUN dart pub get
COPY ./bin ./bin
COPY ./lib ./lib
RUN dart compile exe bin/executable.dart -o output_exe
# <-- Runtime -->
FROM --platform=$TARGETPLATFORM ubuntu:latest as runtime
WORKDIR /app
COPY --from=libraries /app/phc-winner-argon2/libargon2.so.1 /usr/local/lib/libargon2.so.1
COPY --from=build /app/output_exe /app/output_exe
RUN ldconfig
EXPOSE 9303
ENTRYPOINT [ "/app/output_exe" ] Naturally the above uses stub names for the main Dart file and output executable as well as an arbitrary exposed port, but should give you a solid foundation. Now this splits the Docker build into 3 stages - libraries, build, and runtime.
The reason for building the binary in the For this scenario I build the argon2 shared library and copy it to the
Now in the code, I installed the import 'dart:ffi';
import 'dart:io';
import 'package:dargon2_core/dargon2_core.dart';
final dargon2 = DArgon2Native(_DArgon2Loader());
class _DArgon2Loader implements LibLoader {
@override
String getPath() {
return '/usr/local/lib/libargon2.so.1';
}
@override
DynamicLibrary loadLib() {
final path = getPath();
if (File(path).existsSync()) {
return DynamicLibrary.open(path);
}
throw UnsupportedError('Argon2 dynamic library is not available.');
}
}
...
/// Continue to utilize argon2 functions, such as `hashPasswordString` or `verifyHashString`, using the dargon2 instantiated variable. The above is just a quick example and does not account for other platforms or local-dev loading, but this can be accounted for in whichever way you would like. A simple solution would be to set an environment variable in the Dockerfile to tell your program to load the binary from the standard-location (for example, Hopefully this was useful in getting DArgon2 working for you guys! |
@jagandeepbrar thank you so much! I didn't know it wasn't compiling because it was failing to find the library. I am not making any changes to my building environment, but I have forked the repository itself and am using my own fork. Since my Dart executable is shipped together with my Flutter app I was able to simply do the following: GlitterWare@011ba63. Paths for MacOS/Windows may need adjustment, haven't tested them yet. |
@jagandeepbrar Thank you very much. I have updated my docker and dart_lib_loader.dart files. Now It works perfectly.
|
Uh oh!
There was an error while loading. Please reload this page.
It appears that compiling to a native Dart binary will cause the library to fail to load.
When using
dart run
there is no issue with utilizing the library and all functionality can complete as expected, but when first usingdart compile exe <file>
and running the generated binary directly, the library is unable to be loaded.This is occurring because the dynamic library loader is currently using the package path to find the required blobs/dynamic libraries, which is not always found on the host machine (we should be able to expect compiled Dart code to execute without the Dart SDK or packages).
I have a workaround by using
dargon2_core
directly and creating my own DynamicLibrary loader by shipping the compiled binary with the required blobs, but wanted to validate that there isn't another way to allow compiled Dart binaries to load the library directly from thedargon2
package.Details:
The text was updated successfully, but these errors were encountered: