Configurations/60-otok.conf 6043 bytes · raw
## SPDX-License-Identifier: Apache-2.0
## An extension of OpenSSL's Configurations, after the settings of its targets in 10-main.conf and 15-ios.conf
## (Copyright The OpenSSL Project Authors), under OpenSSL's license, the Apache License 2.0.
## Configure targets of the otok recipe: one per OS and architecture of the Apple slices, and one per
## architecture and environment of the Windows target (clang-cl across from Linux, MSVC on Windows). otok's
## toolchain brings the compiler and its flags (CC, CFLAGS with -target and -isysroot, or --target for clang-cl),
## so these targets carry no compiler, SDK or deployment version, unlike the -xcrun targets of 15-ios.conf.
my %targets = (
# Windows, cross-built with clang-cl: the settings of the VC- targets, with the Unix makefile template
# and GNU make instead of nmake. platform/Windows/otok.pm keeps the MSVC names of the libraries
# (libcrypto.lib, libcrypto-<version>-x64.dll); clang-cl links the DLLs, passing lld-link's options
# behind /clang:-Wl, and llvm-ar fills COFF archives. The names of these targets are not VC-: the
# version resources of the DLLs, which want rc's options, stay out.
"otok-windows" => {
template => 1,
inherit_from => [ "VC-noCE-common" ],
build_file => "Makefile",
build_scheme => [ "unified", "unix" ],
perl_platform => 'Windows::otok',
# otok's flags choose the optimization and the runtime (/MD, /MDd), also in static libraries
cflags => "/GF /Gy",
lib_cflags => "",
dso_cflags => "",
bin_cflags => "",
bin_lflags => "",
LDFLAGS => "",
ARFLAGS => "--format=coff rc",
RANLIB => "",
shared_target => "windows-shared",
shared_ldflag => "/LD",
shared_impflag => "/clang:-Wl,/implib:",
shared_defflag => "/clang:-Wl,/def:",
},
# The Windows target keeps one include/ for its architectures, so both write the same configuration.h:
# no sys_id (VC-WIN64A's OPENSSL_SYS_WIN64A, which no source tests) and no RC4_CHAR (a speed choice for
# RC4 that VC-CLANG-WIN64-CLANGASM-ARM makes).
"otok-windows-x86_64" => {
inherit_from => [ "otok-windows" ],
bn_ops => "SIXTY_FOUR_BIT",
asm_arch => 'x86_64',
# GNU syntax with Win64's calling convention and unwind tables, which clang-cl assembles
perlasm_scheme => "mingw64",
multilib => "-x64",
},
# as VC-CLANG-WIN64-CLANGASM-ARM
"otok-windows-arm64" => {
inherit_from => [ "otok-windows" ],
defines => add("_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE", "OPENSSL_SYS_WIN_CORE"),
bn_ops => "SIXTY_FOUR_BIT",
asm_arch => 'aarch64',
perlasm_scheme => "win64",
multilib => "-arm64",
},
"otok-apple" => {
template => 1,
inherit_from => [ "darwin-common" ],
disable => [ "shared", "async" ],
},
# as darwin64-arm64; ios64-xcrun adds RC4_CHAR, a speed choice for RC4. Where the architectures of
# one platform differ in bn_ops (watchOS: arm64_32 beside arm64), otok keeps configuration.h per
# architecture.
"otok-apple-arm64" => {
template => 1,
inherit_from => [ "otok-apple" ],
lib_cppflags => add("-DL_ENDIAN"),
bn_ops => "SIXTY_FOUR_BIT_LONG",
asm_arch => 'aarch64',
perlasm_scheme => "ios64",
},
"otok-apple-x86_64" => {
template => 1,
inherit_from => [ "otok-apple" ],
lib_cppflags => add("-DL_ENDIAN"),
bn_ops => "SIXTY_FOUR_BIT_LONG",
asm_arch => 'x86_64',
perlasm_scheme => "macosx",
},
# Apple Watch: 32-bit pointers on a 64-bit CPU, no assembler
"otok-apple-arm64_32" => {
template => 1,
inherit_from => [ "otok-apple" ],
lib_cppflags => add("-DL_ENDIAN"),
bn_ops => "BN_LLONG RC4_CHAR",
},
);
# sys_id tells OpenSSL the OS; macOS and Mac Catalyst keep darwin-common's MACOSX
my @systems = ([ "macos", undef, [] ], [ "ios", "iOS", [] ], [ "tvos", "tvOS", [ "engine" ] ],
[ "watchos", "watchOS", [ "engine" ] ], [ "xros", "visionOS", [] ]);
foreach my $system (@systems) {
my ($os, $sys_id, $disable) = @$system;
foreach my $arch ("arm64", "x86_64", "arm64_32") {
$targets{"otok-$os-$arch"} = {
inherit_from => [ "otok-apple-$arch" ],
(defined $sys_id ? (sys_id => $sys_id) : ()),
(@$disable ? (disable => add(@$disable)) : ()),
};
}
}
# Windows with MSVC on Windows: the VC- targets with nmake and their makefile, whose compiler flags are otok's (CFLAGS on
# Configure's command line: the optimization and the runtime, /MD or /MDd, also in static libraries, which the VC-
# targets build with /MT /Zl). As for clang-cl, no sys_id and no RC4_CHAR, so that both architectures write one
# configuration.h; no uplink, the applink of OpenSSL's own programs, which these builds do not make.
my %msvc = (
cflags => "/GF /Gy",
lib_cflags => "",
dso_cflags => "",
bin_cflags => "",
sys_id => undef,
uplink_arch => undef,
);
# VC-WIN64A: x86_64 with the assembler of NASM
$targets{"otok-windows-msvc-x86_64"} = {
inherit_from => [ "VC-WIN64A" ],
%msvc,
};
# VC-WIN64-ARM without onecore.lib (kernel32 of the desktop instead) and without assembler: MSVC's armasm64 takes none of
# OpenSSL's
$targets{"otok-windows-msvc-arm64"} = {
inherit_from => [ "VC-WIN64-common" ],
%msvc,
defines => add("_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE", "OPENSSL_SYS_WIN_CORE"),
multilib => "-arm64",
disable => [ "asm" ],
};
%targets;
build.lua 6035 bytes · raw
-- Configure with a target of Configurations/60-otok.conf: in windows/msvc otok-windows-msvc-<arch> and its libraries with
-- nmake; in linux/clang-cl otok-windows-<arch> and its libraries with GNU make. Then the public headers of the source and
-- the build copied as install_dev copies them. The directories built into libcrypto are those of OpenSSL's own Windows
-- builds, not the prefix of the slice.
-- MSVC: the VC- targets, with NASM for x86_64, which Configure looks for in PATH; nmake takes no MAKEFLAGS of make (the
-- jobserver's)
local function msvc(slice, options, shared)
local path = slice.toolchain.env.PATH
if slice.toolchains.nasm then path = slice.toolchains.nasm:match("^(.*)[/\\][^/\\]*$") .. ";" .. path end
local env = { PATH = path, MAKEFLAGS = false, MFLAGS = false }
local configure = { slice.toolchains.perl, slice.source .. "/Configure", "otok-windows-msvc-" .. slice.arch,
shared and "shared" or "no-shared", "no-tests", "no-makedepend",
"--prefix=C:\\Program Files\\OpenSSL", "--openssldir=C:\\Program Files\\Common Files\\SSL",
"CFLAGS=/nologo /W3 /wd4090 " .. table.concat(slice.toolchain.cflags, " ") }
if options["no-deprecated"] then table.insert(configure, "no-deprecated") end
-- without --debug Configure defines NDEBUG; with it DEBUG and _DEBUG, as its VC- targets do (the flags stay otok's)
if slice.configuration == "debug" then table.insert(configure, "--debug") end
otok.run(configure, { cwd = slice.build, env = env })
otok.run({ "nmake", "-nologo", "build_libs" }, { cwd = slice.build, env = env })
end
-- clang-cl across from Linux: the Unix makefile template, platform/Windows/otok.pm for the MSVC names of the libraries
local function clang_cl(slice, options, shared)
local t = slice.toolchain
otok.copy(slice.recipe .. "/Configurations/platform/Windows/otok.pm", slice.source .. "/Configurations/platform/Windows/otok.pm")
-- llvm-ar beside llvm-lib: the makefile adds the objects to an archive in groups, which llvm-lib cannot
local ar = (t.ar:gsub("llvm%-lib([^/]*)$", "llvm-ar%1"))
local configure = { slice.toolchains.perl, slice.source .. "/Configure", "otok-windows-" .. slice.arch,
shared and "shared" or "no-shared", "no-tests", "no-makedepend", "--prefix=" .. slice.prefix, "--libdir=lib",
"CC=" .. t.cc, "CFLAGS=" .. table.concat(t.cflags, " "), "AR=" .. ar }
if options["no-deprecated"] then table.insert(configure, "no-deprecated") end
if slice.configuration == "debug" then table.insert(configure, "--debug") end
otok.run(configure, { cwd = slice.build })
local makefile = otok.read(slice.build .. "/Makefile")
if shared then
-- libssl links libcrypto as the Unix template links a shared library, -L. -lcrypto, which clang-cl does
-- not know: its import library instead
local found
makefile = makefile:gsub("(%s)%-L%.(%s)", "%1%2")
makefile, found = makefile:gsub("(%s)%-lcrypto(%s)", "%1libcrypto.lib%2")
if found == 0 then error("the Makefile does not link libssl with -lcrypto") end
end
-- the compiler OpenSSL_version(OPENSSL_CFLAGS) tells: clang-cl and the flags without the paths of this machine
-- and of the work directory, which would make every build of the slice differ
local flags = {}
for _, flag in ipairs(t.cflags) do
if not flag:find("prefix-map", 1, true) then table.insert(flags, flag) end
end
local count
makefile, count = makefile:gsub('"%$%(CC%) %$%(LIB_CFLAGS%) %$%(CPPFLAGS_Q%)"', function()
return '"clang-cl ' .. table.concat(flags, " ") .. ' $(CPPFLAGS_Q)"'
end)
if count == 0 then error("the Makefile has no rule for crypto/buildinf.h of the expected form") end
otok.write(slice.build .. "/Makefile", makefile)
local engines = makefile:match("\nENGINESDIR=%$%(libdir%)/(engines%-[^\n]*)\n") or "engines"
otok.make{ "build_libs", "OPENSSLDIR=C:/Program Files/Common Files/SSL", "ENGINESDIR=C:/Program Files/OpenSSL/lib/" .. engines,
"MODULESDIR=C:/Program Files/OpenSSL/lib/ossl-modules", cwd = slice.build }
end
function build(slice, options, deps)
otok.copy(slice.recipe .. "/Configurations/60-otok.conf", slice.source .. "/Configurations/60-otok.conf")
local shared = slice.linkage == "dynamic"
local with_msvc = slice.environment == "windows/msvc"
if with_msvc then msvc(slice, options, shared) else clang_cl(slice, options, shared) end
for _, dir in ipairs{ slice.source, slice.build } do
for _, header in ipairs(otok.glob("include/openssl/*.h", dir)) do
otok.copy(header, slice.prefix .. "/include/openssl/" .. header:match("[^/]*$"))
end
end
if with_msvc then
-- arm64 is built without assembler (no-asm, as VC-WIN64-ARM), which configuration.h says with OPENSSL_NO_ASM; only
-- OpenSSL's own sources test it, and the Windows target keeps one include/ for its architectures, so the copy for
-- consumers leaves it out
local configuration = slice.prefix .. "/include/openssl/configuration.h"
local text, count = otok.read(configuration):gsub("# ifndef OPENSSL_NO_ASM\r?\n# define OPENSSL_NO_ASM\r?\n# endif\r?\n", "")
if slice.arch == "arm64" and count ~= 1 then error("configuration.h does not define OPENSSL_NO_ASM as expected") end
otok.write(configuration, text)
end
local libraries = {}
for _, name in ipairs{ "ssl", "crypto" } do
local lib = slice.prefix .. "/lib/lib" .. name .. ".lib"
otok.copy(slice.build .. "/lib" .. name .. ".lib", lib)
libraries[name] = lib
if shared then
local dll = otok.glob("lib" .. name .. "-*.dll", slice.build)[1]
local runtime = slice.prefix .. "/bin/" .. dll:match("[^/]*$")
otok.copy(dll, runtime)
libraries[name] = { link = lib, runtime = runtime }
end
end
return { libraries = libraries, headers = slice.prefix .. "/include" }
end