Full Code of preshing/cairo-windows for AI

master 925dd85d6a78 cached
5 files
10.4 KB
3.1k tokens
1 requests
Download .txt
Repository: preshing/cairo-windows
Branch: master
Commit: 925dd85d6a78
Files: 5
Total size: 10.4 KB

Directory structure:
gitextract_ppf4vhn_/

├── .gitignore
├── LICENSE
├── README.md
├── build-cairo-windows.sh
└── deps.yml

================================================
FILE CONTENTS
================================================

================================================
FILE: .gitignore
================================================
/*/
/*.tar.*


================================================
FILE: LICENSE
================================================
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <http://unlicense.org>


================================================
FILE: README.md
================================================
This repository is meant to help create Cairo DLLs for Windows. Both 32-bit and 64-bit versions can be built. The resulting `cairo.dll` file is fully self-contained and does not depend on any other third-party DLLs. FreeType support is included. See [this blog post](http://preshing.com/20170529/heres-a-standalone-cairo-dll-for-windows) for more information.

Binary releases are available [here](https://github.com/preshing/cairo-windows/releases).

# Build Steps

The `build-cairo-windows.sh` shell script will download, extract, and build all the necessary libraries to link a self-contained `cairo.dll` with FreeType support. It uses the existing build pipelines of each library as much as possible. It was adapted from https://www.cairographics.org/end_to_end_build_for_win32/

The Visual Studio 2017 compiler is used. Either MSYS, MSYS2 or Cygwin must be used to drive the build environment. So far it has only been tested with MSYS2. If using MSYS2, you'll need to install `tar` and `make` first:

    $ pacman -S tar make

## Building 32-bit

You'll need to create an MSYS2 (for example) shell that has all the correct environment variables set for Visual Studio 2017, including `INCLUDE`, `LIB` and `PATH`.

As of this writing, this can be achieved by opening "x86 Native Tools Command Prompt for VS 2017" from the start menu, and entering commands similar to the following. The final command runs the `build-cairo-windows.sh` script.

```
(from an x86 Native Tools Command Prompt for VS 2017)
> set PATH=C:\msys64;%PATH%
> msys2_shell.cmd -use-full-path
$ unset TMP
$ unset TEMP
$ ./build-cairo-windows.sh
```

Some notes:

* `msys2_shell.cmd -use-full-path` opens an MSYS2 terminal while [inheriting the PATH](https://sourceforge.net/p/msys2/discussion/general/thread/dbe17030/#3f85) from the x86 Native Tools Command Prompt.
* `unset TMP` and `unset TEMP` are currently needed to avoid `error MSB6001: Invalid command line switch for "CL.exe". Item has already been added. Key in dictionary: 'TMP' Key being added: 'tmp'`, which is caused by the MSYS2 environment block [having multiple `TMP` entries due to case sensitivty](https://cmake.org/Bug/print_bug_page.php?bug_id=13131).

When it's done, you'll find a self-contained package in a subdirectory named `output/cairo-windows-x.x.x`.

## Building 64-bit

1. First build 32-bit.
2. Open `libpng\projects\vstudio\vstudio.sln` in Visual Studio, then add the "x64" platform to the solution as follows:
   * Build &rarr; Configuration Manager
   * Active solution platform: &rarr; <New...>
   * Select x64, click OK, close the Configuration Manager
   * File &rarr; Save All
3. Perform similar steps as for 32-bit, but open an "**x64** Native Tools Command Prompt for VS 2017" instead, and pass `x64` as an argument to the script:

```
(from an x64 Native Tools Command Prompt for VS 2017)
> set PATH=C:\msys64;%PATH%
> msys2_shell.cmd -use-full-path
$ unset TMP
$ unset TEMP
$ ./build-cairo-windows.sh x64
```

# Updating dependencies

The repo contains a deps.yml which can update cairo, freetype etc using dependencies.io


To run this locally, install the commandline tool from https://deps.app/local/

```
$ curl https://deps.app/install.sh | bash -s -- -b $HOME/bin
```

Then run it, accepting all the prompts:
```
$ yes | deps run
```



================================================
FILE: build-cairo-windows.sh
================================================
#! bash
set -e
trap 'previous_command=$this_command; this_command=$BASH_COMMAND' DEBUG
trap 'echo FAILED COMMAND: $previous_command' EXIT

# Versions used
USE_FREETYPE=1
CAIRO_VERSION=cairo-1.17.2
PIXMAN_VERSION=pixman-0.40.0
LIBPNG_VERSION=libpng-1.6.37
ZLIB_VERSION=zlib-1.2.11
FREETYPE_VERSION=freetype-2.10.2

# Set variables according to command line argument
if [ ${1:-x86} = x64 ]; then
    MSVC_PLATFORM_NAME=x64
    OUTPUT_PLATFORM_NAME=x64
else
    MSVC_PLATFORM_NAME=Win32
    OUTPUT_PLATFORM_NAME=x86
fi

# Make sure the MSVC linker appears first in the path
MSVC_LINK_PATH=`whereis link | sed "s| /usr/bin/link.exe||" | sed "s|.*\(/c.*\)link.exe.*|\1|"`
export PATH="$MSVC_LINK_PATH:$PATH"

# Download packages if not already
wget -nc https://www.cairographics.org/snapshots/$CAIRO_VERSION.tar.xz
wget -nc https://www.cairographics.org/releases/$PIXMAN_VERSION.tar.gz
wget -nc https://download.sourceforge.net/libpng/$LIBPNG_VERSION.tar.gz
wget -nc http://www.zlib.net/$ZLIB_VERSION.tar.gz
if [ $USE_FREETYPE -ne 0 ]; then
    wget -nc http://download.savannah.gnu.org/releases/freetype/$FREETYPE_VERSION.tar.gz
fi    

# Extract packages if not already
if [ ! -d cairo ]; then
    echo "Extracting $CAIRO_VERSION..."
    tar -xJf $CAIRO_VERSION.tar.xz
    mv $CAIRO_VERSION cairo
fi
if [ ! -d pixman ]; then
    echo "Extracting $PIXMAN_VERSION..."
    tar -xzf $PIXMAN_VERSION.tar.gz
    mv $PIXMAN_VERSION pixman
fi
if [ ! -d libpng ]; then
    echo "Extracting $LIBPNG_VERSION..."
    tar -xzf $LIBPNG_VERSION.tar.gz
    mv $LIBPNG_VERSION libpng
fi
if [ ! -d zlib ]; then
    echo "Extracting $ZLIB_VERSION..."
    tar -xzf $ZLIB_VERSION.tar.gz
    mv $ZLIB_VERSION zlib
fi
if [ $USE_FREETYPE -ne 0 ] && [ ! -d freetype ]; then
    echo "Extracting $FREETYPE_VERSION..."
    tar -xzf $FREETYPE_VERSION.tar.gz
    mv $FREETYPE_VERSION freetype
fi

# Build libpng and zlib
cd libpng
sed 's#4996</Disable#4996;5045</Disable#' projects/vstudio/zlib.props > zlib.props.fixed
mv zlib.props.fixed projects/vstudio/zlib.props
if [ ! -d "projects\vstudio\Backup" ]; then
    # Upgrade solution if not already
    devenv.com "projects\vstudio\vstudio.sln" -upgrade
fi
devenv.com "projects\vstudio\vstudio.sln" -build "Release Library|$MSVC_PLATFORM_NAME" -project libpng
cd ..
if [ $MSVC_PLATFORM_NAME = x64 ]; then
    cp "libpng/projects/vstudio/x64/Release Library/libpng16.lib" libpng/libpng.lib
    cp "libpng/projects/vstudio/x64/Release Library/zlib.lib" zlib/zlib.lib
else
    cp "libpng/projects/vstudio/Release Library/libpng16.lib" libpng/libpng.lib
    cp "libpng/projects/vstudio/Release Library/zlib.lib" zlib/zlib.lib
fi

# Build pixman
cd pixman
sed s/-MD/-MT/ Makefile.win32.common > Makefile.win32.common.fixed
mv Makefile.win32.common.fixed Makefile.win32.common
if [ $MSVC_PLATFORM_NAME = x64 ]; then
    # pass -B for switching between x86/x64
    make pixman -B -f Makefile.win32 "CFG=release" "MMX=off"
else
    make pixman -B -f Makefile.win32 "CFG=release"
fi
cd ..

if [ $USE_FREETYPE -ne 0 ]; then
    cd freetype
    # Build freetype
    if [ ! -d "builds/windows/vc2010/Backup" ]; then
        # Upgrade solution if not already
        devenv.com "builds/windows/vc2010/freetype.sln" -upgrade
    fi
    devenv.com "builds/windows/vc2010/freetype.sln" -build "Release Static|$MSVC_PLATFORM_NAME"
    cp "`ls -1d "objs/$MSVC_PLATFORM_NAME/Release Static/freetype.lib"`" .
    cd ..
fi

# Build cairo
cd cairo
sed 's/-MD/-MT/;s/zdll.lib/zlib.lib/' build/Makefile.win32.common > Makefile.win32.common.fixed
mv Makefile.win32.common.fixed build/Makefile.win32.common
if [ $USE_FREETYPE -ne 0 ]; then
    sed '/^CAIRO_LIBS =/s/$/ $(top_builddir)\/..\/freetype\/freetype.lib/;/^DEFAULT_CFLAGS =/s/$/ -I$(top_srcdir)\/..\/freetype\/include/' build/Makefile.win32.common > Makefile.win32.common.fixed
else
    sed '/^CAIRO_LIBS =/s/ $(top_builddir)\/..\/freetype\/freetype.lib//;/^DEFAULT_CFLAGS =/s/ -I$(top_srcdir)\/..\/freetype\/include//' build/Makefile.win32.common > Makefile.win32.common.fixed
fi
mv Makefile.win32.common.fixed build/Makefile.win32.common
sed "s/CAIRO_HAS_FT_FONT=./CAIRO_HAS_FT_FONT=$USE_FREETYPE/" build/Makefile.win32.features > Makefile.win32.features.fixed
mv Makefile.win32.features.fixed build/Makefile.win32.features
# pass -B for switching between x86/x64
make -B -f Makefile.win32 cairo "CFG=release"
cd ..

# Package headers with DLL
OUTPUT_FOLDER=output/${CAIRO_VERSION/cairo-/cairo-windows-}
mkdir -p $OUTPUT_FOLDER/include
for file in cairo/cairo-version.h \
            cairo/src/cairo-features.h \
            cairo/src/cairo.h \
            cairo/src/cairo-deprecated.h \
            cairo/src/cairo-win32.h \
            cairo/src/cairo-script.h \
            cairo/src/cairo-ps.h \
            cairo/src/cairo-pdf.h \
            cairo/src/cairo-svg.h; do
    cp $file $OUTPUT_FOLDER/include
done
if [ $USE_FREETYPE -ne 0 ]; then
    cp cairo/src/cairo-ft.h $OUTPUT_FOLDER/include
fi
mkdir -p $OUTPUT_FOLDER/lib/$OUTPUT_PLATFORM_NAME
cp cairo/src/release/cairo.lib $OUTPUT_FOLDER/lib/$OUTPUT_PLATFORM_NAME
cp cairo/src/release/cairo.dll $OUTPUT_FOLDER/lib/$OUTPUT_PLATFORM_NAME
cp cairo/COPYING* $OUTPUT_FOLDER

trap - EXIT
echo 'Success!'


================================================
FILE: deps.yml
================================================
version: 3
dependencies:
- type: git
  settings:
    remotes:
      git://anongit.freedesktop.org/git/cairo:
         replace_in_files:
         - filename: build-cairo-windows.sh
           pattern: CAIRO_VERSION=cairo-(\S+)
      https://github.com/freedesktop/pixman.git:
        replace_in_files:
        - filename: build-cairo-windows.sh
          pattern: PIXMAN_VERSION=pixman-(\S+)
          tag_prefix: pixman-
      https://github.com/glennrp/libpng.git:
        replace_in_files:
        - filename: build-cairo-windows.sh
          pattern: LIBPNG_VERSION=libpng-(\S+)
          tag_prefix: v
      git://git.sv.nongnu.org/freetype/freetype2.git:
        replace_in_files:
        - filename: build-cairo-windows.sh
          pattern: FREETYPE_VERSION=freetype-(\S+)
          tag_filter:
            matching: 'VER-(\d+)-(\d+)-(\d+)'
            output_as: '$1.$2.$3'  # output and sort as a semver-compatible 
Download .txt
gitextract_ppf4vhn_/

├── .gitignore
├── LICENSE
├── README.md
├── build-cairo-windows.sh
└── deps.yml
Condensed preview — 5 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (11K chars).
[
  {
    "path": ".gitignore",
    "chars": 13,
    "preview": "/*/\n/*.tar.*\n"
  },
  {
    "path": "LICENSE",
    "chars": 1210,
    "preview": "This is free and unencumbered software released into the public domain.\n\nAnyone is free to copy, modify, publish, use, c"
  },
  {
    "path": "README.md",
    "chars": 3306,
    "preview": "This repository is meant to help create Cairo DLLs for Windows. Both 32-bit and 64-bit versions can be built. The result"
  },
  {
    "path": "build-cairo-windows.sh",
    "chars": 5212,
    "preview": "#! bash\nset -e\ntrap 'previous_command=$this_command; this_command=$BASH_COMMAND' DEBUG\ntrap 'echo FAILED COMMAND: $previ"
  },
  {
    "path": "deps.yml",
    "chars": 925,
    "preview": "version: 3\ndependencies:\n- type: git\n  settings:\n    remotes:\n      git://anongit.freedesktop.org/git/cairo:\n         re"
  }
]

About this extraction

This page contains the full source code of the preshing/cairo-windows GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 5 files (10.4 KB), approximately 3.1k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!