Skip to content

Feature Request: Native vcpkg Integration and vcpkg.json Dependency Parsing #101

@AkimioJR

Description

@AkimioJR

Background:

In my CGO library, I use pkg-config

/*
#cgo pkg-config: freetype2 harfbuzz harfbuzz-subset

// freetype
#include <ft2build.h>
#include FT_FREETYPE_H // <freetype/freetype.h>
#include FT_TYPE1_TABLES_H // <freetype/t1tables.h>
#include FT_TRUETYPE_IDS_H // <freetype/ttnameid.h>
#include FT_TRUETYPE_TABLES_H // <freetype/tttables.h>
#include FT_SFNT_NAMES_H // <freetype/ftsnames.h>

// harfbuzz
#define HB_EXPERIMENTAL_API
#include <hb-subset.h>
*/
import "C"

to link third-party libraries across platforms. I want to use GoReleaser to build and release my example program, but currently the process is complex and error-prone, especially for macOS (e.g., due to missing SDKs and cross-compilation issues).

Current workaround:

I have to manually install dependencies via vcpkg in the before hooks, and set up environment variables for each build target, as shown below:

before:
  hooks:
    - apt-get update
    - apt-get install -y pkg-config ca-certificates
    - git clone https://github.com/Microsoft/vcpkg.git /vcpkg
    - /vcpkg/bootstrap-vcpkg.sh

builds:
  - id: linux-amd64
    ...
    hooks:
      pre:
        - flock /tmp/vcpkg.lock /vcpkg/vcpkg install --triplet=x64-linux-release --x-install-root=/vcpkg_installed_linux_x64
    ...
    env:
      - PKG_CONFIG_PATH=/vcpkg_installed_linux_x64/x64-linux-release/lib/pkgconfig
  - id: darwin-arm64
    ...
    hooks:
      pre:
        - flock /tmp/vcpkg.lock /vcpkg/vcpkg install --triplet=arm64-osx-release --x-install-root=/vcpkg_installed_darwin_arm64
    ...
    env:
      - PKG_CONFIG_PATH=/vcpkg_installed_darwin_arm64/arm64-osx-release/lib/pkgconfig

Problems:

  • The process is complex and fragile, especially for cross-compiling to macOS.
  • It requires a lot of manual configuration and scripting.
  • There is no native support for parsing dependencies from a vcpkg.json

Feature Proposal:

  • Add native support for vcpkg in GoReleaser.
  • Allow specifying a vcpkg.json file in the config, so dependencies can be automatically installed by vcpkg.
  • Allow specifying the vcpkg triplet as a parameter.
  • GoReleaser should handle the vcpkg bootstrap, dependency installation, and environment setup automatically.

Example of vcpkg.json:

{
    "builtin-baseline": "7066011e27c97dbcfff739be2b69b592a41fc74a",
    "dependencies": [
        {
            "name": "freetype",
            "features": ["brotli", "bzip2", "png", "zlib"]
        },
        {
            "name": "harfbuzz",
            "features": ["freetype"]
        },
        "brotli",
        "zlib",
        "libpng",
        "bzip2"
    ]
}

And a corresponding GoReleaser config param for the triplet.

Benefit:

This would greatly simplify cross-platform CGO builds and make GoReleaser friendlier for C/C++/CGO projects that rely on vcpkg.

Here's an example of what I'd expect to see as an updated go-releaser config file

- id: linux-amd64
    main: ./cmd/assfont-go
    binary: assfonts-go
    # hooks:
    # pre:
     #    - flock /tmp/vcpkg.lock /vcpkg/vcpkg install --triplet=x64-linux-release --x-install-root=/vcpkg_installed_linux_x64
    goos:
      - linux
    goarch:
      - amd64
    vcpkg:
      - triplet=x64-linux-release
      - config=./vcpkg.json
    env:
      - CC=x86_64-linux-gnu-gcc
      - CXX=x86_64-linux-gnu-g++
      # - PKG_CONFIG_PATH=/vcpkg_installed_linux_x64/x64-linux-release/lib/pkgconfig

Thanks for considering this feature!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions