-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add command to build standalone binary #260
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,7 @@ | |
'log:with-context', | ||
'parallel:sleep', | ||
'repack', | ||
'compile', | ||
'run:ls', | ||
'run:run-parallel', | ||
]; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Compiling your application into a standalone binary | ||
|
||
[Packing your Castor application as a phar](repack.md) can be a good way to easily | ||
share and use it in various environments. | ||
|
||
However, you need to ensure that PHP is installed and configured correctly in all | ||
the environments where you want to use your Castor app. | ||
This can be a hassle, especially if you don't have control over the environments. | ||
|
||
To make things simpler, Castor's `compile` command can help by creating a | ||
customizable PHP binary with a phar, making one executable file that can be used in any setting. | ||
|
||
Just pass your repacked Castor app phar as an argument of this command. | ||
|
||
## Pre-requisites | ||
|
||
Follow the [`repack` documentation](repack.md) to produce a phar of your | ||
Castor app. | ||
|
||
## Running the Compile Command | ||
|
||
To compile your Castor application, navigate to your project directory and run: | ||
|
||
```bash | ||
vendor/bin/castor compile my-custom-castor-app.phar | ||
``` | ||
|
||
> [!WARNING] | ||
> Compiling is not supported yet on Windows. | ||
|
||
### Options | ||
|
||
Make sure to take a look at the command description to see all the available options: | ||
```bash | ||
vendor/bin/castor compile --help | ||
``` | ||
|
||
### Behavior | ||
|
||
The `compile` command performs several steps: | ||
|
||
1. Downloads or uses an existing [Static PHP CLI tool](https://github.com/crazywhalecc/static-php-cli) to compile PHP and the phar into a binary. | ||
2. If required, it automatically installs dependencies and compiles PHP with the specified extensions. | ||
3. Combines the compiled PHP and your phar file into a single executable. | ||
|
||
## Post-Compilation | ||
|
||
Once the compilation is finished, your Castor application is transformed into a standalone binary named `castor` by default (you can use the `--output` option to change it). | ||
|
||
This binary is now ready to be distributed and run in environments that do not have PHP installed. | ||
|
||
You can simply run it like any other executable: | ||
|
||
```bash | ||
./castor | ||
tigitz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this part, It could be written:
More over in the
Save PHP static building artifacts cache the key could be only
php-static-building-artifacts-cache`see https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#matching-a-cache-key
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was my initial idea, unfortunately it doesn't work as expected.
When the restore action with
key: X
is executed, it looks for acache[X]
and use it (hit) if it exists.When the save action with
key: X
is executed, it tries to savecache[X]
but if fails if it already exists, it doesn't update the cache key.And that's not what we want because when a new arg is added to the build command, a new directory is created:
/home/runner/.cache/castor/castor-php-static-compiler/{new_compile_command_build_hash}/*
and we want to update the cache with this new build artifacts.If the current config what's happening is:
Run 1
/home/runner/.cache/castor/castor-php-static-compiler/{compiler_test_command}/*
/home/runner/.cache/castor/castor-php-static-compiler/{build_compiler_for_CASTOR_BIN}/*
/home/runner/.cache/castor/castor-php-static-compiler/*
askey: php-static-building-artifacts-cache-XXX
where XXX is hash(castor-php-static-compiler/*)Run 2
/home/runner/.cache/castor/castor-php-static-compiler/**/*
, no build/home/runner/.cache/castor/castor-php-static-compiler/*
askey: php-static-building-artifacts-cache-XXX
but fails. It's ok no new artifacts were generated anyway.Run 3, new compilation is added or options of existing build are changed in
CompileCommandTest
for example:/home/runner/.cache/castor/castor-php-static-compiler/{compiler_test_command}/*
/home/runner/.cache/castor/castor-php-static-compiler/{build_compiler_for_CASTOR_BIN}/*
/home/runner/.cache/castor/castor-php-static-compiler/*
askey: php-static-building-artifacts-cache-YYY
where YYY is a new hash ofcastor-php-static-compiler/*
because new artifacts where generated since XXXThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two folders
because
If yes, I almost got it, but not perfectly :)
If not I'm totally lost 😅
Anyway, I'll approve the PR, play a bit with it, with the cache, etc :)
Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes exactly! Both build are not using the same extensions, the one in the test has less extension, it just makes sure it compiles and can run a hello world.
The compiled castor has more extensions because it needs to rune the whole suit of examples.