Skip to content
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

Added PowerShell scripts and MSVC guide #314

Merged
merged 2 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Contributing to Notan

## Linux
> TODO

## MacOS
> TODO

## Windows (MSVC)

To be able to compile the Notan examples you will need to have the following pre-requirements in your system:

* [CMake](https://cmake.org/download/)
* [Python](https://www.python.org/downloads/)
* [Ninja](https://github.com/ninja-build/ninja/wiki/Pre-built-Ninja-packages)

If you want to use the wasm32 target you will need to execute some additional commands for it:
````cmd
rustup target add wasm32-unknown-unknown
cargo install -f wasm-bindgen-cli --version 0.2.87
cargo install wasm-opt
````

After this you will be able to use the PowerShell scripts in the `scripts` folder to compile the examples or the doc.
1 change: 1 addition & 0 deletions scripts/build_docs.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Start-Process cargo -ArgumentList "doc --all-features" -NoNewWindow -Wait
19 changes: 19 additions & 0 deletions scripts/build_msvc_examples.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Create directory if it doesn't exist
[void](New-Item -ItemType Directory -Path ".\docs\msvc_examples\examples\assets" -ErrorAction SilentlyContinue)

# Copy assets to docs/examples directory
Copy-Item -Path ".\examples\assets" -Destination ".\docs\msvc_examples" -Recurse -ErrorAction SilentlyContinue

# Function to compile each example
function Compile {
param (
[string]$example
)

.\scripts\msvc_example.ps1 $example --release --no-assets
}

# Loop through each .rs file in examples directory
Get-ChildItem -Path ".\examples\*.rs" | ForEach-Object {
Compile $_.Basename
}
36 changes: 36 additions & 0 deletions scripts/build_web_examples.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Create directory if it doesn't exist
[void](New-Item -ItemType Directory -Path ".\docs\examples\assets" -ErrorAction SilentlyContinue)

# Copy assets to docs/examples directory
Copy-Item -Path ".\examples\assets" -Destination ".\docs\examples" -Recurse -ErrorAction SilentlyContinue

# Initialize document body
$doc_body = "<ul>`n"

# Function to compile each example
function Compile {
param (
[string]$example
)

.\scripts\web_example.ps1 $example --release --no-assets

$url = "examples/${example}.html"
$image = "examples/images/${example}.jpg"
$doc_body += "`n<li><a href=`"$url`"><div class=`"example-image`"><img src=`"$image`" alt=`"$example`"></div><div class=`"example-link`">$example</div></a></li>"
}

# Loop through each .rs file in examples directory
Get-ChildItem -Path ".\examples\*.rs" | ForEach-Object {
Compile $_.Basename
}

# Wait for compilation to finish
#Wait-Process -Name "web_example"

$doc_body += "`n</ul>"

# Copy docs.html to index.html and replace body placeholder
Copy-Item -Path ".\scripts\docs.html" -Destination ".\docs\index.html"
$index = (Get-Content ".\scripts\docs.html") -replace "{{ BODY }}", $doc_body
$index | Set-Content -Path ".\docs\index.html"
File renamed without changes.
22 changes: 22 additions & 0 deletions scripts/msvc_example.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
param(
[string]$1,
[string]$2,
[string]$3
)

$features = "glyph,egui,text,extra,audio,links,drop_files,clipboard,save_file,texture_to_file"
if ($2 -eq "--release") {
# Build release version
cargo build --target x86_64-pc-windows-msvc --release --example $1 --features=$features
Copy-Item .\target\x86_64-pc-windows-msvc\release\examples\$1.exe .\docs\msvc_examples\$1.exe
}
else {
# Build debug version
cargo build --target x86_64-pc-windows-msvc --example $1 --features=$features
Copy-Item .\target\x86_64-pc-windows-msvc\debug\examples\$1.exe .\docs\msvc_examples\$1.exe
}

if ($3 -ne "--no-assets") {
# Copy assets folder
Copy-Item .\examples\assets .\docs\msvc_examples -Recurse -Force
}
38 changes: 38 additions & 0 deletions scripts/web_example.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
param(
[string]$1,
[string]$2,
[string]$3
)

[void](New-Item -ItemType Directory -Path ".\docs\examples\$1" -Force)

$env:RUSTFLAGS = "--cfg=web_sys_unstable_apis"
$features = "glyph,egui,text,extra,audio,links,drop_files,clipboard,save_file,texture_to_file"

if ($2 -eq "--release") {
# Build release version
cargo build --target wasm32-unknown-unknown --release --example $1 --features=$features
wasm-bindgen .\target\wasm32-unknown-unknown\release\examples\$1.wasm --out-dir .\docs\examples\$1 --no-modules --browser
wasm-opt -O -o .\docs\examples\$1\${1}_bg.wasm .\docs\examples\$1\${1}_bg.wasm

if ($3 -eq "--gzip") {
# Gzip the wasm files
Compress-Archive -Path ".\docs\examples\$1\$1_bg.wasm" -DestinationPath ".\docs\examples\$1\$1_bg.wasm.gz" -Force
Compress-Archive -Path ".\docs\examples\$1\$1.js" -DestinationPath ".\docs\examples\$1\$1.js.gz" -Force
}
}
else {
# Build debug version
cargo build --target wasm32-unknown-unknown --example $1 --features=$features
wasm-bindgen .\target\wasm32-unknown-unknown\debug\examples\$1.wasm --out-dir .\docs\examples\$1 --no-modules --browser --keep-debug --debug
}

# Copy example.html and replace placeholder with example name
Copy-Item .\scripts\example.html .\docs\examples\$1.html -Force
$index = Get-Content .\scripts\example.html | ForEach-Object { $_ -replace '{{ EXAMPLE }}', $1 }
$index | Set-Content .\docs\examples\$1.html -Force

if ($3 -ne "--no-assets") {
# Copy assets folder
Copy-Item .\examples\assets .\docs\examples -Recurse -Force
}
Loading