From a3b13cc703b115e9e56ac49ab49d8852c43d766b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Fri, 20 Oct 2023 17:19:39 +0200 Subject: [PATCH 1/2] Fix NPM 'postinstall' task in Windows (#1187) --- npm-scripts.mjs | 4 +++- worker/build.rs | 28 +++++++++++++++++++++++----- worker/scripts/getmake.py | 15 +++++++++++++-- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/npm-scripts.mjs b/npm-scripts.mjs index 7ca9942e75..2089a6379e 100644 --- a/npm-scripts.mjs +++ b/npm-scripts.mjs @@ -445,7 +445,9 @@ function installMsysMake() pythonPath = String(res.stdout).trim(); } - executeCmd(`${pythonPath} worker\\scripts\\getmake.py`); + const dir = path.resolve('worker/out/msys'); + + executeCmd(`${pythonPath} worker\\scripts\\getmake.py --dir="${dir}"`); } function ensureDir(dir) diff --git a/worker/build.rs b/worker/build.rs index 7d2264bfaf..2caf96525b 100644 --- a/worker/build.rs +++ b/worker/build.rs @@ -16,9 +16,15 @@ fn main() { }; let out_dir = env::var("OUT_DIR").unwrap(); - // Force forward slashes on Windows too so that is plays well with our dumb `Makefile` + // Force forward slashes on Windows too so that is plays well with our dumb `Makefile`. let mediasoup_out_dir = format!("{}/out", out_dir.replace('\\', "/")); + // Store original PATH so we make `make clean-all` use it. This is because, in Windows, + // we may need to fetch `make` and we store it in out/msys and then we add out/msys/bin + // to the PATH, and that folder may contain rm.exe, so `make clean-all` would use + // that rm.exe and delete itself and make the task fail. + let original_path = env::var("PATH").unwrap(); + // Add C++ std lib #[cfg(target_os = "linux")] { @@ -78,25 +84,36 @@ fn main() { #[cfg(target_os = "windows")] { if !std::path::Path::new("worker/out/msys/bin/make.exe").exists() { - let python = if Command::new("where") - .arg("python3.exe") + let python = if let Ok(python) = env::var("PYTHON") { + python + } else if Command::new("where") + .arg("python3") .status() .expect("Failed to start") .success() { - "python3" + "python3".to_string() } else { - "python" + "python".to_string() }; + let dir = format!("{}/msys", mediasoup_out_dir.replace('\\', "/")); + if !Command::new(python) .arg("scripts\\getmake.py") + .arg("--dir") + .arg(dir.clone()) .status() .expect("Failed to start") .success() { panic!("Failed to install MSYS/make") } + + env::set_var( + "PATH", + format!("{}\\bin;{}", dir, env::var("PATH").unwrap()), + ); } env::set_var( @@ -161,6 +178,7 @@ fn main() { // Clean if !Command::new("make") .arg("clean-all") + .env("PATH", original_path) .env("MEDIASOUP_OUT_DIR", &mediasoup_out_dir) .spawn() .expect("Failed to start") diff --git a/worker/scripts/getmake.py b/worker/scripts/getmake.py index c6c0dbb9a3..50ec9ea7f1 100644 --- a/worker/scripts/getmake.py +++ b/worker/scripts/getmake.py @@ -1,10 +1,21 @@ -import io, hashlib, tarfile, urllib.request +import argparse, io, hashlib, tarfile, urllib.request + +argParser = argparse.ArgumentParser() + +argParser.add_argument( + '--dir', + type=str, + required=True, + help='absolute path of the directoy in which fetched content will be placed' +) + +args = argParser.parse_args() def get(url, digest): data = urllib.request.urlopen(url).read() assert hashlib.sha256(data).hexdigest() == digest tar = tarfile.open(fileobj=io.BytesIO(data)) - tar.extractall('worker/out/msys') + tar.extractall(args.dir) tar.close() get('https://sourceforge.net/projects/mingw/files/MSYS/Base/msys-core/msys-1.0.19-1/msysCORE-1.0.19-1-msys-1.0.19-bin.tar.xz/download', '8c4157d739a460f85563bc4451e9f1bbd42b13c4f63770d43b9f45a781f07858') From f8bc8ea7009122ceec025d99a5cdf4de984da0b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Fri, 20 Oct 2023 17:24:55 +0200 Subject: [PATCH 2/2] 3.12.15 --- CHANGELOG.md | 5 +++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e89ef10020..fa51a3c085 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Changelog +### 3.12.15 + +* Fix NPM "postinstall" task in Windows ([PR #1187](https://github.com/versatica/mediasoup/pull/1187)). + + ### 3.12.14 * CI: Use Node.js version 20 ([PR #1177](https://github.com/versatica/mediasoup/pull/1177)). diff --git a/package-lock.json b/package-lock.json index a7a1ab5989..a7b34424ac 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "mediasoup", - "version": "3.12.14", + "version": "3.12.15", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "mediasoup", - "version": "3.12.14", + "version": "3.12.15", "hasInstallScript": true, "license": "ISC", "dependencies": { diff --git a/package.json b/package.json index 17b6b4c303..364a425fd8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mediasoup", - "version": "3.12.14", + "version": "3.12.15", "description": "Cutting Edge WebRTC Video Conferencing", "contributors": [ "IƱaki Baz Castillo (https://inakibaz.me)",