1

I have a cmake project that uses vcpkg to manage its dependencies. vcpkg is used in 'manifest mode'. Meaning my dependencies are specified in the vcpkg.json that reside in the project root directory:

{
    "name": "myproject",
    "version-string": "1.0.0",
    "builtin-baseline": "232704deb708fc866905af170b63c1a9cb821dbc",
    "dependencies": [
        {
          "name" : "imgui",
          "default-features": true,
          "features" : ["docking-experimental"]
        },
        "magnum",
        {
          "name" : "magnum-integration",        
          "default-features": false,
          "features" : ["imgui"]
        }
    ]
}

The "builtin-baseline" field contains the git SHA-1 identifying a commit in my own privately maintained vcpkg repository.

For example, the magnum dependency is configured to the use latest 'baseline' version. meaning if you go to where vcpkg in installed, there is a file versions/baseline.json where the baseline is determined.

vcpkg has a (complicated and non intuitive) mechanism to pin certain dependencies to older versions. However, I could not find a structured way of how to modify the vcpkg installation so it will install a different version from a git repository. vcpkg "overlay ports" feature does not work in manifest mode.

Ideally, vcpkg would allow me to do something simple, such as:

    "magnum",
        {
          "git-commit" : "dagfaghsfdg",
          "name" : "magnum-integration",        
          "default-features": false,
          "features" : ["imgui"]
        }

So how can I configure vcpkg to use a certain git commit for a dependency (in manifest mode)?

Elad Maimoni
  • 3,703
  • 3
  • 20
  • 37

1 Answers1

5

Currently the solution I came up with is as follows. I am not sure it is ideal.

I will demonstrate it on the "magnum" dependency.

Step 1: Modify the relevant vcpkg/portfile.cmake

Usually this file will contain a call to a function called vcpkg_from_github that refers to a git tag (REF parameter). Modify this parameter to refer to the desired commit.

vcpkg_from_github(
    OUT_SOURCE_PATH SOURCE_PATH
    REPO mosra/magnum
    REF 49bcbed2f4799e7b341975a5dde98d4ba4d288d8
    SHA512 08582553725ee63eb4c6732fa6a7d82e8e0a1fed92e0e9d82035c2aa79b0df29f1fdef521768f1ef8399cef8b4550e3a8734c3a0c4f04c40ecdb7fd6c99e1bc5
    HEAD_REF master
)

the SHA512 also needs to be changed. But becuase vcpkg likes to make things hard, it cannot deduce it automatically. You must to attempt a vcpkg install on the package, fail, get the actual value, and set it manually:

vcpkg install magnum

File does not have expected hash:

          File path: [ C:/Libraries/vcpkg/downloads/mosra-magnum-72ee390afa8dd1f9d94355595ff4dc74408977fc.tar.gz ]
      Expected hash: [ 08582553725ee63eb4c6732fa6a7d82e8e0a1fed92e0e9d82035c2aa79b0df29f1fdef521768f1ef8399cef8b4550e3a8734c3a0c4f04c40ecdb7fd6c99e1bc5 ]
        Actual hash: [ 08582553725ee63eb4c6732fa6a7d82e8e0a1fed92e0e9d82035c2aa79b0df29f1fdef521768f1ef8399cef8b4550e3a8734c3a0c4f04c40ecdb7fd6c99e1bc4 ]

replace the SHA512 parameter with the value in Actual hash.

Step 2: Modify the version string in vcpkg/vcpkg.json

inside this file there is a version field. change it to something that makes sense.

  "name": "magnum",
  "version-string": "2022.00",
  "port-version": 0

I also changed the port-version to 0.

Step 3: Modify the baseline

Step 1 and 2 are enough if you wish to use non manifest mode. But you must modify the baseline if you wish to use a manifest.

Inside versions/baseline.json, change the baseline to the new version (matches the port file).

"magnum": {
  "baseline": "2022.00",
  "port-version": 0
},

Step 4: register the new version

Inside the versions directory, there are directories in alphabetical order with files listing available versions for each library. for example magnum.json:

  "versions": [
    {
      "git-tree": "39331fa0e35e058c25f2ee188ca816343111c232",
      "version-string": "2022.00",
      "port-version": 0
    },
    ...

So you need to add a new version entry. Now the "git-tree" field is not a git commit. it is a git object-id. in order to get it, you need to first commit all the current changes you made to the vcpkg directory, and the do:

git rev-parse HEAD:ports/magnum

copy the output to the git-tree field.

Step 5: repeat this for other dependencies of the dependency you changed

In my case, magnum is dependent on "corrade" library so I had to make the same changes there.

Step 6: change builtin-baseline

commit all your changes to the vcpkg repository, modify your manifest file (vcpkg.json) builtin-baseline field to refer to the latest commit in your vcpkg repo.

Elad Maimoni
  • 3,703
  • 3
  • 20
  • 37