Skip to content

Commit

Permalink
Ccache windows dynamic build (#1077)
Browse files Browse the repository at this point in the history
* Configure ccache exe for Visual Studio generator through env var

* add info on Windows ccache to README

* Determine ccache version automatically

* cmake indentation

* remove outdated comment
  • Loading branch information
trvto authored Oct 13, 2023
1 parent 013df5e commit dc6f7eb
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 19 deletions.
45 changes: 38 additions & 7 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -420,12 +420,6 @@ jobs:
build_test_pytket_windows:
name: Build and test pytket (windows)
# I could not get ccache working for this build
# Building tket as a dynamic library currently fails with the Ninja and Makefiles Generators and ccache is set up is more difficult with the Visual Studio generator
# I tried to get ccache working with the Visual Studio generator using the suggestions here: https://github.com/ccache/ccache/wiki/MS-Visual-Studio#usage-with-cmake
# I was able to get ccache to wrap the compiler invocations, but all files are reported as uncacheable, due to "No input file"
# See https://ccache.dev/manual/4.8.2.html#_cache_statistics for more info on what that means. I myself haven't fully understood.
# Giving up for now
needs: check_changes
if: needs.check_changes.outputs.tket_or_workflow_changed == 'true' || needs.check_changes.outputs.pytket_or_workflow_changed == 'true'
runs-on: windows-2022
Expand All @@ -452,10 +446,43 @@ jobs:
$normalized_file = [IO.File]::ReadAllText($f) -replace "`r`n", "`n"
[IO.File]::WriteAllText($f, $normalized_file)
}
- name: ccache setup
# This is what hendrikmuhs/ccache-action does, but for windows (theirs is buggy on windows)
id: ccache-setup
run: |
choco upgrade ccache
$ccache_dir = ccache --get-config cache_dir
echo ccache_dir=$ccache_dir >> $env:GITHUB_OUTPUT
ccache --set-config=max_size='500M'
ccache --set-config=compression=true
ccache --set-config compiler_check=content
ccache --set-config namespace=WITH_TESTS
ccache -p
- name: Get current time
uses: josStorer/[email protected]
id: current_time
with:
format: YYYYMMDDHHmmss
- name: ccache windows
uses: actions/cache@v3
with:
path: ${{ steps.ccache-setup.outputs.ccache_dir }}
key: tket-dynamic-visual-studio-windows-2022-${{ steps.current_time.outputs.formattedTime }}
restore-keys: |
tket-dynamic-visual-studio-windows-2022
- name: get ccache version
id: ccache-ver
shell: bash
run: |
ccache_ver=$(choco list -e ccache | grep "ccache" | grep -ioE '[0-9]+\.[0-9]+\.[0-9]+')
echo "Found ccache version ${ccache_ver}"
echo "ccache_ver=${ccache_ver}" >> $GITHUB_OUTPUT
- name: Build tket
if: needs.check_changes.outputs.tket_changed == 'true'
run: |
conan create tket --user tket --channel stable -o boost/*:header_only=True -o tklog/*:shared=True -o tket/*:shared=True -tf `"`"
$env:TKET_VSGEN_CCACHE_EXE = 'C:\\ProgramData\\chocolatey\\lib\\ccache\\tools\\ccache-${{ steps.ccache-ver.outputs.ccache_ver }}-windows-x86_64\\ccache.exe'
conan build tket --user tket --channel stable -o boost/*:header_only=True -o tklog/*:shared=True -o tket/*:shared=True
conan export-pkg tket --user tket --channel stable -o boost/*:header_only=True -o tklog/*:shared=True -o tket/*:shared=True -tf `"`"
- name: Install tket
if: needs.check_changes.outputs.tket_changed != 'true'
run: conan install --requires tket/${{ needs.check_changes.outputs.tket_ver }}@tket/stable -o boost/*:header_only=True -o tklog/*:shared=True -o tket/*:shared=True
Expand Down Expand Up @@ -500,6 +527,10 @@ jobs:
run: |
conan remote login -p ${{ secrets.JFROG_ARTIFACTORY_TOKEN_3 }} tket-libs ${{ secrets.JFROG_ARTIFACTORY_USER_3 }}
conan upload tket/${{ needs.check_changes.outputs.tket_ver }}@tket/stable -r=tket-libs
- name: ccache stats
run: |
ccache -s #show stats
ccache -z #show stats
publish_pytket_coverage:
name: Publish pytket coverage
Expand Down
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,23 @@ Chocolatey on Windows:
choco install ninja ccache
```

If installed, `ccache` is used automatically. `ninja` can be set as the default generator
using the following command:
```shell
echo "tools.cmake.cmaketoolchain:generator = Ninja" >> $(conan config home)/global.conf
```
On MacOS/Linux:

- If installed, `ccache` is used automatically
- `ninja` must either be set as the default Cmake generator using the following command:
```shell
echo "tools.cmake.cmaketoolchain:generator = Ninja" >> $(conan config home)/global.conf
```
or be specified on a command-by-command basis by providing the argument
`-c tools.cmake.cmaketoolchain:generator=Ninja` to conan

On Windows:
- Set `ninja` as generator as described above (less reliable than the default `Visual Studio` generator)
- `ccache` will be used automatically *only* when using `Ninja` or `Makefile` as the Cmake generator. It can
also be used with `Visual Studio` generators by setting the environment
variable `TKET_VSGEN_CCACHE_EXE` to the path of the `ccache` executable. **Note: this
must be the path to the actual binary, not a symlink or shim (as used by Chocolatey)**. If using Chocolatey
to install `ccache`, you can find the path to the binary using `ccache --shimgen-help`


### Building and testing the utility libraries
Expand Down
2 changes: 1 addition & 1 deletion pytket/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def package(self):
cmake.install()

def requirements(self):
self.requires("tket/1.2.58@tket/stable")
self.requires("tket/1.2.59@tket/stable")
self.requires("tklog/0.3.3@tket/stable")
self.requires("tkrng/0.3.3@tket/stable")
self.requires("tkassert/0.3.3@tket/stable")
Expand Down
29 changes: 24 additions & 5 deletions tket/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,30 @@ if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()

find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
message("-> Setting ccache (${CCACHE_PROGRAM} as compiler launcher for generator ${CMAKE_GENERATOR}")
message("-> This is only supported for the Ninja and Makefile generators")

# ccache stuff
if (CMAKE_GENERATOR MATCHES "Visual Studio" AND DEFINED ENV{TKET_VSGEN_CCACHE_EXE})
file(COPY_FILE $ENV{TKET_VSGEN_CCACHE_EXE} ${CMAKE_BINARY_DIR}/cl.exe ONLY_IF_DIFFERENT)
message("-> Setting ccache ($ENV{TKET_VSGEN_CCACHE_EXE}) as compiler launcher for generator ${CMAKE_GENERATOR}")

# By default Visual Studio generators will use /Zi which is not compatible
# with ccache, so tell Visual Studio to use /Z7 instead.
message(STATUS " Setting MSVC debug information format to 'Embedded'")
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<$<CONFIG:Debug,RelWithDebInfo>:Embedded>")

set(CMAKE_VS_GLOBALS
"CLToolExe=cl.exe"
"CLToolPath=${CMAKE_BINARY_DIR}"
"TrackFileAccess=false"
"UseMultiToolTask=true"
"DebugInformationFormat=OldStyle"
)
else()
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
message("-> Setting ccache (${CCACHE_PROGRAM}) as compiler launcher for generator ${CMAKE_GENERATOR}")
endif ()
endif()

if(WIN32)
Expand Down
2 changes: 1 addition & 1 deletion tket/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

class TketConan(ConanFile):
name = "tket"
version = "1.2.58"
version = "1.2.59"
package_type = "library"
license = "Apache 2"
homepage = "https://github.com/CQCL/tket"
Expand Down

0 comments on commit dc6f7eb

Please sign in to comment.