NativePHP / laravel

Laravel wrapper for the NativePHP framework
https://nativephp.com
MIT License
3.09k stars 159 forks source link

[Bug]: php artisan native:build use wrong php build #289

Closed vikas5914 closed 4 months ago

vikas5914 commented 4 months ago

What were you trying to do?

When running php artisan native:build on Windows,

What happened?

it throws error saying Error: Command failed: D:\Projects\trash\laravel-win\vendor\nativephp\electron\resources\js\resources\php\php

Upon checking the log and comparing it with php artisan native:build win it looks like the command is wrong.. it running NativePHP@1.0.0 build:all instead of NativePHP@1.0.0 build:win

D:\Projects\trash\laravel-win ❯ php artisan native:build                                                                                                                                        03:04:19
Build NativePHP app…
Installing dependencies from lock file
Verifying lock file contents can be installed on current platform.
Nothing to install, update or remove
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi

   INFO  Discovering packages.

  laravel/tinker .............................................................................................................................. DONE
  nativephp/electron .......................................................................................................................... DONE
  nativephp/laravel ........................................................................................................................... DONE
  nesbot/carbon ............................................................................................................................... DONE
  nunomaduro/termwind ......................................................................................................................... DONE

55 packages you are using are looking for funding.
Use the `composer fund` command to find out more!

> NativePHP@1.0.0 build:all
> cross-env npm run build:mac && cross-env npm run build:win && cross-env npm run build:linux

> NativePHP@1.0.0 build:mac
> cross-env npm run build:mac-arm && cross-env npm run build:mac-x86

> NativePHP@1.0.0 build:mac-arm
> cross-env node php.js --arm64 --mac && cross-env npm run build && cross-env node ./node_modules/electron-builder/cli.js -p never --mac --config --arm64

Binary Source:  D:\Projects\trash\laravel-win\vendor\nativephp\php-bin\bin\mac\arm64\php-8.2.zip
Binary Filename:  php
PHP version: 8.2
Unzipping PHP binary from D:\Projects\trash\laravel-win\vendor\nativephp\php-bin\bin\mac\arm64\php-8.2.zip to D:\Projects\trash\laravel-win\vendor\nativephp\electron\resources\js\resources\php
Copied certificate file to D:\Projects\trash\laravel-win\vendor\nativephp\electron\resources\js\resources\cacert.pem
Copied PHP binary to  D:\Projects\trash\laravel-win\vendor\nativephp\electron\resources\js\resources\php\php

> NativePHP@1.0.0 build
> electron-vite build

vite v4.5.3 building for production...
transforming...
✓ 3 modules transformed.
rendering chunks...
out/main/index.js  0.62 kB
✓ built in 66ms
vite v4.5.3 building for production...
transforming...
✓ 1 modules transformed.
rendering chunks...
out/preload/index.js  0.70 kB
✓ built in 8ms
vite v4.5.3 building for production...
"contextBridge" and "ipcRenderer" are imported from external module "electron" but never used in "src/preload/index.js".
transforming...
✓ 2 modules transformed.
rendering chunks...
../../out/renderer/index.html  0.37 kB
✓ built in 75ms
  • electron-builder  version=24.13.3 os=10.0.26100
Arch:  x64
Platform:  win32
=====================
Building for mac
=====================
updater config { provider: 'spaces', name: null, region: null, path: null }
=====================
=====================
Copied app to resources
D:\Projects\trash\laravel-win\dist
=====================
  • loaded configuration  file=D:\Projects\trash\laravel-win\vendor\nativephp\electron\resources\js\electron-builder.js
  ⨯ Build for macOS is supported only on macOS, please see https://electron.build/multi-platform-build
'D:\Projects\trash\laravel-win\vendor\nativephp\electron\resources\js\resources\php\php' is not recognized as an internal or external command,
operable program or batch file.
=====================
Error copying app to resources
Error: Command failed: D:\Projects\trash\laravel-win\vendor\nativephp\electron\resources\js\resources\php\php D:\Projects\trash\laravel-win\vendor\nativephp\electron\resources\js\resources\app\artisan native:minify D:\Projects\trash\laravel-win\vendor\nativephp\electron\resources\js\resources\app
'D:\Projects\trash\laravel-win\vendor\nativephp\electron\resources\js\resources\php\php' is not recognized as an internal or external command,
operable program or batch file.

    at genericNodeError (node:internal/errors:984:15)
    at wrappedFn (node:internal/errors:538:14)
    at checkExecSyncError (node:child_process:890:11)
    at execSync (node:child_process:962:15)
    at Object.<anonymous> (D:\Projects\trash\laravel-win\vendor\nativephp\electron\resources\js\electron-builder.js:113:9)
    at Module._compile (node:internal/modules/cjs/loader:1455:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1534:10)
    at Module.load (node:internal/modules/cjs/loader:1265:32)
    at Function.Module._load (node:internal/modules/cjs/loader:1081:12)
    at Module.require (node:internal/modules/cjs/loader:1290:19)
    at require (node:internal/modules/helpers:188:18)
    at readConfig (D:\Projects\trash\laravel-win\vendor\nativephp\electron\resources\js\node_modules\read-config-file\src\main.ts:20:14)
    at findAndReadConfig (D:\Projects\trash\laravel-win\vendor\nativephp\electron\resources\js\node_modules\read-config-file\src\main.ts:48:18)
    at getConfig (D:\Projects\trash\laravel-win\vendor\nativephp\electron\resources\js\node_modules\app-builder-lib\src\util\config.ts:44:34)
    at Packager.build (D:\Projects\trash\laravel-win\vendor\nativephp\electron\resources\js\node_modules\app-builder-lib\src\packager.ts:317:27)
    at executeFinally (D:\Projects\trash\laravel-win\vendor\nativephp\electron\resources\js\node_modules\builder-util\src\promise.ts:12:14) {
  status: 1,
  signal: null,
  output: [
    null,
    <Buffer >,
    <Buffer 27 44 3a 5c 50 72 6f 6a 65 63 74 73 5c 74 72 61 73 68 5c 6c 61 72 61 76 65 6c 2d 77 69 6e 5c 76 65 6e 64 6f 72 5c 6e 61 74 69 76 65 70 68 70 5c 65 6c ... 127 more bytes>
  ],
  pid: 7240,
  stdout: <Buffer >,
  stderr: <Buffer 27 44 3a 5c 50 72 6f 6a 65 63 74 73 5c 74 72 61 73 68 5c 6c 61 72 61 76 65 6c 2d 77 69 6e 5c 76 65 6e 64 6f 72 5c 6e 61 74 69 76 65 70 68 70 5c 65 6c ... 127 more bytes>
}
=====================

How to reproduce the bug

Just create a fresh new L11 app install the native PHP and run the command

Package Versions

0.6.2

PHP Version

8.2.18

Laravel Version

11.0

Node Version

22.0.0

Which operating systems have you seen this occur on?

Windows

OS version

Windows 11 Pro, 24H2, 26100.268

Notes

No response

simonhamp commented 4 months ago

Cross-compilation hasn't been tested yet.

Also, you won't be able to compile for Mac on anything other than a Mac - this is a limitation of Electron (and probably an Apple thing 🤷‍♂️)

Stick to compiling for the current platform for now with:

php artisan native:build win
vikas5914 commented 4 months ago

@simonhamp I am not trying to cross-compile. Just for windows only.

According to documentation, php artisan native:build will build for the platform and architecture where I am running the build. So my expectation it should build only for the windows,but instead its trying to cross-compile.

AntonioDiPassio-AppSys commented 4 months ago

+1

simonhamp commented 4 months ago

Ok, there are 3 issues here 😅

  1. What should happen when you run native:build without a platform qualifier - what is the developer expectation
  2. What the docs tell you will happen
  3. What the current implementation actually does

It sounds like 2 & 3 are conflicting, but how it gets resolved should possibly be determined by 1.

So the question is: ignoring what the docs say for a second, what do you expect to happen when running the command php artisan native:build?

vikas5914 commented 4 months ago

@simonhamp I recently used electron/packager, which created a build for the current host platform if no platform is provided. So I am ok with the same behaviour.

People can provide that argument if they want to build for cross or all platforms.

AntonioDiPassio-AppSys commented 4 months ago

I agree, without platform should be current platform But perhaps add the 'all' argument to build for all platforms

simonhamp commented 4 months ago

Thanks both for the feedback. I'll get this 'fixed' then so that the implementation lines up with the docs

Fludem commented 4 months ago

Cross-compilation hasn't been tested yet.

Also, you won't be able to compile for Mac on anything other than a Mac - this is a limitation of Electron (and probably an Apple thing 🤷‍♂️)

Stick to compiling for the current platform for now with:

php artisan native:build win

I'm not sure if there are solutions for building apps that aren't electron-based, but I do recall one of my friends having to get my other friend, who had a Mac, to build his app for him.

Wasn't electron either so I do think it's an Apple/Mac limitation.

vikas5914 commented 4 months ago

Thanks both for the feedback. I'll get this 'fixed' then so that the implementation matches the docs.

@simonhamp Since this is Laravel-based, we can use prompts to choose the OS if no platform is provided.

simonhamp commented 4 months ago

@vikas5914 we could...

vikas5914 commented 4 months ago

@simonhamp check https://github.com/NativePHP/electron/pull/92

vikas5914 commented 4 months ago

Fixed in https://github.com/NativePHP/electron/releases/tag/0.6.3