diff --git a/.gitignore b/.gitignore index 039d3116..c61b08b8 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,5 @@ yarn-error.log # Rust compilation dirs rust/*/target +# Compiled rust apps (rust modules are recompiled during container start) +storage/ffi-libs/*.so \ No newline at end of file diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 56ae574d..9f4f1e06 100644 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -48,6 +48,9 @@ elif [[ "$role" == "app" ]]; then php artisan cache:clear && php artisan config:cache && php artisan route:cache && php artisan view:cache fi + # Compile rust modules + ./rust/test_ffi/compile.sh + exec php-fpm else echo "Could not match the container role \"$role\"" diff --git a/rust/README.md b/rust/README.md index 3953475a..bd4ecf9a 100644 --- a/rust/README.md +++ b/rust/README.md @@ -8,10 +8,10 @@ take up a lot of memory and the BattleEngine in PHP can e.g. take up gigabytes o The rust source code is stored in the `./rust/` folder. ## Compile rust version -After making change to any rust modules, you should manually compile them and copy it over to -the `storage/ffi-libs` folder. +The Rust modules are automatically compiled during container startup. However, during development +or testing, you may want to manually compile the modules to test your changes immediately. -To compile rust, go to the rust module directory, e.g. +To compile rust, go to the rust module directory inside the container, e.g. ```bash # Navigate to the rust package you want to compile @@ -28,9 +28,6 @@ cp target/release/libtest_ffi.so ../../storage/ffi-libs Alternatively, you can also run the `compile.sh` script inside the module's folder which executes the statements above: ```bash -# Navigate to the rust package you want to compile -cd rust/test_ffi - -# Execute compile.sh -./compile.sh +# Execute compile.sh (from app root) +./rust/test_ffi/compile.sh ``` \ No newline at end of file diff --git a/rust/test_ffi/compile.sh b/rust/test_ffi/compile.sh index 51e8cf50..0b8ec5bb 100755 --- a/rust/test_ffi/compile.sh +++ b/rust/test_ffi/compile.sh @@ -1,6 +1,6 @@ # Compile the rust package -cargo build --release +cargo build --manifest-path="rust/test_ffi/Cargo.toml" --release # Copy the compiled rust package to the ffi-libs storage directory. # The .so files are called by Laravel. -cp target/release/libtest_ffi.so ../../storage/ffi-libs \ No newline at end of file +cp rust/test_ffi/target/release/libtest_ffi.so storage/ffi-libs \ No newline at end of file diff --git a/storage/ffi-libs/README.md b/storage/ffi-libs/README.md new file mode 100644 index 00000000..758d6382 --- /dev/null +++ b/storage/ffi-libs/README.md @@ -0,0 +1 @@ +Rust modules will be compiled during container startup and will be placed here automatically. \ No newline at end of file diff --git a/storage/ffi-libs/libtest_ffi.so b/storage/ffi-libs/libtest_ffi.so deleted file mode 100755 index 8dcf1521..00000000 Binary files a/storage/ffi-libs/libtest_ffi.so and /dev/null differ