|
46 | 46 | ]; |
47 | 47 |
|
48 | 48 | commonDeps = with pkgs; [ |
| 49 | + stdenv.cc |
| 50 | + gcc-unwrapped |
49 | 51 | pkg-config |
50 | 52 | installShellFiles |
51 | 53 | python3 |
|
64 | 66 | deps = if isDarwin then darwinDeps ++ commonDeps else linuxDeps ++ commonDeps; |
65 | 67 | libraryPathVar = if isDarwin then "DYLD_LIBRARY_PATH" else "LD_LIBRARY_PATH"; |
66 | 68 | platform = if isDarwin then "macos" else "linuxbsd"; |
67 | | - binary = if isDarwin then "redot.macos.editor.${arch}" else "redot.linuxbsd.editor.${arch}"; |
68 | 69 | }); |
69 | 70 | in { |
70 | 71 | apps = forEachSupportedSystem ({ |
71 | 72 | pkgs, |
72 | 73 | deps, |
73 | 74 | libraryPathVar, |
74 | 75 | platform, |
75 | | - binary, |
76 | 76 | arch, |
77 | 77 | ... |
78 | 78 | }: let |
79 | 79 | script = pkgs.writeShellScript "redot" '' |
| 80 | + export PATH=${pkgs.lib.makeBinPath deps}:$PATH |
80 | 81 | export ${libraryPathVar}=${pkgs.lib.makeLibraryPath deps} |
81 | | - if [ ! -f ./bin/${binary} ]; then |
| 82 | +
|
| 83 | + scons_args=() |
| 84 | + runtime_args=() |
| 85 | + parsing_runtime_args=0 |
| 86 | + show_help=0 |
| 87 | + target=editor |
| 88 | + target_arch=${arch} |
| 89 | + scons_platform=${platform} |
| 90 | + dev_build=no |
| 91 | + precision=single |
| 92 | + threads=yes |
| 93 | + extra_suffix= |
| 94 | +
|
| 95 | + for arg in "$@"; do |
| 96 | + if [ "$parsing_runtime_args" -eq 0 ] && [ "$arg" = "--help" ]; then |
| 97 | + show_help=1 |
| 98 | + continue |
| 99 | + fi |
| 100 | +
|
| 101 | + if [ "$parsing_runtime_args" -eq 0 ] && [ "$arg" = "--" ]; then |
| 102 | + parsing_runtime_args=1 |
| 103 | + continue |
| 104 | + fi |
| 105 | +
|
| 106 | + if [ "$parsing_runtime_args" -eq 0 ]; then |
| 107 | + case "$arg" in |
| 108 | + target=*) target=''${arg#target=} ;; |
| 109 | + arch=*) |
| 110 | + target_arch=''${arg#arch=} |
| 111 | + if [ "$target_arch" = "auto" ]; then |
| 112 | + target_arch=${arch} |
| 113 | + fi |
| 114 | + ;; |
| 115 | + platform=*) |
| 116 | + scons_platform=''${arg#platform=} |
| 117 | + continue |
| 118 | + ;; |
| 119 | + dev_build=*) dev_build=''${arg#dev_build=} ;; |
| 120 | + precision=*) precision=''${arg#precision=} ;; |
| 121 | + threads=*) threads=''${arg#threads=} ;; |
| 122 | + extra_suffix=*) extra_suffix=''${arg#extra_suffix=} ;; |
| 123 | + esac |
| 124 | +
|
| 125 | + scons_args+=("$arg") |
| 126 | + else |
| 127 | + runtime_args+=("$arg") |
| 128 | + fi |
| 129 | + done |
| 130 | +
|
| 131 | + if [ "$show_help" -eq 1 ]; then |
| 132 | + cat <<EOF |
| 133 | +Usage: |
| 134 | + nix run . |
| 135 | + nix run . -- [scons build flags...] |
| 136 | + nix run . -- [scons build flags...] -- [redot runtime args...] |
| 137 | +
|
| 138 | +Examples: |
| 139 | + nix run . |
| 140 | + nix run . -- target=editor dev_build=yes num_jobs=12 |
| 141 | + nix run . -- target=template_release production=yes |
| 142 | + nix run . -- target=editor dev_build=yes -- --path /tmp/project |
| 143 | +
|
| 144 | +Argument handling: |
| 145 | + - The first '--' is consumed by Nix. |
| 146 | + - Arguments before the next '--' are passed to SCons. |
| 147 | + - Arguments after the next '--' are passed to the Redot binary. |
| 148 | +
|
| 149 | +Notes: |
| 150 | + - Common SCons flags include target=..., dev_build=yes, production=yes, |
| 151 | + module_mono_enabled=yes, precision=double, num_jobs=..., and ccflags=... |
| 152 | + - The wrapper auto-builds only when a matching binary is not already present. |
| 153 | + Use 'nix develop' for full manual rebuild control. |
| 154 | +EOF |
| 155 | + exit 0 |
| 156 | + fi |
| 157 | +
|
| 158 | + binary_pattern="redot.$scons_platform.''${target}" |
| 159 | +
|
| 160 | + if [ "$dev_build" = "yes" ]; then |
| 161 | + binary_pattern="$binary_pattern.dev" |
| 162 | + fi |
| 163 | +
|
| 164 | + if [ "$precision" = "double" ]; then |
| 165 | + binary_pattern="$binary_pattern.double" |
| 166 | + fi |
| 167 | +
|
| 168 | + binary_pattern="$binary_pattern.''${target_arch}" |
| 169 | +
|
| 170 | + if [ "$threads" = "no" ]; then |
| 171 | + binary_pattern="$binary_pattern.nothreads" |
| 172 | + fi |
| 173 | +
|
| 174 | + if [ -n "$extra_suffix" ]; then |
| 175 | + binary_pattern="$binary_pattern.$extra_suffix" |
| 176 | + fi |
| 177 | +
|
| 178 | + binary_path="./bin/$binary_pattern" |
| 179 | +
|
| 180 | + if [ ! -f "$binary_path" ]; then |
82 | 181 | echo "Building Redot..." |
83 | | - scons platform=${platform} |
| 182 | + scons "''${scons_args[@]}" platform=$scons_platform |
84 | 183 | fi |
85 | | - exec ./bin/${binary} "$@" |
| 184 | +
|
| 185 | + if [ ! -f "$binary_path" ]; then |
| 186 | + echo "Could not find a built Redot binary at $binary_path" >&2 |
| 187 | + exit 1 |
| 188 | + fi |
| 189 | +
|
| 190 | + exec "$binary_path" "''${runtime_args[@]}" |
86 | 191 | ''; |
87 | 192 | in { |
88 | 193 | default = { |
|
0 commit comments