Last active
August 29, 2015 14:06
-
-
Save MikaelSmith/d885c72dd87e61e3f969 to your computer and use it in GitHub Desktop.
Build script that downloads dependencies and builds puppetlabs/cfacter.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Starting from a base Windows Server 2008r2 or 2012r2 installation, install required tools, setup the PATH, and download and build software. | |
# This script can be run directly from the web using "iex ((new-object net.webclient).DownloadString('<url_to_raw>'))" | |
### Configuration | |
## Setup the working directory | |
$sourceDir=$pwd | |
## Set the number of cores to use for parallel builds | |
$cores=2 | |
## Choose whether to download pre-built libraries or build from source | |
$buildSource=$FALSE | |
## Choose 32 or 64-bit build | |
$arch=64 | |
$mingwVerNum = "4.8.3" | |
$mingwVerChoco = "${mingwVerNum}.20141208" | |
$mingwThreads = "posix" | |
if ($arch -eq 64) { | |
$mingwExceptions = "seh" | |
$mingwArch = "x86_64" | |
} else { | |
$mingwExceptions = "dwarf" | |
$mingwArch = "i686" | |
} | |
$mingwVer = "${mingwArch}_mingw-w64_${mingwVerNum}_${mingwThreads}_${mingwExceptions}" | |
$boostVerNum = "1.55.0" | |
$boostVer = "boost_$(${boostVerNum}.Replace('.', '_'))" | |
$boostPkg = "${boostVer}-${mingwVer}" | |
$yamlCppVerNum = "0.5.1" | |
$yamlCppVer = "yaml-cpp-${yamlCppVerNum}" | |
$yamlPkg = "${yamlCppVer}-${mingwVer}" | |
### Setup, build, and install | |
## Install Chocolatey, then use it to install required tools. | |
iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1')) | |
choco install 7zip.commandline cmake git ruby python doxygen.install | |
choco install mingw -Version "${mingwVerChoco}" | |
$env:PATH = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") | |
cd $sourceDir | |
## Download cfacter and setup build directories | |
git clone --recursive https://github.com/puppetlabs/cfacter | |
mkdir -Force cfacter\release\ext | |
cd cfacter\release | |
$buildDir=$pwd | |
cd ext | |
$toolsDir=$pwd | |
if ($buildSource) { | |
## Download, build, and install Boost | |
(New-Object net.webclient).DownloadFile("http://iweb.dl.sourceforge.net/project/boost/boost/$boostVerNum/$boostVer.7z", "$toolsDir\$boostVer.7z") | |
& 7za x "${boostVer}.7z" | FIND /V "ing " | |
cd $boostVer | |
.\bootstrap mingw | |
$args = @( | |
'toolset=gcc', | |
"--build-type=minimal", | |
"install", | |
"--with-program_options", | |
"--with-system", | |
"--with-filesystem", | |
"--with-date_time", | |
"--with-thread", | |
"--with-regex", | |
"--with-log", | |
"--with-locale", | |
"--prefix=`"$toolsDir\$boostPkg`"", | |
"boost.locale.iconv=off" | |
"-j$cores" | |
) | |
.\b2 $args | |
cd $toolsDir | |
## Download, build, and install yaml-cpp | |
(New-Object net.webclient).DownloadFile("https://yaml-cpp.googlecode.com/files/${yamlCppVer}.tar.gz", "$toolsDir\${yamlCppVer}.tar.gz") | |
& 7za x "${yamlCppVer}.tar.gz" | |
& 7za x "${yamlCppVer}.tar" | FIND /V "ing " | |
cd $yamlCppVer | |
mkdir build | |
cd build | |
$args = @( | |
'-G', | |
"MinGW Makefiles", | |
"-DBOOST_ROOT=`"$toolsDir\$boostPkg`"", | |
"-DCMAKE_INSTALL_PREFIX=`"$toolsDir\$yamlPkg`"", | |
".." | |
) | |
cmake $args | |
mingw32-make install -j $cores | |
cd $toolsDir | |
} else { | |
## Download and unpack Boost from a pre-built package in S3 | |
(New-Object net.webclient).DownloadFile("https://s3.amazonaws.com/kylo-pl-bucket/${boostPkg}.7z", "$toolsDir\${boostPkg}.7z") | |
& 7za x "${boostPkg}.7z" | FIND /V "ing " | |
## Download and unpack yaml-cpp from a pre-built package in S3 | |
(New-Object net.webclient).DownloadFile("https://s3.amazonaws.com/kylo-pl-bucket/${yamlPkg}.7z", "$toolsDir\${yamlPkg}.7z") | |
& 7za x "${yamlPkg}.7z" | FIND /V "ing " | |
} | |
## Build CFacter | |
cd $buildDir | |
$args = @( | |
'-G', | |
"MinGW Makefiles", | |
"-DBOOST_ROOT=`"$toolsDir\$boostPkg`"", | |
"-DYAMLCPP_ROOT=`"$toolsDir\$yamlPkg`"", | |
"-DBOOST_STATIC=ON", | |
".." | |
) | |
cmake $args | |
mingw32-make -j $cores |
Note: this seems to be broken for Ruby integration because RubyInstaller uses win32 threads and the mingw package on Chocolatey uses a POSIX thread implementation.
It looks like I'll probably have to build Boost with ICU, so this'll be updated with downloading MSYS and building ICU (http://qt-project.org/wiki/Compiling-ICU-with-MinGW)
Building Boost with ICU under MinGW
Build ICU using MSYS
# Download MSYS
(New-Object net.webclient).DownloadFile("http://sourceforge.net/projects/mingw-w64/files/External%20binary%20packages%20%28Win64%20hosted%29/MSYS%20%2832-bit%29/MSYS-20111123.zip", "$pwd\MSYS.zip")
& 7za x "MSYS.zip" | FIND /V "ing "
# Download ICU
(New-Object net.webclient).DownloadFile("http://download.icu-project.org/files/icu4c/54.1/icu4c-54_1-src.zip", "$pwd\icu4c-54_1-src.zip")
& 7za x "icu4c-54_1-src.zip" | FIND /V "ing "
# Add MSYS to PATH temporarily (CMake doesn't like having sh in PATH)
$env:SAVED_PATH=$env:PATH
$env:PATH="${pwd}\msys\bin;"+$env:PATH
$bashToolsDir = $pwd -replace "\\", "/"
# Build ICU
cd icu/source
echo "
./runConfigureICU MinGW --prefix=$bashToolsDir
make && make install
" | & bash
$env:PATH=$env:SAVED_PATH
Build Boost
Boost doesn't search for ICU static libraries, so for now we only use the dynamic libraries.
- Find and replace in libs/{locale,regex}/build/Jamfile.v2: icui18n -> icuin, icudata -> icudt
- Add
-sICU_PATH="<path to icu>"
when building Boost
This should be retired in favor of using https://github.com/puppetlabs/cfacter/blob/master/contrib/cfacter.ps1
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The next step is moving this to a CMake super-project. This script isn't idempotent.