MrcSnm / redub

Alternative implementation of dub, speed and consistency oriented
https://code.dlang.org/packages/redub
MIT License
37 stars 8 forks source link

How to use #8

Closed aberba closed 6 months ago

aberba commented 6 months ago

The README does not show how to go about using this package

ichordev commented 6 months ago

You use it just like dub, or do you mean the library part?

MrcSnm commented 6 months ago

I've added how to build, run and use its public API in the last commit:

Running redub without having it on path

Building redub

Using its library API

The usage of the library APIispretty straightforward. You get mainly 2 functions

  1. resolveDependencies which will parse the project and its dependencies, after that, you got all the project information
  2. buildProject which will get the project information and build in parallel
import redub.api;
import redub.logging;
void main()
{
  import std.file;
  //Enables logging on redub
  setLogLevel(LogLevel.verbose);
  //Gets the project information
  ProjectDetails d = resolveDependencies(
    invalidateCache: false,
    std.system.os,
    CompilationDetails("dmd", "arch not yet implemented", "dmd v[2.105.0]"),
    ProjectToParse("configuration", getcwd(), "subPackage", "path/to/dub/recipe.json (optional)")
  );
  /** Optionally, you can change some project information by accessing the details.tree (a ProjectNode), from there, you can freely modify the BuildRequirements of the project
  * d.tree.requirements.cfg.outputDirectory = "some/path";
  * d.tree.requirements.cfg.dFlags~= "-gc";
  */
  //Execute the build process
  buildProject(d);
}