ccgo 3.7.0

A high-performance C++ cross-platform build CLI
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
# Version Management

Complete guide to managing versions in CCGO projects using semantic versioning, git tags, and automated version injection.

## Overview

CCGO provides comprehensive version management features:

- **Semantic Versioning** - Follow SemVer 2.0.0 specifications
- **Automated Tagging** - Create git tags from CCGO.toml version
- **Version Injection** - Automatically inject version info into builds
- **Multi-Platform Support** - Consistent versioning across all platforms
- **Build Metadata** - Include git commit SHA, build timestamp in binaries
- **Release Management** - Simplify release workflows

## Version Format

### Semantic Versioning

CCGO follows [Semantic Versioning 2.0.0](https://semver.org/):

```
MAJOR.MINOR.PATCH[-PRERELEASE][+BUILDMETADATA]
```

**Components:**
- `MAJOR`: Incompatible API changes
- `MINOR`: New backward-compatible functionality
- `PATCH`: Backward-compatible bug fixes
- `PRERELEASE`: Optional pre-release identifier (alpha, beta, rc)
- `BUILDMETADATA`: Optional build metadata (commit SHA, timestamp)

**Examples:**
```
1.0.0           # Stable release
1.2.3           # Patch update
2.0.0-alpha.1   # Pre-release
1.5.0+20240115  # With build metadata
2.1.0-rc.2+g8f3a  # Pre-release with git hash
```

## Configuration

### CCGO.toml

```toml
[package]
name = "mylib"
version = "1.2.3"  # SemVer format
authors = ["Your Name <you@example.com>"]

[version]
# Version injection settings
inject_build_metadata = true  # Include git SHA and timestamp
inject_to_code = true          # Generate version header files
prerelease_suffix = "beta"     # Optional: alpha, beta, rc

# Platform-specific version overrides (optional)
[version.android]
version_code = 10203  # Android integer version (auto-calculated if not set)

[version.ios]
build_number = "123"  # iOS build number (defaults to PATCH)

[version.windows]
file_version = "1.2.3.0"  # Windows 4-part version
```

### Version Auto-Calculation

CCGO automatically calculates platform-specific version numbers:

**Android version_code:**
```
version_code = MAJOR * 10000 + MINOR * 100 + PATCH

Example: 1.2.3 → 10203
```

**iOS build number:**
```
build_number = PATCH (default)
Or custom: build_number = "123"
```

**Windows file version:**
```
file_version = MAJOR.MINOR.PATCH.0

Example: 1.2.3 → 1.2.3.0
```

## Creating Version Tags

### Using ccgo tag

```bash
# Create tag from CCGO.toml version
ccgo tag

# Create tag with custom version
ccgo tag v2.0.0

# Create tag with message
ccgo tag --message "Release version 2.0.0 with new features"

# Create annotated tag
ccgo tag --annotate

# Push tag to remote
ccgo tag --push
```

### Tag Format

```bash
# CCGO creates tags in format: v{VERSION}
v1.0.0
v1.2.3-beta.1
v2.0.0
```

### Manual Tagging

```bash
# Create lightweight tag
git tag v1.0.0

# Create annotated tag
git tag -a v1.0.0 -m "Release 1.0.0"

# Push tag to remote
git push origin v1.0.0

# Push all tags
git push --tags
```

## Version Injection

### Build-Time Injection

CCGO automatically injects version information during builds:

```bash
# Version info injected into all builds
ccgo build android

# Disable version injection
ccgo build android --no-version-inject
```

### Generated Version Header

**C++ Header (`include/<project>/version.h`):**
```cpp
#pragma once

#define MYLIB_VERSION "1.2.3"
#define MYLIB_VERSION_MAJOR 1
#define MYLIB_VERSION_MINOR 2
#define MYLIB_VERSION_PATCH 3

#define MYLIB_GIT_SHA "8f3a2b1c"
#define MYLIB_GIT_BRANCH "main"
#define MYLIB_BUILD_TIMESTAMP "2024-01-15T10:30:00Z"
#define MYLIB_BUILD_TYPE "Release"

// Platform-specific
#ifdef __ANDROID__
#define MYLIB_VERSION_CODE 10203
#elif defined(__APPLE__)
#define MYLIB_BUNDLE_VERSION "123"
#elif defined(_WIN32)
#define MYLIB_FILE_VERSION "1.2.3.0"
#endif

namespace mylib {
    const char* get_version();
    const char* get_git_sha();
    const char* get_build_timestamp();
}
```

**Implementation:**
```cpp
// src/version.cpp (auto-generated)
#include "mylib/version.h"

namespace mylib {
    const char* get_version() {
        return MYLIB_VERSION;
    }

    const char* get_git_sha() {
        return MYLIB_GIT_SHA;
    }

    const char* get_build_timestamp() {
        return MYLIB_BUILD_TIMESTAMP;
    }
}
```

### Using Version in Code

```cpp
#include "mylib/version.h"
#include <iostream>

void print_version() {
    std::cout << "MyLib version: " << mylib::get_version() << "\n";
    std::cout << "Git SHA: " << mylib::get_git_sha() << "\n";
    std::cout << "Built: " << mylib::get_build_timestamp() << "\n";
}
```

## Platform-Specific Versioning

### Android

**Version Code and Version Name:**
```toml
[package]
version = "1.2.3"

[version.android]
version_code = 10203       # Integer for Play Store
version_name = "1.2.3"     # Display name (defaults to package.version)
```

**Gradle Integration:**
```kotlin
// Generated in build.gradle.kts
android {
    defaultConfig {
        versionCode = 10203
        versionName = "1.2.3"
    }
}
```

### iOS

**Bundle Version:**
```toml
[package]
version = "1.2.3"

[version.ios]
bundle_short_version = "1.2.3"  # CFBundleShortVersionString
build_number = "123"             # CFBundleVersion
```

**Info.plist:**
```xml
<key>CFBundleShortVersionString</key>
<string>1.2.3</string>
<key>CFBundleVersion</key>
<string>123</string>
```

### OpenHarmony

**HAR Version:**
```toml
[package]
version = "1.2.3"

[version.ohos]
app_version_code = 10203
app_version_name = "1.2.3"
```

**module.json5:**
```json
{
  "module": {
    "versionCode": 10203,
    "versionName": "1.2.3"
  }
}
```

### Windows

**File Version:**
```toml
[package]
version = "1.2.3"

[version.windows]
file_version = "1.2.3.0"        # Four-part version
product_version = "1.2"          # Display version
company_name = "Your Company"
copyright = "Copyright © 2024"
```

**Resource File (.rc):**
```rc
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,2,3,0
PRODUCTVERSION 1,2,0,0
{
    VALUE "FileVersion", "1.2.3.0"
    VALUE "ProductVersion", "1.2"
    VALUE "CompanyName", "Your Company"
    VALUE "LegalCopyright", "Copyright © 2024"
}
```

## Pre-Release Versions

### Alpha Releases

```toml
[package]
version = "2.0.0-alpha.1"

[version]
prerelease_suffix = "alpha"
```

```bash
# Tag alpha release
ccgo tag v2.0.0-alpha.1 --message "Alpha release 1"
```

### Beta Releases

```toml
[package]
version = "2.0.0-beta.2"

[version]
prerelease_suffix = "beta"
```

### Release Candidates

```toml
[package]
version = "2.0.0-rc.1"

[version]
prerelease_suffix = "rc"
```

### Promotion to Stable

```bash
# Promote RC to stable
# 1. Update CCGO.toml
version = "2.0.0"  # Remove -rc.1

# 2. Create stable tag
ccgo tag v2.0.0 --message "Stable release 2.0.0"
```

## Build Metadata

### Git Information

CCGO automatically includes:
- **Commit SHA**: Current git commit hash
- **Branch**: Current git branch name
- **Tag**: Closest git tag (if any)
- **Dirty**: Whether working directory has uncommitted changes

### Timestamp

```cpp
// ISO 8601 format
#define MYLIB_BUILD_TIMESTAMP "2024-01-15T10:30:00Z"
```

### Build Type

```cpp
// Release or Debug
#define MYLIB_BUILD_TYPE "Release"
```

### Custom Metadata

```toml
[version]
custom_metadata = [
    "jenkins_build_123",
    "ci_pipeline_456"
]
```

## Version Queries

### Check Current Version

```bash
# Show version from CCGO.toml
ccgo --version

# Show detailed version info
ccgo version --detailed

# Output:
# CCGO version: 3.0.10
# Project: mylib
# Version: 1.2.3
# Git SHA: 8f3a2b1c
# Git branch: main
# Modified: no
```

### Runtime Version Query

```cpp
// In your application
#include "mylib/mylib.h"

const char* version = mylib::get_version();
printf("Library version: %s\n", version);
```

## Versioning Workflows

### Development Workflow

```bash
# 1. Start new feature
git checkout -b feature/new-api
# CCGO.toml: version = "1.2.0"

# 2. Develop and test
ccgo build --all
ccgo test

# 3. Merge to main
git checkout main
git merge feature/new-api

# 4. Bump version
# Update CCGO.toml: version = "1.3.0"

# 5. Create tag
ccgo tag v1.3.0 --message "Add new API"

# 6. Push
git push origin main --tags
```

### Release Workflow

```bash
# 1. Create release branch
git checkout -b release/2.0
# CCGO.toml: version = "2.0.0-rc.1"

# 2. Test release candidate
ccgo build --all
ccgo test --all

# 3. Fix bugs if needed
# ... bug fixes ...

# 4. Promote to stable
# Update CCGO.toml: version = "2.0.0"
ccgo tag v2.0.0 --message "Release 2.0.0"

# 5. Merge back to main
git checkout main
git merge release/2.0

# 6. Push
git push origin main --tags
```

### Hotfix Workflow

```bash
# 1. Create hotfix branch from tag
git checkout -b hotfix/1.2.4 v1.2.3
# CCGO.toml: version = "1.2.4"

# 2. Fix critical bug
# ... fix ...

# 3. Test
ccgo build --all
ccgo test

# 4. Create tag
ccgo tag v1.2.4 --message "Hotfix: critical bug"

# 5. Merge to main and release branch
git checkout main
git cherry-pick hotfix/1.2.4

git checkout release/1.2
git cherry-pick hotfix/1.2.4

# 6. Push
git push origin main release/1.2 --tags
```

## Changelog Integration

### Automatic Changelog Generation

```bash
# Generate changelog from git tags
ccgo changelog

# Output to file
ccgo changelog --output CHANGELOG.md

# Between specific versions
ccgo changelog --from v1.0.0 --to v2.0.0
```

### Changelog Format

```markdown
# Changelog

## [2.0.0] - 2024-01-15

### Added
- New authentication API
- Support for OAuth 2.0

### Changed
- Updated dependency versions
- Improved error handling

### Fixed
- Memory leak in network module
- Crash on invalid input

### Breaking Changes
- Removed deprecated APIs
- Changed function signatures

## [1.2.3] - 2024-01-01

### Fixed
- Critical security vulnerability
```

## Version Constraints

### Dependency Versions

```toml
[dependencies]
openssl = { version = "^1.1.0" }  # Compatible with 1.1.x
boost = { version = "~1.80.0" }   # Compatible with 1.80.x
zlib = { version = "1.2.11" }     # Exact version

# Version ranges
protobuf = { version = ">=3.0.0, <4.0.0" }
```

**Operators:**
- `^`: Compatible with (same major version)
- `~`: Approximately compatible (same minor version)
- `>=`, `<=`, `>`, `<`: Comparison operators
- `,`: AND operator

### Platform-Specific Constraints

```toml
[dependencies.android]
androidx-core = { version = "1.12.0" }

[dependencies.ios]
alamofire = { version = "~5.8.0" }
```

## Best Practices

### 1. Version Numbering

- **Start at 1.0.0** for first stable release
- **0.y.z** for initial development (unstable API)
- **Increment MAJOR** for breaking changes
- **Increment MINOR** for new features
- **Increment PATCH** for bug fixes

### 2. Tag Management

```bash
# Always use annotated tags for releases
git tag -a v1.0.0 -m "Release 1.0.0"

# Lightweight tags for internal use only
git tag build-123

# Push tags explicitly
git push origin v1.0.0
```

### 3. Version in Commit Messages

```bash
# Good commit messages
git commit -m "chore: bump version to 1.2.3"
git commit -m "release: v2.0.0"
git commit -m "hotfix: v1.2.4 - fix critical bug"
```

### 4. Pre-Release Testing

```bash
# Test all platforms before release
ccgo build --all --release
ccgo test --all

# Verify version info
ccgo version --detailed
```

### 5. Documentation

- Update CHANGELOG.md before each release
- Document breaking changes clearly
- Maintain migration guides for major versions

## CI/CD Integration

### GitHub Actions

```yaml
name: Release
on:
  push:
    tags:
      - 'v*'

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Extract version
        id: version
        run: |
          VERSION=${GITHUB_REF#refs/tags/v}
          echo "version=$VERSION" >> $GITHUB_OUTPUT

      - name: Build all platforms
        run: ccgo build --all --release

      - name: Create GitHub Release
        uses: actions/create-release@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          tag_name: ${{ github.ref }}
          release_name: Release ${{ steps.version.outputs.version }}
          draft: false
          prerelease: false
```

### GitLab CI

```yaml
release:
  stage: deploy
  only:
    - tags
  script:
    - ccgo build --all --release
    - ccgo publish --all --registry official
  artifacts:
    paths:
      - target/
```

## Troubleshooting

### Version Mismatch

**Problem:**
```
Warning: CCGO.toml version (1.2.3) doesn't match git tag (v1.2.2)
```

**Solution:**
```bash
# Update CCGO.toml to match tag
# Or create new tag matching CCGO.toml
ccgo tag --force
```

### Invalid Version Format

**Problem:**
```
Error: Invalid version format: "1.2.3.4.5"
```

**Solution:**
```toml
# Use SemVer format
version = "1.2.3"  # Not "1.2.3.4.5"
```

### Tag Already Exists

**Problem:**
```
Error: tag 'v1.0.0' already exists
```

**Solution:**
```bash
# Delete old tag (if intentional)
git tag -d v1.0.0
git push origin :refs/tags/v1.0.0

# Create new tag
ccgo tag v1.0.0
```

## Examples

### Complete Versioning Setup

```toml
# CCGO.toml
[package]
name = "mylib"
version = "1.2.3"
authors = ["Your Name <you@example.com>"]

[version]
inject_build_metadata = true
inject_to_code = true

[version.android]
version_code = 10203

[version.ios]
build_number = "123"

[version.windows]
file_version = "1.2.3.0"
company_name = "Your Company"
copyright = "Copyright © 2024"
```

## Resources

### Tools

- [Semantic Versioning]https://semver.org/
- [Keep a Changelog]https://keepachangelog.com/
- [Conventional Commits]https://www.conventionalcommits.org/

### CCGO Documentation

- [CLI Reference]../reference/cli.md
- [CCGO.toml Reference]../reference/ccgo-toml.md
- [Git Integration]git-integration.md
- [Publishing Guide]publishing.md

### Community

- [GitHub Discussions]https://github.com/zhlinh/ccgo/discussions
- [Issue Tracker]https://github.com/zhlinh/ccgo/issues

## Next Steps

- [Git Integration]git-integration.md
- [Publishing Guide]publishing.md
- [CI/CD Setup]../development/contributing.md
- [Changelog Management]../development/changelog.md