From 530307ed47ad14ff944e7366340e0b860ff04b64 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Tue, 5 Feb 2019 22:43:30 +0530 Subject: [PATCH] New subproject win-nasm to provide nasm on Windows This is needed for building openh264 as a subproject. Currently it's downloaded unconditionally since the download is very small. --- meson.build | 1 + subprojects/win-nasm/.gitignore | 2 + subprojects/win-nasm/download-binary.py | 51 +++++++++++++++++++++++++ subprojects/win-nasm/meson.build | 20 ++++++++++ 4 files changed, 74 insertions(+) create mode 100644 subprojects/win-nasm/.gitignore create mode 100644 subprojects/win-nasm/download-binary.py create mode 100644 subprojects/win-nasm/meson.build diff --git a/meson.build b/meson.build index e5a4d16eac..8131d45522 100644 --- a/meson.build +++ b/meson.build @@ -57,6 +57,7 @@ os.symlink(os.path.join('@1@', 'subprojects', '@0@'), if build_system == 'windows' subproject('win-flex-bison-binaries') + subproject('win-nasm') endif subproject('orc', required: get_option('orc')) diff --git a/subprojects/win-nasm/.gitignore b/subprojects/win-nasm/.gitignore new file mode 100644 index 0000000000..12f2372377 --- /dev/null +++ b/subprojects/win-nasm/.gitignore @@ -0,0 +1,2 @@ +nasm-*/ +nasm-*.zip diff --git a/subprojects/win-nasm/download-binary.py b/subprojects/win-nasm/download-binary.py new file mode 100644 index 0000000000..26ad64ba1e --- /dev/null +++ b/subprojects/win-nasm/download-binary.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 + +import os +import sys +import ssl +import zipfile +import hashlib +import urllib.request + +# Disable certificate checking because it always fails on Windows +# We verify the checksum anyway. +ctx = ssl.create_default_context() +ctx.check_hostname = False +ctx.verify_mode = ssl.CERT_NONE + +base_url = 'https://www.nasm.us/pub/nasm/releasebuilds/{0}/{1}/nasm-{0}-{1}.zip' +arch = 'win64' if sys.argv[2] == 'x86_64' else 'win32' +url = base_url.format(sys.argv[1], arch) +zip_sha256 = sys.argv[3] +source_dir = os.path.join(os.environ['MESON_SOURCE_ROOT'], os.environ['MESON_SUBDIR']) +dest = os.path.basename(url) +dest_path = os.path.join(source_dir, dest) + +def get_sha256(zipf): + hasher = hashlib.sha256() + with open(zipf, 'rb') as f: + hasher.update(f.read()) + return hasher.hexdigest() + +if os.path.isfile(dest_path): + found_sha256 = get_sha256(dest_path) + if found_sha256 == zip_sha256: + print('{} already downloaded'.format(dest)) + sys.exit(0) + else: + print('{} checksum mismatch, redownloading'.format(dest)) + +print('Downloading {} to {}'.format(url, dest)) +with open(dest_path, 'wb') as d: + f = urllib.request.urlopen(url, context=ctx) + d.write(f.read()) + +found_sha256 = get_sha256(dest_path) +if found_sha256 != zip_sha256: + print('SHA256 of downloaded file {} was {} instead of {}' + ''.format(dest, found_sha256, zip_sha256)) + sys.exit(1) + +print('Extracting {}'.format(dest)) +zf = zipfile.ZipFile(dest_path, "r") +zf.extractall(path=source_dir) diff --git a/subprojects/win-nasm/meson.build b/subprojects/win-nasm/meson.build new file mode 100644 index 0000000000..d7775f56fb --- /dev/null +++ b/subprojects/win-nasm/meson.build @@ -0,0 +1,20 @@ +project('win-nasm', version : '2.14.02') + +py3 = import('python3').find_python() + +message('Downloading and extracting nasm binaries for Windows...') + +arch = host_machine.cpu_family() +if arch == 'x86_64' + zip_hash = '18918ac906e29417b936466e7a2517068206c8db8c04b9762a5befa18bfea5f0' +else + zip_hash = '250f9b5eeb2111e8c7b494a977490985b8604fe7518a6f5041cde37cc727a067' +endif + +ret = run_command(py3, files('download-binary.py'), meson.project_version(), arch, zip_hash) +if ret.returncode() != 0 + message(ret.stdout()) + error(ret.stderr()) +endif + +meson.override_find_program('nasm', find_program(join_paths('nasm-@0@'.format(meson.project_version()), 'nasm')))