builder: produce an iOS binary instead of a bundle (#9316)

pull/9325/head
Leah Lundqvist 2021-03-15 19:03:05 +01:00 committed by GitHub
parent 7f0c8d1eec
commit 0823ea4af1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 30 additions and 97 deletions

View File

@ -84,13 +84,5 @@ pub fn (mut b Builder) compile_c() {
out_name_c = b.get_vtmp_filename(b.pref.out_name, '.tmp.so.c')
}
b.build_c(files, out_name_c)
if b.pref.os == .ios {
bundle_name := b.pref.out_name.split('/').last()
bundle_id := if b.pref.bundle_id != '' { b.pref.bundle_id } else { 'app.vlang.$bundle_name' }
display_name := if b.pref.display_name != '' { b.pref.display_name } else { bundle_name }
os.mkdir('${display_name}.app') or { panic(err) }
os.write_file('${display_name}.app/Info.plist', make_ios_plist(display_name, bundle_id,
bundle_name, 1)) or { panic(err) }
}
b.cc()
}

View File

@ -432,12 +432,7 @@ fn (mut v Builder) setup_output_name() {
if os.is_dir(v.pref.out_name) {
verror("'$v.pref.out_name' is a directory")
}
if v.pref.os == .ios {
bundle_name := v.pref.out_name.split('/').last()
v.ccoptions.o_args << '-o "${v.pref.out_name}.app/$bundle_name"'
} else {
v.ccoptions.o_args << '-o "$v.pref.out_name"'
}
v.ccoptions.o_args << '-o "$v.pref.out_name"'
}
fn (mut v Builder) vjs_cc() bool {
@ -536,7 +531,12 @@ fn (mut v Builder) cc() {
ios_sdk := if v.pref.is_ios_simulator { 'iphonesimulator' } else { 'iphoneos' }
ios_sdk_path_res := os.execute_or_panic('xcrun --sdk $ios_sdk --show-sdk-path')
mut isysroot := ios_sdk_path_res.output.replace('\n', '')
ccompiler = 'xcrun --sdk iphoneos clang -isysroot $isysroot'
arch := if v.pref.is_ios_simulator {
'-arch x86_64'
} else {
'-arch armv7 -arch armv7s -arch arm64'
}
ccompiler = 'xcrun --sdk iphoneos clang -isysroot $isysroot $arch'
}
v.setup_ccompiler_options(ccompiler)
v.build_thirdparty_obj_files()

View File

@ -86,44 +86,34 @@ fn (mut b Builder) run_compiled_executable_and_exit() {
if b.pref.only_check_syntax {
return
}
if b.pref.os == .ios && b.pref.is_ios_simulator == false {
panic('Running iOS apps on physical devices is not yet supported. Please run in the simulator using the -simulator flag.')
if b.pref.os == .ios {
panic('Running iOS apps is not supported yet.')
}
if b.pref.is_verbose {
println('============ running $b.pref.out_name ============')
}
if b.pref.os == .ios {
device := '"iPhone SE (2nd generation)"'
os.execute_or_panic('xcrun simctl boot $device')
bundle_name := b.pref.out_name.split('/').last()
display_name := if b.pref.display_name != '' { b.pref.display_name } else { bundle_name }
os.execute_or_panic('xcrun simctl install $device ${display_name}.app')
bundle_id := if b.pref.bundle_id != '' { b.pref.bundle_id } else { 'app.vlang.$bundle_name' }
os.execute_or_panic('xcrun simctl launch $device $bundle_id')
} else {
exefile := os.real_path(b.pref.out_name)
mut cmd := '"$exefile"'
if b.pref.backend == .js {
jsfile := os.real_path('${b.pref.out_name}.js')
cmd = 'node "$jsfile"'
}
for arg in b.pref.run_args {
// Determine if there are spaces in the parameters
if arg.index_byte(` `) > 0 {
cmd += ' "' + arg + '"'
} else {
cmd += ' ' + arg
}
}
if b.pref.is_verbose {
println('command to run executable: $cmd')
}
if b.pref.is_test || b.pref.is_run {
ret := os.system(cmd)
b.cleanup_run_executable_after_exit(exefile)
exit(ret)
exefile := os.real_path(b.pref.out_name)
mut cmd := '"$exefile"'
if b.pref.backend == .js {
jsfile := os.real_path('${b.pref.out_name}.js')
cmd = 'node "$jsfile"'
}
for arg in b.pref.run_args {
// Determine if there are spaces in the parameters
if arg.index_byte(` `) > 0 {
cmd += ' "' + arg + '"'
} else {
cmd += ' ' + arg
}
}
if b.pref.is_verbose {
println('command to run executable: $cmd')
}
if b.pref.is_test || b.pref.is_run {
ret := os.system(cmd)
b.cleanup_run_executable_after_exit(exefile)
exit(ret)
}
exit(0)
}

View File

@ -1,39 +0,0 @@
module builder
fn make_ios_plist(display_name string, bundle_id string, bundle_name string, bundle_version int) string {
return '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>$display_name</string>
<key>CFBundleExecutable</key>
<string>$bundle_name</string>
<key>CFBundleIdentifier</key>
<string>$bundle_id</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$bundle_name</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0.0</string>
<key>CFBundleSignature</key>
<string>VIOS</string>
<key>CFBundleVersion</key>
<string>$bundle_version</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>'
}

View File

@ -12,7 +12,7 @@ pub fn (mut g Gen) gen_c_main() {
}
g.out.writeln('')
main_fn_start_pos := g.out.len
if g.pref.os == .android && g.pref.is_apk {
if (g.pref.os == .android && g.pref.is_apk) || g.pref.os == .ios {
g.gen_c_android_sokol_main()
} else {
g.gen_c_main_header()

View File

@ -115,8 +115,6 @@ pub mut:
vroot string
out_name_c string // full os.real_path to the generated .tmp.c file; set by builder.
out_name string
display_name string
bundle_id string
path string // Path to file/folder to compile
// -d vfmt and -d another=0 for `$if vfmt { will execute }` and `$if another ? { will NOT get here }`
compile_defines []string // just ['vfmt']
@ -410,14 +408,6 @@ pub fn parse_args(known_external_commands []string, args []string) (&Preferences
res.custom_prelude = prelude
i++
}
'-name' {
res.display_name = cmdline.option(current_args, '-name', '')
i++
}
'-bundle' {
res.bundle_id = cmdline.option(current_args, '-bundle', '')
i++
}
else {
if command == 'build' && is_source_file(arg) {
eprintln('Use `v $arg` instead.')