tvandinther / libsql-client-dotnet

A .NET client for libsql
https://www.nuget.org/packages/Libsql.Client
MIT License
60 stars 3 forks source link

Build intructions? #28

Open NatElkins opened 1 month ago

NatElkins commented 1 month ago

Hi,

I'm also interested in using libsql from .NET. I don't know too much about native interop in .NET, but I'd love to learn more and contribute! I see you're using csbindgen to generate the C# native bindings. Do I need cargo installed to build this repo? What steps can I use to build this locally and start tinkering?

Thank you!

tvandinther commented 1 month ago

Hello, and welcome! Yes, Cargo is required to build this repo. I have a shell.nix file in this repo for the rust requirements. If you have nix installed, running nix-shell will let you generate the bindings. The dependencies required are .NET (any version which supports .NET Standard 2.0, latest version should be fine) and the rust toolchain for building the required dynamic libs. You can then run the generate-bindings.sh script which will build a dll and a C# file and put them in the right places. At that point you should be able to run dotnet test successfully.

I think some development instructions would be a good addition to this repo so that these questions are more easily addressed for the future. We can close this issue with the addition of a development instructions document.

NatElkins commented 1 month ago

~I just installed Nix, and I've run nix-shell in the root of the repo. Here's the error I get:~

➜  libsql-client-dotnet git:(master) nix shell
path '/Users/nat/Projects/libsql-client-dotnet' does not contain a 'flake.nix', searching up
error: path '/Users/nat/Projects/libsql-client-dotnet' is not part of a flake (neither it nor its parent directories contain a 'flake.nix' file)
➜  libsql-client-dotnet git:(master)

~Any suggestions?~

Realized I ran nix shell instead of nix-shell.

NatElkins commented 1 month ago

When I try to build, I get an error like this:

error: linking with `cc` failed: exit status: 1

And then more errors later on:

  = note: ld: library not found for -liconv
          clang-16: error: linker command failed with exit code 1 (use -v to see invocation)

error: could not compile `libsql-sqlite3-parser` (build script) due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `libsql-ffi` (build script) due to 1 previous error

Any suggestions?

NatElkins commented 1 month ago

I'm on an M3 Mac.

tvandinther commented 1 month ago

Perhaps this stackoverflow post is useful to you. https://stackoverflow.com/questions/71788323/how-should-i-resolve-a-ld-library-not-found-for-liconv-error-when-running-c

It'd be nice to have a nix flake with everything in it, but I'd expect the libsql devs to maintain one for their repository and combine it with one for this project, otherwise this project will have to maintain a dependency list for libsql. But I digress, hopefully that post solves your issue.

NatElkins commented 1 month ago

Thanks, following that Stack Overflow answer helped! I did encounter another error though:

ld: framework not found Security

Which I resolved by updating my shell.nix like so:

{ pkgs ? import <nixpkgs> {} }:

pkgs.mkShell {
  buildInputs = with pkgs; [
    rustup
    cmake
    darwin.apple_sdk.frameworks.Security # Added this
  ];

  shellHook = ''
    rustup default stable
  '';
}