Skip to content
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

Build intructions? #28

Open
NatElkins opened this issue Sep 20, 2024 · 11 comments
Open

Build intructions? #28

NatElkins opened this issue Sep 20, 2024 · 11 comments
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@NatElkins
Copy link

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
Copy link
Owner

tvandinther commented Sep 23, 2024

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
Copy link
Author

NatElkins commented Sep 25, 2024

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
Copy link
Author

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
Copy link
Author

I'm on an M3 Mac.

@tvandinther
Copy link
Owner

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
Copy link
Author

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
  '';
}

@paulpeeters
Copy link

How should I create the csharp_bindings.dll? I ran generate-bindings.sh in nix-shell within WSL.

@tvandinther
Copy link
Owner

How should I create the csharp_bindings.dll? I ran generate-bindings.sh in nix-shell within WSL.

Hi Paul, is there any specific issue you encountered during the build process?

@paulpeeters
Copy link

Hi Tom, I’m trying to build the Demo project in Visual Studio under Windows, but I can’t find the csharp_bindings.dll file. The Libsql.g.cs file was properly created by running the generate-bindings.sh.

@tvandinther
Copy link
Owner

If the bindings build completed successfully then you should be able to find it in the path rust-bindings/target/release.

Though if your goal is to just try demo and play with the client (rather than altering the library code itself) then the best option is to create a new project and install the client library from nuget. This link is available in the project description but I should probably add it near the top of the README as installation instructions for clarity.

@tvandinther tvandinther added the documentation Improvements or additions to documentation label Dec 23, 2024
@tvandinther tvandinther self-assigned this Dec 23, 2024
@paulpeeters
Copy link

I reran the script but the path rust-bindings/target/release does not contain the DLL mentioned in libsql.g.cs. I noticed that there are 2 .so files but these are linux shared library files.

image

My goal is indeed to try the demo and play with the client but I thought the best first step to take is to try the demo from this repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants