jacob-carlborg / dstep

A tool for converting C and Objective-C headers to D modules
204 stars 37 forks source link

How to use dstep generate PostgreSQL & MySQL binding? #289

Open zoujiaqing opened 3 months ago

zoujiaqing commented 3 months ago

Thank you.

jacob-carlborg commented 3 months ago
  1. Download the latest release from: https://github.com/jacob-carlborg/dstep/releases/tag/v1.0.0. If you're using macOS you probably need to compile it yourself
  2. Run DStep and pass the header file to it dstep mysql.h. It will output a corresponding D file mysql.d.

You can pass multiple files as well. You might need to add imports to the D files after running DStep. You might also need to pass some compiler flags to DStep. DStep accepts the same flags as Clang does.

See the readme as well:

https://github.com/jacob-carlborg/dstep?tab=readme-ov-file#usage

zoujiaqing commented 3 months ago

Thank you jacob!

Show error:

~/Downloads/dstep mysql.h -o mysql.d
dyld[59002]: missing symbol called
zsh: abort      ~/Downloads/dstep mysql.h -o mysql.d

System info:

uname -a
Darwin mac 23.3.0 Darwin Kernel Version 23.3.0: Wed Dec 20 21:30:44 PST 2023; root:xnu-10002.81.5~7/RELEASE_ARM64_T6000 arm64
jacob-carlborg commented 3 months ago

For macOS you need to compile it yourself. There are build instructions in the readme [1]. I recommend using LLVM/libclang 15.0.7.

[1] https://github.com/jacob-carlborg/dstep?tab=readme-ov-file#building

jacob-carlborg commented 3 months ago

I'll try to put out a new release, with precompiled binaries, but that might take a while.

zoujiaqing commented 3 months ago

Thank you!

mysql.d file has generated!

An warning has occurred:

% ./configure --llvm-path /opt/homebrew/Cellar/llvm@15/15.0.7
% dub build
% mv bin/dstep ~/bin/dstep
% cd ~/projects/test
% ~/bin/dstep mysql.h -o mysql.d
./field_types.h:54:6: warning: a type renamed to 'enum_field_types_' due to the collision with the symbol declared in ./field_types.h:94:31

step version:

% ~/bin/dstep --version
1.0.4-26-g5541229
jacob-carlborg commented 3 months ago

I think that warning should be fine. It's printed due to there's an enum named enum_field_types and a typedef with the same name. That's fine in C, since in C you need to explicitly include the enum keyword when referring to an enum. But in D that's not the case.

jacob-carlborg commented 3 months ago

BTW, there are several existing bindings to MySQL and PostgreSQL.