Skip to content

Commit c75748f

Browse files
committed
Update: Improved iOS support, now installing automatically and running the app
1 parent 8f815d3 commit c75748f

File tree

3 files changed

+33
-12
lines changed

3 files changed

+33
-12
lines changed

tools/hbuild/dub.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"copyright": "Copyright © 2023, Hipreme",
66
"dependencies": {
77
"arsd-official:terminal": "~>11.5.0",
8-
"redub": "~>1.24.5",
8+
"redub": "~>1.24.7",
99
"handy-httpd": "~>8.4.3",
1010
"archive": "~>0.7.1",
1111
"my-ip": "~>0.2.0",

tools/hbuild/source/common_macos.d

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ void setupPerCompiler(ref Terminal t, string compiler, string arch, out string e
1313
{
1414
string outputDruntime = getHipPath("build", "appleos", XCodeDFolder, "static", "libdruntime-ldc.a");
1515
string ldcLibPath = buildNormalizedPath(configs["ldcPath"].str, "lib-"~arch);
16+
1617
string druntimeLib = ldcLibPath.getFirstExisting("libdruntime-ldc.a");
1718
if(druntimeLib == null)
1819
throw new Error("DRuntime Library not found on path "~configs["ldcPath"].str);
@@ -25,6 +26,7 @@ void setupPerCompiler(ref Terminal t, string compiler, string arch, out string e
2526
string outputPhobos = getHipPath("build", "appleos", XCodeDFolder,"static");
2627
std.file.mkdirRecurse(outputPhobos);
2728
outputPhobos = buildNormalizedPath(outputPhobos, "libphobos2.a");
29+
2830
t.writelnSuccess("Copying phobos to XCode ", phobosLib, "->", outputPhobos);
2931
t.flush;
3032
std.file.copy(phobosLib, outputPhobos);

tools/hbuild/source/targets/ios.d

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ string getTargetArchitecture(bool isSimulator)
2222
string getExtraCommand(string type)
2323
{
2424
if(type == "simulator") return " -sdk iphonesimulator ";
25-
return "";
25+
return " -sdk iphoneos";
2626
}
2727

2828

@@ -100,6 +100,7 @@ unittest
100100

101101
private string getDestination()
102102
{
103+
// return "-destination 'generic/platform=iOS' ";
103104
return "-destination 'platform=iOS Simulator,name="~
104105
configs["iosDevice"].str ~
105106
",OS=" ~configs["iosVersions"].array[0].integer.versionFromInt ~ "' ";
@@ -113,7 +114,21 @@ private string getIosTriple(string arch, bool isSimulator)
113114
return "arm64-apple-ios14.0-simulator";
114115
}
115116
return arch~"-apple-ios14.0";
116-
117+
}
118+
119+
string getIosLibFolder(bool isSimulator)
120+
{
121+
version(X86_64)
122+
{
123+
if(isSimulator)
124+
return "ios-x86_64";
125+
}
126+
else
127+
{
128+
if(isSimulator)
129+
return "ios-arm64-simulator";
130+
}
131+
return "ios-arm64";
117132
}
118133
ChoiceResult putInstalledDeviceInformation(ref Terminal t)
119134
{
@@ -163,17 +178,16 @@ ChoiceResult putInstalledDeviceInformation(ref Terminal t)
163178
updateConfigFile();
164179

165180
return ChoiceResult.Continue;
166-
167-
168181
}
169182

170183
ChoiceResult prepareiOS(Choice* c, ref Terminal t, ref RealTimeConsoleInput input, in CompilationOptions cOpts)
171184
{
172-
string arch = getTargetArchitecture(TARGET_TYPE == "simulator");
185+
bool isSimulator = TARGET_TYPE == "simulator";
186+
string arch = getTargetArchitecture(isSimulator);
173187
prepareAppleOSBase(c,t,input);
174188

175189
string out_extraLinkerFlags;
176-
setupPerCompiler(t, "ldc2", "ios-"~arch, out_extraLinkerFlags);
190+
setupPerCompiler(t, "ldc2", getIosLibFolder(isSimulator), out_extraLinkerFlags);
177191
injectLinkerFlagsOnXcode(t, input, out_extraLinkerFlags);
178192
if(!("lastUser" in configs))
179193
{
@@ -197,7 +211,7 @@ ChoiceResult prepareiOS(Choice* c, ref Terminal t, ref RealTimeConsoleInput inpu
197211
cleanAppleOSLibFolder();
198212
ProjectDetails d;
199213
if(waitRedub(t, DubArguments().
200-
command("build").configuration("ios").arch(getIosTriple(arch, TARGET_TYPE == "simulator")).compiler("ldc2").opts(cOpts),
214+
command("build").configuration("ios").arch(getIosTriple(arch, isSimulator)).compiler("ldc2").opts(cOpts),
201215
d,
202216
getHipPath("build", "appleos", XCodeDFolder, "libs")) != 0)
203217
{
@@ -213,15 +227,20 @@ ChoiceResult prepareiOS(Choice* c, ref Terminal t, ref RealTimeConsoleInput inpu
213227
clean ~
214228
"build CONFIGURATION_BUILD_DIR=\"bin\" "~
215229
codeSignCommand ~ extraCommands ~
216-
getDestination() ~
217-
" && cd bin && HipremeEngine.app/Contents/iOS/HipremeEngine")
218-
);
230+
getDestination()
231+
));
232+
233+
t.wait(spawnShell(
234+
"open -a Simulator && "~
235+
"xcrun simctl install booted " ~ getHipPath("build", "appleos", "bin", "HipremeEngine.app") ~ " && " ~
236+
"xcrun simctl launch booted hipreme.HipremeEngine"
237+
));
219238
}
220239
}
221240
if(configs["firstiOSRun"].boolean)
222241
{
223242
configs["firstiOSRun"] = false;
224243
updateConfigFile();
225244
}
226-
return ChoiceResult.Continue;
245+
return ChoiceResult.None;
227246
}

0 commit comments

Comments
 (0)