diff --git a/CHANGELOG.md b/CHANGELOG.md index 97ccfc58b7..a4707f5108 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,11 @@ * `Worker`: Make DTLS fragment stay within MTU size range ([PR #1156](https://github.com/versatica/mediasoup/pull/1156), based on [PR #1143](https://github.com/versatica/mediasoup/pull/1143) by @vpnts-se). +### 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/npm-scripts.mjs b/npm-scripts.mjs index 23fc6ac535..a12f1e6a41 100644 --- a/npm-scripts.mjs +++ b/npm-scripts.mjs @@ -501,7 +501,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/package-lock.json b/package-lock.json index 454166c872..f13dec0d52 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 ccb51ffb30..1bdbec08e9 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)", 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')