How do I create a package?

Anonymouse zorael at gmail.com
Sat Mar 5 16:15:31 UTC 2022


On Saturday, 5 March 2022 at 15:30:19 UTC, M wrote:
> On Saturday, 5 March 2022 at 15:12:35 UTC, M wrote:
>
>> THE DOCS ARE INADEQUATE TO THE TASK.
>
> I've created a directory bcm2835. Then within source/bcm2835 I 
> have bcm2835.d.
>
> I run dub build, and file called libbcm2835.a gets built.
>
> I type
>         dub list
>
> and  it reports
>
>     Packages present in the system and known to dub:
>     ...
>     bcm2835 ~master: /home/pi/repos/cerbo/dsp/dlang/bcm2835/
>
> So, some kind of success, presumably.
>
> So then, in the app I want to build, I type
>
>       dub add bcm2835
>
> but it says
>
>      Could not find package 'bcm2835'.
>
>
> So, dunno, any ideas?

So I tried and I agree it's not intuitive.

Once you've created a package `bcm2835` with `dub init`, you can 
add it to the local registry with `dub add-local 
/path/to/bcm2835`.

```
Registered package: bcm2835 (version: ~master)
```

This you already did, presumably, or something to the same effect.

```
Packages present in the system and known to dub:
[...]
   bcm2835 ~master: /home/wob/src/test/bcm2835/
```

Then you can add it to your `dub.sdl`/`dub.json` as a dependency 
with `dub add` *if and only if* you also specify a version. Else 
it will look it up in the online registry, find nothing, and 
fail. The help text in `dub add --help` briefly mentions it.

```
$ dub add bcm2835@"*"
Adding dependency bcm2835 >=0.0.0

$ dub build
Performing "debug" build using /usr/bin/dmd for x86_64.
bcm2835 ~master: target for configuration "library" is up to date.
test ~master: building configuration "application"...
Linking...
To force a rebuild of up-to-date targets, run again with --force.
```


More information about the Digitalmars-d-learn mailing list