Skip to content

Commit 35ecb09

Browse files
authored
Clang/Clang++ command (#136)
* Don't use install-manifest anymore * Remove install-manifest from docs
1 parent 02fcf57 commit 35ecb09

File tree

6 files changed

+237
-92
lines changed

6 files changed

+237
-92
lines changed

.github/workflows/ci.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,22 @@ jobs:
6161
6262
curl -fLo cs https://github.com/coursier/launchers/raw/master/coursier &&
6363
chmod +x cs
64+
65+
./cs bootstrap com.indoorvivants.vcpkg:sn-vcpkg_3:$(cat version) -f -o local_cli
6466
65-
./cs launch com.indoorvivants.vcpkg:sn-vcpkg_3:$(cat version) -- bootstrap
67+
./local_cli bootstrap
6668
67-
./cs launch com.indoorvivants.vcpkg:sn-vcpkg_3:$(cat version) -- install -v libpq s2n
69+
./local_cli install -v libpq s2n
6870
6971
echo '{"name": "my-application","version": "0.15.2","dependencies": ["sqlite3"]}' > test-vcpkg.json
70-
./cs launch com.indoorvivants.vcpkg:sn-vcpkg_3:$(cat version) -- install-manifest -v test-vcpkg.json
72+
./local_cli install --manifest test-vcpkg.json
73+
74+
./local_cli clang sqlite3 -- .github/workflows/fixtures/test-sqlite.c
75+
./local_cli clang --manifest test-vcpkg.json -- .github/workflows/fixtures/test-sqlite.c
76+
77+
./local_cli clang++ sqlite3 -- .github/workflows/fixtures/test-sqlite.c
78+
./local_cli clang++ --manifest test-vcpkg.json -- .github/workflows/fixtures/test-sqlite.c
7179
72-
./cs launch com.indoorvivants.vcpkg:sn-vcpkg_3:$(cat version) -- install -q -c -l libpq s2n
7380
7481
7582
windows_build:
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <stdio.h>
2+
#include <sqlite3.h>
3+
4+
int main(int argc, char* argv[]) {
5+
sqlite3 *db;
6+
char *zErrMsg = 0;
7+
int rc;
8+
9+
rc = sqlite3_open("test.db", &db);
10+
11+
if( rc ) {
12+
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
13+
return(0);
14+
} else {
15+
fprintf(stderr, "Opened database successfully\n");
16+
}
17+
sqlite3_close(db);
18+
}

README.md

Lines changed: 65 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
- [CLI](#cli)
1515
- [`bootstrap`](#bootstrap)
1616
- [`install`](#install)
17-
- [`install-manifest`](#install-manifest)
17+
- [`clang` and `clang++`](#clang-and-clang)
1818
- [Core](#core)
1919
- [VcpkgRootInit](#vcpkgrootinit)
2020
- [VcpkgNativeConfig](#vcpkgnativeconfig)
@@ -75,7 +75,7 @@ There are several modules of interest:
7575
You can quickly test it by running:
7676

7777
```
78-
$ cs launch com.indoorvivants.vcpkg:sn-vcpkg_3:0.0.11 -- install libpq -l -q -c
78+
$ cs launch com.indoorvivants.vcpkg:sn-vcpkg_3:0.0.13 -- install libpq -l -q -c
7979
-I<...>/sbt-vcpkg/vcpkg-install/arm64-osx/lib/pkgconfig/../../include
8080
-L<...>/sbt-vcpkg/vcpkg-install/arm64-osx/lib/pkgconfig/../../lib
8181
-L<...>/sbt-vcpkg/vcpkg-install/arm64-osx/lib/pkgconfig/../../lib/pkgconfig/../../lib
@@ -101,7 +101,7 @@ There are several modules of interest:
101101
For SBT, add this to your `project/plugins.sbt`:
102102

103103
```scala
104-
addSbtPlugin("com.indoorvivants.vcpkg" % "sbt-vcpkg" % "0.0.11")
104+
addSbtPlugin("com.indoorvivants.vcpkg" % "sbt-vcpkg" % "0.0.13")
105105
```
106106

107107
And in your build.sbt:
@@ -137,7 +137,7 @@ Tasks and settings (find them all by doing `help vcpkg*` in SBT shell):
137137
Add dependency to your `build.sc`:
138138

139139
```scala
140-
import $ivy.`com.indoorvivants.vcpkg::mill-vcpkg:0.0.11`
140+
import $ivy.`com.indoorvivants.vcpkg::mill-vcpkg:0.0.13`
141141
```
142142

143143
And use the `VcpkgModule` mixin:
@@ -164,7 +164,7 @@ The Mill tasks are the same as in the SBT plugin
164164
In `project/plugins.sbt`:
165165

166166
```scala
167-
addSbtPlugin("com.indoorvivants.vcpkg" % "sbt-vcpkg-native" % "0.0.11")
167+
addSbtPlugin("com.indoorvivants.vcpkg" % "sbt-vcpkg-native" % "0.0.13")
168168
```
169169

170170
In `build.sbt`:
@@ -194,7 +194,7 @@ For real world usage, see [Examples](#examples).
194194
Add dependency to your `build.sc`:
195195

196196
```scala
197-
import $ivy.`com.indoorvivants.vcpkg::mill-vcpkg-native:0.0.11`
197+
import $ivy.`com.indoorvivants.vcpkg::mill-vcpkg-native:0.0.13`
198198
```
199199

200200
And use the `VcpkgNativeModule` mixin:
@@ -268,18 +268,24 @@ Options and flags:
268268

269269
#### `install`
270270

271-
Install one or several dependencies, and optionally output linking/compilation flags for all of them.
271+
Install one or several dependencies, by name or from a manifest file, and optionally output linking/compilation flags for all of them.
272272

273-
Example: `sn-vcpkg install libgit2 cjson -l -c`
273+
Examples:
274+
- `sn-vcpkg install libgit2 cjson -l -c`
275+
- `sn-vcpkg install --manifest vcpkg.json -l -c`
274276

275277
```
276-
Usage: sn-vcpkg install [--output-compilation] [--output-linking] [--vcpkg-root-manual <location> [--no-bootstrap] | --vcpkg-root-env <env-var> [--no-bootstrap] | --no-bootstrap] [--vcpkg-install <dir>] [--no-bootstrap] [--verbose] [--quiet] <dep>...
278+
Usage:
279+
sn-vcpkg install --manifest <string> [--output-compilation] [--output-linking] [--vcpkg-root-manual <location> [--no-bootstrap] | --vcpkg-root-env <env-var> [--no-bootstrap] | --no-bootstrap] [--vcpkg-install <dir>] [--no-bootstrap] [--verbose] [--quiet]
280+
sn-vcpkg install [--output-compilation] [--output-linking] [--vcpkg-root-manual <location> [--no-bootstrap] | --vcpkg-root-env <env-var> [--no-bootstrap] | --no-bootstrap] [--vcpkg-install <dir>] [--no-bootstrap] [--verbose] [--quiet] <dep>...
277281
278282
Install a list of vcpkg dependencies
279283
280284
Options and flags:
281285
--help
282286
Display this help text.
287+
--manifest <string>
288+
vcpkg manifest file
283289
--output-compilation, -c
284290
Output (to STDOUT) compilation flags for installed libraries, one per line
285291
--output-linking, -l
@@ -298,39 +304,59 @@ Options and flags:
298304
Only error logging
299305
```
300306

301-
#### `install-manifest`
307+
#### `clang` and `clang++`
302308

303-
Install dependencies from a manifest file, and optionally output linking/compilation flags for all of them.
309+
These commands invoke clang or clang++ with all the configuration
310+
flags required [^1] to run the specified dependencies.
304311

305-
Example: `sn-vcpkg install-manifest vcpkg.json -l -c`
312+
For example, say you have a snippet of C code that needs sqlite3 dependency:
306313

314+
```c
315+
#include <stdio.h>
316+
#include <sqlite3.h>
317+
318+
int main(int argc, char* argv[]) {
319+
sqlite3 *db;
320+
char *zErrMsg = 0;
321+
int rc;
322+
323+
rc = sqlite3_open("test.db", &db);
324+
325+
if( rc ) {
326+
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
327+
return(0);
328+
} else {
329+
fprintf(stderr, "Opened database successfully\n");
330+
}
331+
sqlite3_close(db);
332+
}
307333
```
308-
Usage: sn-vcpkg install-manifest [--output-compilation] [--output-linking] [--vcpkg-root-manual <location> [--no-bootstrap] | --vcpkg-root-env <env-var> [--no-bootstrap] | --no-bootstrap] [--vcpkg-install <dir>] [--no-bootstrap] [--verbose] [--quiet] <vcpkg manifest file>
309334
310-
Install vcpkg dependencies from a manifest file (like vcpkg.json)
335+
You can compile it directly by running
311336
312-
Options and flags:
313-
--help
314-
Display this help text.
315-
--output-compilation, -c
316-
Output (to STDOUT) compilation flags for installed libraries, one per line
317-
--output-linking, -l
318-
Output (to STDOUT) linking flags for installed libraries, one per line
319-
--vcpkg-root-manual <location>
320-
Initialise vcpkg in this location
321-
--no-bootstrap
322-
Allow bootstrapping vcpkg from scratch
323-
--vcpkg-root-env <env-var>
324-
Pick up vcpkg root from the environment variable
325-
--vcpkg-install <dir>
326-
folder where packages will be installed
327-
--verbose, -v
328-
Verbose logging
329-
--quiet, -q
330-
Only error logging
337+
```
338+
sn-vcpkg clang sqlite3 -- test-sqlite.c
331339
```
332340
341+
Or if you have a vcpkg manifest file:
333342
343+
```json
344+
{
345+
"name": "my-application",
346+
"version": "0.15.2",
347+
"dependencies": ["sqlite3"]
348+
}
349+
```
350+
351+
You can use that as well:
352+
353+
```
354+
sn-vcpkg clang --manifest vcpkg.json -- test-sqlite.c
355+
```
356+
357+
All the arguments after `--` will be passed to clang/clang++ without modification (_before_ the flags calculated for dependencies)
358+
359+
[^1]: as long as the dependencies themselves provide a well configured pkg-config file, of course
334360

335361
### Core
336362

@@ -359,7 +385,7 @@ compilation arguments from installed vcpkg dependencies.
359385
**Defaults**
360386
```scala
361387
VcpkgNativeConfig()
362-
// res3: VcpkgNativeConfig = Vcpkg NativeConfig:
388+
// res2: VcpkgNativeConfig = Vcpkg NativeConfig:
363389
// | approximate = true
364390
// | autoConfigure = true
365391
// | prependCompileOptions = true
@@ -404,7 +430,7 @@ VcpkgNativeConfig().withPrependLinkingOptions(true)
404430
```scala
405431
// Completely overwrite
406432
VcpkgNativeConfig().withRenamedLibraries(Map("cjson" -> "libcjson", "cmark" -> "libcmark"))
407-
// res8: VcpkgNativeConfig = Vcpkg NativeConfig:
433+
// res7: VcpkgNativeConfig = Vcpkg NativeConfig:
408434
// | approximate = true
409435
// | autoConfigure = true
410436
// | prependCompileOptions = true
@@ -414,7 +440,7 @@ VcpkgNativeConfig().withRenamedLibraries(Map("cjson" -> "libcjson", "cmark" -> "
414440

415441
// Append only
416442
VcpkgNativeConfig().addRenamedLibrary("cjson", "libcjson")
417-
// res9: VcpkgNativeConfig = Vcpkg NativeConfig:
443+
// res8: VcpkgNativeConfig = Vcpkg NativeConfig:
418444
// | approximate = true
419445
// | autoConfigure = true
420446
// | prependCompileOptions = true
@@ -431,7 +457,7 @@ Specification for vcpkg dependencies. Can be either:
431457

432458
```scala
433459
VcpkgDependencies("cmark", "cjson")
434-
// res10: VcpkgDependencies = Names(
460+
// res9: VcpkgDependencies = Names(
435461
// deps = List(
436462
// Dependency(name = "cmark", features = Set()),
437463
// Dependency(name = "cjson", features = Set())
@@ -443,14 +469,14 @@ VcpkgDependencies("cmark", "cjson")
443469

444470
```scala
445471
VcpkgDependencies(new java.io.File("./vcpkg.json"))
446-
// res11: VcpkgDependencies = ManifestFile(path = ./vcpkg.json)
472+
// res10: VcpkgDependencies = ManifestFile(path = ./vcpkg.json)
447473
```
448474

449475
- a list of detailed dependency specs:
450476

451477
```scala
452478
VcpkgDependencies.Names(List(Dependency("libpq", Set("arm-build")), Dependency.parse("cpprestsdk[boost]")))
453-
// res12: Names = Names(
479+
// res11: Names = Names(
454480
// deps = List(
455481
// Dependency(name = "libpq", features = Set("arm-build")),
456482
// Dependency(name = "cpprestsdk", features = Set("boost"))

build.sbt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ lazy val docs =
7676
.dependsOn(core.jvm(V.scala3), cli.jvm(V.scala3))
7777
.settings(scalaVersion := V.scala3)
7878
.settings(
79-
mdocVariables := Map("VERSION" -> "0.0.11", "SCALA3_VERSION" -> V.scala3)
79+
mdocVariables := Map("VERSION" -> "0.0.13", "SCALA3_VERSION" -> V.scala3)
8080
)
8181

8282
lazy val docsDrifted = taskKey[Boolean]("")
@@ -153,6 +153,7 @@ lazy val cli = projectMatrix
153153
.settings(
154154
name := "sn-vcpkg",
155155
run / fork := true,
156+
run / baseDirectory := (ThisBuild / baseDirectory).value,
156157
testFrameworks += new TestFramework("weaver.framework.CatsEffect"),
157158
libraryDependencies += "com.monovore" %% "decline" % V.decline,
158159
libraryDependencies += "io.circe" %% "circe-parser" % V.circe,

docs/README.in.md

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
- [CLI](#cli)
1515
- [`bootstrap`](#bootstrap)
1616
- [`install`](#install)
17-
- [`install-manifest`](#install-manifest)
17+
- [`clang` and `clang++`](#clang-and-clang)
1818
- [Core](#core)
1919
- [VcpkgRootInit](#vcpkgrootinit)
2020
- [VcpkgNativeConfig](#vcpkgnativeconfig)
@@ -252,29 +252,71 @@ println(s"```\n$help\n```")
252252

253253
#### `install`
254254

255-
Install one or several dependencies, and optionally output linking/compilation flags for all of them.
255+
Install one or several dependencies, by name or from a manifest file, and optionally output linking/compilation flags for all of them.
256256

257-
Example: `sn-vcpkg install libgit2 cjson -l -c`
257+
Examples:
258+
- `sn-vcpkg install libgit2 cjson -l -c`
259+
- `sn-vcpkg install --manifest vcpkg.json -l -c`
258260

259261
```scala mdoc:passthrough
260262
val helpInstall = com.indoorvivants.vcpkg.cli.Options.opts.parse(Array("install", "--help")).fold(identity, _ => ???)
261263

262264
println(s"```\n$helpInstall\n```")
263265
```
264266

265-
#### `install-manifest`
267+
#### `clang` and `clang++`
266268

267-
Install dependencies from a manifest file, and optionally output linking/compilation flags for all of them.
269+
These commands invoke clang or clang++ with all the configuration
270+
flags required [^1] to run the specified dependencies.
268271

269-
Example: `sn-vcpkg install-manifest vcpkg.json -l -c`
272+
For example, say you have a snippet of C code that needs sqlite3 dependency:
270273

271-
```scala mdoc:passthrough
272-
val helpManifest = com.indoorvivants.vcpkg.cli.Options.opts.parse(Array("install-manifest", "--help")).fold(identity, _ => ???)
274+
```c
275+
#include <stdio.h>
276+
#include <sqlite3.h>
277+
278+
int main(int argc, char* argv[]) {
279+
sqlite3 *db;
280+
char *zErrMsg = 0;
281+
int rc;
282+
283+
rc = sqlite3_open("test.db", &db);
284+
285+
if( rc ) {
286+
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
287+
return(0);
288+
} else {
289+
fprintf(stderr, "Opened database successfully\n");
290+
}
291+
sqlite3_close(db);
292+
}
293+
```
294+
295+
You can compile it directly by running
296+
297+
```
298+
sn-vcpkg clang sqlite3 -- test-sqlite.c
299+
```
300+
301+
Or if you have a vcpkg manifest file:
302+
303+
```json
304+
{
305+
"name": "my-application",
306+
"version": "0.15.2",
307+
"dependencies": ["sqlite3"]
308+
}
309+
```
273310

274-
println(s"```\n$helpManifest\n```")
311+
You can use that as well:
312+
313+
```
314+
sn-vcpkg clang --manifest vcpkg.json -- test-sqlite.c
275315
```
276316

317+
All the arguments after `--` will be passed to clang/clang++ without modification (_before_ the flags calculated for dependencies)
277318

319+
[^1]: as long as the dependencies themselves provide a well configured pkg-config file, of course
278320

279321
### Core
280322

0 commit comments

Comments
 (0)