libuv-build/makefile.shade

265 строки
14 KiB
Plaintext

var PRODUCT_VERSION = '1.10.0'
var AUTHORS='Microsoft Open Technologies, Inc.'
use-standard-lifecycle
k-standard-goals
var Configuration2 = '${E("Configuration")}'
var ROOT = '${Directory.GetCurrentDirectory()}'
var BUILD_DIR2 = '${Path.Combine(ROOT, "artifacts", "build")}'
var PROGRAM_FILES_X86 = '${Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86)}'
var MSBUILD = '${Path.Combine(PROGRAM_FILES_X86, "MSBuild", "14.0", "Bin", "MSBuild.exe")}'
var CLANG = '${SearchForClang()}'
var FULL_VERSION = '${PRODUCT_VERSION + "-" + E("DOTNET_BUILD_VERSION")}'
#repo-initialize target='initialize'
git gitCommand="submodule update --init"
#native-compile
#build-compile target='compile'
#build-windows .ensure-msbuild target='build-compile' if='CanBuildForWindows'
@{
Exec(MSBUILD, Path.Combine(ROOT, "src\\libuv\\libuv.vcxproj") + " /p:Platform=Win32 /p:Configuration=" + Configuration2);
Exec(MSBUILD, Path.Combine(ROOT, "src\\libuv\\libuv.vcxproj") + " /p:Platform=x64 /p:Configuration=" + Configuration2);
Exec(MSBUILD, Path.Combine(ROOT, "src\\libuv\\libuv.vcxproj") + " /p:Platform=ARM /p:Configuration=" + Configuration2);
}
#copy-symbols target='build-compile' if='CanBuildForWindows'
copy sourceDir='${Path.Combine(ROOT, "src\\libuv\\bin\\Win32", Configuration2)}' outputDir='${Path.Combine(BUILD_DIR2, "symbols\\Win32", Configuration2)}' include='*.pdb' overwrite='${true}'
copy sourceDir='${Path.Combine(ROOT, "src\\libuv\\bin\\x64", Configuration2)}' outputDir='${Path.Combine(BUILD_DIR2, "symbols\\x64", Configuration2)}' include='*.pdb' overwrite='${true}'
copy sourceDir='${Path.Combine(ROOT, "src\\libuv\\bin\\ARM", Configuration2)}' outputDir='${Path.Combine(BUILD_DIR2, "symbols\\ARM", Configuration2)}' include='*.pdb' overwrite='${true}'
#ensure-msbuild
@{
if (!File.Exists(MSBUILD))
{
Log.Warn("msbuild version 14 not found. Please ensure you have the VS 2015 C++ SDK installed.");
Environment.Exit(1);
}
}
#nuget-pack target='package' if='CanBuildForWindows'
copy sourceDir='${Path.Combine(ROOT, "src\\libuv\\bin\\Win32", Configuration2)}' outputDir='${Path.Combine(BUILD_DIR2, "package-src-win\\contents\\runtimes\\win-x86\\native")}' include='*.dll' overwrite='${true}'
copy sourceDir='${Path.Combine(ROOT, "src\\libuv\\bin\\x64", Configuration2)}' outputDir='${Path.Combine(BUILD_DIR2, "package-src-win\\contents\\runtimes\\win-x64\\native")}' include='*.dll' overwrite='${true}'
copy sourceDir='${Path.Combine(ROOT, "src\\libuv\\bin\\ARM", Configuration2)}' outputDir='${Path.Combine(BUILD_DIR2, "package-src-win\\contents\\runtimes\\win-arm\\native")}' include='*.dll' overwrite='${true}'
copy sourceDir='${Path.Combine(ROOT, "build")}' outputDir='${Path.Combine(BUILD_DIR2, "package-src-win\\contents")}' include='*' exclude='*.nuspec' overwrite='${true}'
copy sourceDir='${Path.Combine(ROOT, "build")}' outputDir='${Path.Combine(BUILD_DIR2, "package-src-win")}' include='Microsoft.AspNetCore.Internal.libuv-Windows.nuspec' overwrite='${true}'
nuget-pack packageVersion='${FULL_VERSION}' outputDir='${BUILD_DIR2}' extra='-NoPackageAnalysis' nugetPath='.build/nuget.exe' nuspecFile='${Path.Combine(BUILD_DIR2, "package-src-win\\Microsoft.AspNetCore.Internal.libuv-Windows.nuspec")}'
#build-darwin .ensure-clang target='build-compile' if='CanBuildForDarwin'
@{
var libuvRoot = Path.Combine(ROOT, "submodules/libuv");
var sourceFiles = GetCommonSourceFiles(libuvRoot);
sourceFiles.Add(Path.Combine(libuvRoot, "src/unix/darwin.c"));
sourceFiles.Add(Path.Combine(libuvRoot, "src/unix/darwin-proctitle.c"));
sourceFiles.Add(Path.Combine(libuvRoot, "src/unix/kqueue.c"));
sourceFiles.Add(Path.Combine(libuvRoot, "src/unix/fsevents.c"));
sourceFiles.Add(Path.Combine(libuvRoot, "src/unix/pthread-barrier.c"));
var outputDir = Path.Combine(ROOT, "src/libuv/bin/darwin");
var outputPath = Path.Combine(outputDir, "libuv.dylib");
Directory.CreateDirectory(outputDir);
var sources = string.Join(" ", sourceFiles);
Exec(CLANG,
string.Format("{0} -lm -pthread -fPIC -shared -o {1} -I{2}/include -I{2}/src -Wall -Wextra -Wno-unused-parameter -g --std=gnu89 -pedantic -D_DARWIN_USE_64_BIT_INODE=1 -D_DARWIN_UNLIMITED_SELECT=1 -D_BUILDING_UV_SHARED=1 -arch i386 -arch x86_64",
sources, outputPath, libuvRoot));
}
#nuget-pack target='package' if='CanBuildForDarwin'
copy sourceDir='${Path.Combine(ROOT, "src/libuv/bin/darwin")}' outputDir='${Path.Combine(BUILD_DIR2, "package-src-darwin/runtimes/osx/native")}' include='*.dylib' overwrite='${true}'
copy sourceDir='${Path.Combine(ROOT, "build")}' outputDir='${Path.Combine(BUILD_DIR2, "package-src-darwin")}' include='*' overwrite='${true}'
nuget-pack packageVersion='${FULL_VERSION}' outputDir='${BUILD_DIR2}' extra='-NoPackageAnalysis -Properties TargetOS=Darwin' nugetPath='.build/nuget.exe' nuspecFile='${Path.Combine(BUILD_DIR2, "package-src-darwin/libuv.nuspec")}'
#build-linux .ensure-clang target='build-compile' if='CanBuildForLinux'
@{
var libuvRoot = Path.Combine(ROOT, "submodules/libuv");
var sourceFiles = GetCommonSourceFiles(libuvRoot);
sourceFiles.Add(Path.Combine(libuvRoot, "src/unix/linux-core.c"));
sourceFiles.Add(Path.Combine(libuvRoot, "src/unix/linux-inotify.c"));
sourceFiles.Add(Path.Combine(libuvRoot, "src/unix/linux-syscalls.c"));
var sources = string.Join(" ", sourceFiles);
var outputDir = Path.Combine(ROOT, "src/libuv/bin/linux");
var outputPath = Path.Combine(outputDir, "libuv.so");
Directory.CreateDirectory(outputDir);
var armOutputDir = Path.Combine(ROOT, "src/libuv/bin/linux-arm");
var armOutputPath = Path.Combine(armOutputDir, "libuv.so");
Directory.CreateDirectory(armOutputDir);
var arm64OutputDir = Path.Combine(ROOT, "src/libuv/bin/linux-arm64");
var arm64OutputPath = Path.Combine(arm64OutputDir, "libuv.so");
Directory.CreateDirectory(arm64OutputDir);
var armelOutputDir = Path.Combine(ROOT, "src/libuv/bin/linux-armel");
var armelOutputPath = Path.Combine(armelOutputDir, "libuv.so");
Directory.CreateDirectory(armelOutputDir);
var flags = string.Format("-lm -pthread -ldl -lrt -fPIC -shared -I{0}/include -I{0}/src -Wall -Wextra -Wno-unused-parameter -Wstrict-aliasing -g --std=gnu89 -pedantic -D_GNU_SOURCE -D_BUILDING_UV_SHARED=1", libuvRoot);
Exec(CLANG,
string.Format("{0} -o {1} {2}", sources, outputPath, flags));
// The "arm" target should align with what CoreFX is doing, see
// https://github.com/dotnet/corefx/blob/master/cross/arm/toolchain.cmake#L9
Exec(CLANG,
string.Format("{0} -target armv7-linux-gnueabihf -mfpu=vfpv3 -B/usr/arm-linux-gnueabihf/bin/ -B/usr/arm-linux-gnueabihf/lib/ -isystem /usr/arm-linux-gnueabihf/include -o {1} {2}", sources, armOutputPath, flags));
// The "arm64" target should align with what CoreFX is doing, see
// https://github.com/dotnet/corefx/blob/master/cross/arm64/toolchain.cmake
Exec(CLANG,
string.Format("{0} -target aarch64-linux-gnu -B/usr/aarch64-linux-gnu/bin/ -B/usr/aarch64-linux-gnu/lib/ -isystem /usr/aarch64-linux-gnu/include -o {1} {2}", sources, arm64OutputPath, flags));
// The "armel" target should align with what CoreFX is doing, see
// https://github.com/dotnet/corefx/blob/master/cross/armel/toolchain.cmake#L9
Exec(CLANG,
string.Format("{0} -target armv7-linux-gnueabi -mfpu=vfpv3 -mfloat-abi=softfp -B/usr/arm-linux-gnueabi/bin/ -B/usr/arm-linux-gnueabi/lib/ -isystem /usr/arm-linux-gnueabi/include -o {1} {2}", sources, armelOutputPath, flags));
}
#nuget-pack target='package' if='CanBuildForDarwin'
copy sourceDir='${Path.Combine(ROOT, "src/libuv/bin/darwin")}' outputDir='${Path.Combine(BUILD_DIR2, "package-src-darwin/contents/runtimes/osx/native")}' include='*.dylib' overwrite='${true}'
copy sourceDir='${Path.Combine(ROOT, "build")}' outputDir='${Path.Combine(BUILD_DIR2, "package-src-darwin/contents")}' include='*' exclude='*.nuspec' overwrite='${true}'
copy sourceDir='${Path.Combine(ROOT, "build")}' outputDir='${Path.Combine(BUILD_DIR2, "package-src-darwin")}' include='Microsoft.AspNetCore.Internal.libuv-Darwin.nuspec' overwrite='${true}'
nuget-pack packageVersion='${FULL_VERSION}' outputDir='${BUILD_DIR2}' extra='-NoPackageAnalysis' nugetPath='.build/nuget.exe' nuspecFile='${Path.Combine(BUILD_DIR2, "package-src-darwin/Microsoft.AspNetCore.Internal.libuv-Darwin.nuspec")}'
#nuget-pack target='package' if='CanBuildForLinux'
copy sourceDir='${Path.Combine(ROOT, "src/libuv/bin/linux-arm")}' outputDir='${Path.Combine(BUILD_DIR2, "package-src-linux/contents/runtimes/linux-arm/native")}' include='*.so' overwrite='${true}'
copy sourceDir='${Path.Combine(ROOT, "src/libuv/bin/linux-arm64")}' outputDir='${Path.Combine(BUILD_DIR2, "package-src-linux/contents/runtimes/linux-arm64/native")}' include='*.so' overwrite='${true}'
copy sourceDir='${Path.Combine(ROOT, "src/libuv/bin/linux-armel")}' outputDir='${Path.Combine(BUILD_DIR2, "package-src-linux/contents/runtimes/linux-armel/native")}' include='*.so' overwrite='${true}'
copy sourceDir='${Path.Combine(ROOT, "src/libuv/bin/linux")}' outputDir='${Path.Combine(BUILD_DIR2, "package-src-linux/contents/runtimes/linux-x64/native")}' include='*.so' overwrite='${true}'
copy sourceDir='${Path.Combine(ROOT, "build")}' outputDir='${Path.Combine(BUILD_DIR2, "package-src-linux/contents")}' include='*' exclude='*.nuspec' overwrite='${true}'
copy sourceDir='${Path.Combine(ROOT, "build")}' outputDir='${Path.Combine(BUILD_DIR2, "package-src-linux")}' include='Microsoft.AspNetCore.Internal.libuv-Linux.nuspec' overwrite='${true}'
nuget-pack packageVersion='${FULL_VERSION}' outputDir='${BUILD_DIR2}' extra='-NoPackageAnalysis' nugetPath='.build/nuget.exe' nuspecFile='${Path.Combine(BUILD_DIR2, "package-src-linux/Microsoft.AspNetCore.Internal.libuv-Linux.nuspec")}'
#ensure-clang
@{
if (CLANG == null || !File.Exists(CLANG))
{
Log.Warn("clang not found. Please ensure you have clang on the path or set CXX to a path to clang.");
Environment.Exit(1);
}
}
functions @{
bool CanBuildForWindows
{
get
{
var p = (int)Environment.OSVersion.Platform;
return (p != 4) && (p != 6) && (p != 128);
}
}
bool CanBuildForDarwin
{
get
{
return string.Equals(Uname(), "Darwin");
}
}
bool CanBuildForLinux
{
get
{
return string.Equals(Uname(), "Linux");
}
}
public string SearchForClang()
{
var CXX = Environment.GetEnvironmentVariable("CXX");
if (!string.IsNullOrEmpty(CXX))
{
return CXX;
}
foreach(var dir in Environment.GetEnvironmentVariable("PATH").Split(Path.PathSeparator))
{
if (File.Exists(Path.Combine(dir, "clang")))
{
return Path.Combine(dir, "clang");
}
else if (File.Exists(Path.Combine(dir, "clang-3.5")))
{
return Path.Combine(dir, "clang-3.5");
}
}
return null;
}
public string Uname()
{
try
{
string uname;
ExecuteAndRedirectOutput("uname", "", out uname);
return string.IsNullOrEmpty(uname) ? null : uname.Trim();
}
catch
{
return null;
}
}
int ExecuteAndRedirectOutput(string command, string argument, out string content)
{
var procStartInfo = new ProcessStartInfo
{
FileName = command,
Arguments = argument,
WorkingDirectory = Directory.GetCurrentDirectory(),
UseShellExecute = false
};
procStartInfo.RedirectStandardOutput = true;
var process = Process.Start(procStartInfo);
content = process.StandardOutput.ReadToEnd();
process.WaitForExit();
return process.ExitCode;
}
public List<string> GetCommonSourceFiles(string libuvRoot)
{
return new List<string>
{
Path.Combine(libuvRoot, "src/fs-poll.c"),
Path.Combine(libuvRoot, "src/inet.c"),
Path.Combine(libuvRoot, "src/threadpool.c"),
Path.Combine(libuvRoot, "src/uv-common.c"),
Path.Combine(libuvRoot, "src/version.c"),
Path.Combine(libuvRoot, "src/unix/async.c"),
Path.Combine(libuvRoot, "src/unix/core.c"),
Path.Combine(libuvRoot, "src/unix/dl.c"),
Path.Combine(libuvRoot, "src/unix/fs.c"),
Path.Combine(libuvRoot, "src/unix/getaddrinfo.c"),
Path.Combine(libuvRoot, "src/unix/getnameinfo.c"),
Path.Combine(libuvRoot, "src/unix/loop.c"),
Path.Combine(libuvRoot, "src/unix/loop-watcher.c"),
Path.Combine(libuvRoot, "src/unix/pipe.c"),
Path.Combine(libuvRoot, "src/unix/poll.c"),
Path.Combine(libuvRoot, "src/unix/process.c"),
Path.Combine(libuvRoot, "src/unix/signal.c"),
Path.Combine(libuvRoot, "src/unix/stream.c"),
Path.Combine(libuvRoot, "src/unix/tcp.c"),
Path.Combine(libuvRoot, "src/unix/thread.c"),
Path.Combine(libuvRoot, "src/unix/timer.c"),
Path.Combine(libuvRoot, "src/unix/tty.c"),
Path.Combine(libuvRoot, "src/unix/udp.c"),
Path.Combine(libuvRoot, "src/unix/proctitle.c"),
};
}
}