Skip to content

add build script parameter to set ZIG_OPTIMIZE_MODE #168

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ For other versions, check the git tags of this repository.
## Build Instructions

```
./build <arch>-<os>-<abi> <mcpu>
./build <arch>-<os>-<abi> <mcpu> <zig_mode>
```

All parameters are required:
Expand All @@ -48,6 +48,10 @@ All parameters are required:
* `<mcpu>`: Replace with a `-mcpu` parameter of Zig. `baseline` is recommended
and means it will target a generic CPU for the target. `native` means it
will target the native CPU. See the Zig documentation for more details.
* `<zig_mode>`: Replace with any one value from the
[std.builtin.OptimizeMode](https://ziglang.org/documentation/master/std/#std.builtin.OptimizeMode)
enum. Note this only applies to the final output Zig binary. Intermediary build
stages will use ReleaseFast.

Please be aware of the following two CMake environment variables that can
significantly affect how long it takes to build:
Expand All @@ -71,7 +75,7 @@ installed via the Visual Studio installer.
The script must be run within the `Developer Command Prompt for VS 2019` shell:

```
build.bat <arch>-<os>-<abi> <mcpu>
build.bat [arch>-<os>-<abi] [mcpu] [zig_mode]
```

To build for x86 Windows, run the script within the `x86 Native Tools Command Prompt for VS 2019`.
Expand Down
3 changes: 2 additions & 1 deletion build
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set -eu

TARGET="$1" # Example: riscv64-linux-gnu
MCPU="$2" # Examples: `baseline`, `native`, `generic+v7a`, or `arm1176jzf_s`
ZIG_OPTIMIZE_MODE="$3"

ROOTDIR="$(pwd)"
ZIG_VERSION="0.12.0-dev.2058+04ac028a2"
Expand Down Expand Up @@ -195,7 +196,7 @@ $ZIG build \
--search-prefix "$ROOTDIR/out/$TARGET-$MCPU" \
-Dflat \
-Dstatic-llvm \
-Doptimize=ReleaseFast \
-Doptimize="$ZIG_OPTIMIZE_MODE" \
-Dstrip \
Comment on lines -198 to 200
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One potential issue I see with this PR is this. I would assume that the motivation for distributing e.g. a ReleaseSafe build of the compiler is that we can get useful stack traces when something goes wrong on the user's machine. It seems like -Dstrip undermines that.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but andrew has expressed not wanting to add branching to this script, so that leaves the open question of if the -Dstrip should be removed unconditionally and -Dopotimize changed to ReleaseSafe always and the option removed in the wake of the acceptance of 15194

-Dtarget="$TARGET" \
-Dcpu="$MCPU" \
Expand Down
3 changes: 2 additions & 1 deletion build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ if %ERRORLEVEL% neq 0 (

if "%1" == "" (set "TARGET=x86_64-windows-gnu") ELSE (set TARGET=%~1)
if "%2" == "" (set "MCPU=native") ELSE (set MCPU=%~2)
if "%3" == "" (set "ZIG_OPTIMIZE_MODE=ReleaseSafe") ELSE (set ZIG_OPTIMIZE_MODE=%~3)
if "%VSCMD_ARG_HOST_ARCH%"=="x86" set HOST_TARGET=x86-windows-msvc
if "%VSCMD_ARG_HOST_ARCH%"=="x64" set HOST_TARGET=x86_64-windows-msvc
echo Boostrapping targeting %TARGET% (%MCPU%), using %HOST_TARGET% as the host compiler
Expand Down Expand Up @@ -266,7 +267,7 @@ cd "%ROOTDIR%\zig"
--search-prefix "%ROOTDIR%%OUTDIR%\%TARGET%-%MCPU%" ^
-Dflat ^
-Dstatic-llvm ^
-Doptimize=ReleaseFast ^
-Doptimize="%ZIG_OPTIMIZE_MODE%" ^
-Dstrip ^
-Dtarget="%TARGET%" ^
-Dcpu="%MCPU%" ^
Expand Down