From aad650987931f2f5ad0288b662b0154e98e2603d Mon Sep 17 00:00:00 2001 From: Bugra Date: Sat, 21 Dec 2024 22:30:27 +0300 Subject: [PATCH] fix: windows build --- .github/workflows/build-windows.yml | 26 +++++++ .github/workflows/deploy-website.yml | 1 - packages/cpp.js/src/actions/getAllBridges.js | 4 +- packages/cpp.js/src/actions/getDependLibs.js | 6 +- packages/cpp.js/src/bin.js | 8 +- packages/cpp.js/src/state/loadConfig.js | 2 +- packages/cpp.js/src/utils/findFiles.js | 5 ++ packages/cpp.js/src/utils/getAbsolutePath.js | 2 +- .../cpp.js/src/utils/getCMakeListsFilePath.js | 6 +- .../cppjs-core-docker/DraftWindowsDockerfile | 74 +++++++++++++++++++ 10 files changed, 119 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/build-windows.yml create mode 100644 packages/cpp.js/src/utils/findFiles.js create mode 100644 packages/cppjs-core-docker/DraftWindowsDockerfile diff --git a/.github/workflows/build-windows.yml b/.github/workflows/build-windows.yml new file mode 100644 index 00000000..8ebfe3a1 --- /dev/null +++ b/.github/workflows/build-windows.yml @@ -0,0 +1,26 @@ +name: build windows +on: + push: + branches: + - main + paths: + - packages/** + - .github/workflows/build-windows.yml + pull_request: + branches: + - main + paths: + - packages/cpp.js/** + - packages/cppjs-plugin-*/** + - .github/workflows/build-windows.yml + +permissions: {} +jobs: + build: + runs-on: Windows + steps: + - uses: actions/checkout@v4 + - name: Install dependencies + run: pnpm install + - name: Build for windows + run: pnpm run ci:windows:build diff --git a/.github/workflows/deploy-website.yml b/.github/workflows/deploy-website.yml index 64fa5ed1..d74298d9 100644 --- a/.github/workflows/deploy-website.yml +++ b/.github/workflows/deploy-website.yml @@ -7,7 +7,6 @@ on: paths: - website/** - .github/workflows/deploy-website.yml - pull_request: jobs: deploy: diff --git a/packages/cpp.js/src/actions/getAllBridges.js b/packages/cpp.js/src/actions/getAllBridges.js index fa481cf8..eb043f13 100644 --- a/packages/cpp.js/src/actions/getAllBridges.js +++ b/packages/cpp.js/src/actions/getAllBridges.js @@ -1,8 +1,8 @@ -import { glob } from 'glob'; +import findFiles from '../utils/findFiles.js'; import state from '../state/index.js'; export default function getAllBridges() { return [ - ...glob.sync(`${state.config.paths.build}/bridge/*.i.cpp`, { absolute: true }), + ...findFiles(`${state.config.paths.build}/bridge/*.i.cpp`), ]; } diff --git a/packages/cpp.js/src/actions/getDependLibs.js b/packages/cpp.js/src/actions/getDependLibs.js index 7bb3bab5..3e00ae3f 100644 --- a/packages/cpp.js/src/actions/getDependLibs.js +++ b/packages/cpp.js/src/actions/getDependLibs.js @@ -1,15 +1,15 @@ -import { glob } from 'glob'; +import findFiles from '../utils/findFiles.js'; import state from '../state/index.js'; export default function getDependLibs() { let dependLibs = [ - ...glob.sync(`${state.config.paths.build}/Source-Release/Emscripten-x86_64/dependencies/**/*.a`, { absolute: true, cwd: state.config.paths.project }), + ...findFiles(`${state.config.paths.build}/Source-Release/Emscripten-x86_64/dependencies/**/*.a`, { cwd: state.config.paths.project }), ]; state.config.dependencyParameters.cmakeDepends.forEach((d) => { if (d.export.libName) { d.export.libName.forEach((fileName) => { if (d.platform['Emscripten-x86_64'].ignoreLibName?.includes(fileName)) return; - dependLibs.push(...glob.sync(`${d.paths.output}/prebuilt/Emscripten-x86_64/lib/lib${fileName}.a`, { absolute: true, cwd: d.paths.project })); + dependLibs.push(...findFiles(`${d.paths.output}/prebuilt/Emscripten-x86_64/lib/lib${fileName}.a`, { cwd: d.paths.project })); }); } }); diff --git a/packages/cpp.js/src/bin.js b/packages/cpp.js/src/bin.js index 51c0d6ec..6f0e18ec 100755 --- a/packages/cpp.js/src/bin.js +++ b/packages/cpp.js/src/bin.js @@ -3,7 +3,6 @@ import fs from 'node:fs'; import { execFileSync } from 'node:child_process'; import { Command, Option } from 'commander'; -import { glob } from 'glob'; import replace from 'replace'; import { state } from './index.js'; @@ -18,6 +17,7 @@ import systemKeys from './utils/systemKeys.js'; import { getDockerImage } from './utils/pullDockerImage.js'; import { getContentHash } from './utils/hash.js'; +import findFiles from './utils/findFiles.js'; const packageJSON = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url))); @@ -262,8 +262,8 @@ function buildLib(platform) { const modules = []; state.config.paths.module.forEach((modulePath) => { - modules.push(...glob.sync('**/*.i', { absolute: true, cwd: modulePath })); - modules.push(...glob.sync('*.i', { absolute: true, cwd: modulePath })); + modules.push(...findFiles('**/*.i', { cwd: modulePath })); + modules.push(...findFiles('*.i', { cwd: modulePath })); }); if (modules.length > 0) { fs.mkdirSync(`${state.config.paths.output}/prebuilt/${p}/swig`, { recursive: true }); @@ -289,7 +289,7 @@ function buildLib(platform) { async function createWasmJs() { let headers = []; state.config.paths.header.forEach((headerPath) => { - headers.push(glob.sync('**/*.h', { absolute: true, cwd: headerPath })); + headers.push(findFiles('**/*.h', { cwd: headerPath })); }); headers = headers.filter((path) => !!path.toString()).flat(); diff --git a/packages/cpp.js/src/state/loadConfig.js b/packages/cpp.js/src/state/loadConfig.js index e293477c..979e3e6e 100644 --- a/packages/cpp.js/src/state/loadConfig.js +++ b/packages/cpp.js/src/state/loadConfig.js @@ -64,7 +64,7 @@ function getFilledConfig(config, options = { isDepend: false }) { newConfig.paths.bridge = (newConfig.paths.bridge || [...newConfig.paths.native, newConfig.paths.build]) .map((p) => getPath(p)); newConfig.paths.output = getPath(newConfig.paths.output) || newConfig.paths.build; - newConfig.paths.cmake = options.isDepend ? getCMakeListsFilePath(newConfig.paths.output) : ( + newConfig.paths.cmake = options.isDepend ? getPath(getCMakeListsFilePath(newConfig.paths.output)) : ( getPath(newConfig.paths.cmake || getCMakeListsFilePath(newConfig.paths.project)) ); newConfig.paths.cmakeDir = getParentPath(newConfig.paths.cmake); diff --git a/packages/cpp.js/src/utils/findFiles.js b/packages/cpp.js/src/utils/findFiles.js new file mode 100644 index 00000000..cd98352f --- /dev/null +++ b/packages/cpp.js/src/utils/findFiles.js @@ -0,0 +1,5 @@ +import { glob } from 'glob'; + +export default function findFiles(regex, options = {}) { + return glob.sync(regex, { absolute: true, posix: true, ...options }).map(p => p.replace('//?/', '')); +} diff --git a/packages/cpp.js/src/utils/getAbsolutePath.js b/packages/cpp.js/src/utils/getAbsolutePath.js index 60c2e602..bc06d2ef 100644 --- a/packages/cpp.js/src/utils/getAbsolutePath.js +++ b/packages/cpp.js/src/utils/getAbsolutePath.js @@ -5,7 +5,7 @@ export default function getAbsolutePath(projectPath, path) { return null; } if (upath.isAbsolute(path)) { - return path; + return upath.resolve(path); } if (projectPath) { return upath.resolve(upath.join(upath.resolve(projectPath), path)); diff --git a/packages/cpp.js/src/utils/getCMakeListsFilePath.js b/packages/cpp.js/src/utils/getCMakeListsFilePath.js index 7ccbb16c..e5febabe 100644 --- a/packages/cpp.js/src/utils/getCMakeListsFilePath.js +++ b/packages/cpp.js/src/utils/getCMakeListsFilePath.js @@ -1,10 +1,10 @@ -import { glob } from 'glob'; import getParentPath from './getParentPath.js'; +import findFiles from './findFiles.js'; export default function getCMakeListsFilePath(basePath = process.cwd()) { - let temp = glob.sync('CMakeLists.txt', { absolute: true, cwd: basePath }); + let temp = findFiles('CMakeLists.txt', { cwd: basePath }); if (temp.length === 0) { - temp = glob.sync('*/CMakeLists.txt', { absolute: true, cwd: basePath, ignore: ['node_modules/*', 'dist/*', 'build/*'] }); + temp = findFiles('*/CMakeLists.txt', { cwd: basePath, ignore: ['node_modules/*', 'dist/*', 'build/*'] }); } if (temp.length > 0) return temp[0]; diff --git a/packages/cppjs-core-docker/DraftWindowsDockerfile b/packages/cppjs-core-docker/DraftWindowsDockerfile new file mode 100644 index 00000000..9d89f697 --- /dev/null +++ b/packages/cppjs-core-docker/DraftWindowsDockerfile @@ -0,0 +1,74 @@ +FROM winamd64/openjdk:24-nanoserver + +SHELL ["cmd", "/S", "/C"] + +RUN curl -o python.zip -L https://www.python.org/ftp/python/3.13.1/python-3.13.1-embed-amd64.zip && \ + mkdir C:\Python && \ + tar -xf python.zip -C C:\Python && \ + del python.zip + +RUN curl -o nodejs.zip -L https://nodejs.org/dist/v22.12.0/node-v22.12.0-win-x64.zip && \ + mkdir C:\NodeJS && \ + tar -xf nodejs.zip -C C:\NodeJS && \ + del nodejs.zip + +RUN curl -o cmake.zip -L https://github.com/Kitware/CMake/releases/download/v3.31.3/cmake-3.31.3-windows-x86_64.zip && \ + mkdir C:\CMake && \ + tar -xf cmake.zip -C C:\CMake && \ + del cmake.zip + +RUN curl -o mingit.zip -L https://github.com/git-for-windows/git/releases/download/v2.47.1.windows.1/MinGit-2.47.1-64-bit.zip && \ + mkdir C:\Git && \ + tar -xf mingit.zip -C C:\Git && \ + del mingit.zip + +RUN curl -o C:\cacert.pem -L https://curl.se/ca/cacert.pem + +USER ContainerAdministrator +RUN setx /M PATH "%PATH%;C:\Python;C:\NodeJS\node-v22.12.0-win-x64;C:\CMake\cmake-3.31.3-windows-x86_64\bin;C:\Git\cmd;C:\emsdk" +RUN setx /M SSL_CERT_FILE "C:\cacert.pem" +USER ContainerUser + +RUN git clone https://github.com/emscripten-core/emsdk.git C:\emsdk && \ + cd C:\emsdk && \ + emsdk install 3.1.51 + +RUN emsdk activate 3.1.51 + +USER ContainerAdministrator +RUN setx /M PATH "C:\emsdk\upstream\emscripten;%PATH%" +RUN setx /M EMSDK "C:\emsdk" +RUN setx /M EMSDK_NODE "C:\emsdk\node\20.18.0_64bit\bin\node.exe" +RUN setx /M EMSDK_PYTHON "C:\emsdk\python\3.9.2-nuget_64bit\python.exe" +RUN setx /M NDK_VERSION "25.2.9519653" +RUN setx /M ANDROID_SDK_ROOT "c:\android-sdk" +RUN setx /M ANDROID_HOME "c:\android-sdk" +RUN setx /M NDK_ROOT "%ANDROID_SDK_ROOT%/ndk/${NDK_VERSION}" +USER ContainerUser + +RUN curl -o android-sdk.zip https://dl.google.com/android/repository/commandlinetools-win-11076708_latest.zip && \ + mkdir %ANDROID_SDK_ROOT% && \ + tar -xf android-sdk.zip -C %ANDROID_SDK_ROOT% +RUN mkdir %ANDROID_SDK_ROOT%\licenses +RUN node -e "require('fs').writeFileSync('c:/android-sdk/licenses/android-sdk-license', '24333f8a63b6825ea9c5514f83c2829b004d1fee')" +RUN node -e "require('fs').writeFileSync('c:/android-sdk/licenses/android-sdk-preview-license', '84831b9409646a918e30573bab4c9c91346d8abd')" +RUN %ANDROID_SDK_ROOT%\cmdline-tools\bin\sdkmanager --sdk_root=%ANDROID_SDK_ROOT% --install "ndk;%NDK_VERSION%" +RUN del android-sdk.zip + +WORKDIR c:/emsdk/upstream/emscripten/src/embind +RUN curl -o embind.js -L https://raw.githubusercontent.com/bugra9/emscripten/embind-overloading-support/src/embind/embind.js + +WORKDIR c:/emsdk/upstream/emscripten +RUN node -e "const fs = require('fs'); const filePath = './system/include/emscripten/bind.h'; const data = fs.readFileSync(filePath, 'utf8').replace(/smart_ptr\(smartPtrName\);/g, ' '); fs.writeFileSync(filePath, data);" +RUN node -e "const fs = require('fs'); const filePath = './cache/sysroot/include/emscripten/bind.h'; const data = fs.readFileSync(filePath, 'utf8').replace(/smart_ptr\(smartPtrName\);/g, ' '); fs.writeFileSync(filePath, data);" + +WORKDIR c:/ +RUN curl -o add-embind-support.zip -L https://github.com/bugra9/swig/archive/refs/heads/add-embind-support.zip +RUN tar -xf add-embind-support.zip -C c:/ + +#WORKDIR c:/swig-add-embind-support +#RUN cmake . +#RUN make +#RUN make install + +ENTRYPOINT [ "cmd", "/c" ]