Skip to content

Commit 3803a05

Browse files
committed
feat: working compilation for ipad
1 parent 68a5f0c commit 3803a05

File tree

10 files changed

+177
-13
lines changed

10 files changed

+177
-13
lines changed

liveview_native/live_nx_iree/native/swiftui/LiveNxIREE.xcodeproj/project.pbxproj

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
0A6CE5F5167F6157FF061569 /* DisconnectedView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D488732A3104CEE004CB7B42 /* DisconnectedView.swift */; };
1313
125165EBA8D40490F0AABE88 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 51F3B59B97B70D891071B6C4 /* Assets.xcassets */; };
1414
137E19B83B668B9C3130A3D7 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7955FA5760A1DB1E827049B /* ContentView.swift */; };
15+
373496882C7707DE00FD2E6F /* NxAddon.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373496872C7707DE00FD2E6F /* NxAddon.swift */; };
16+
3734968B2C77081100FD2E6F /* NxFunctionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3734968A2C77081100FD2E6F /* NxFunctionView.swift */; };
1517
379E276B2C76D40900624AA7 /* nx_iree.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 379E276A2C76D40900624AA7 /* nx_iree.cpp */; };
1618
459F92DE90F9275614EDC9F7 /* LiveViewNative in Frameworks */ = {isa = PBXBuildFile; productRef = 6767E5600DE50B2F89C488A9 /* LiveViewNative */; };
1719
82539B66B2DD23CF4560F655 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7BB2FC47EF2667DBC127B716 /* Preview Assets.xcassets */; };
@@ -22,6 +24,8 @@
2224

2325
/* Begin PBXFileReference section */
2426
0C32E6E8FE5182B70F4A8001 /* ReconnectingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReconnectingView.swift; sourceTree = "<group>"; };
27+
373496872C7707DE00FD2E6F /* NxAddon.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NxAddon.swift; sourceTree = "<group>"; };
28+
3734968A2C77081100FD2E6F /* NxFunctionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NxFunctionView.swift; sourceTree = "<group>"; };
2529
379E257A2C76CD5400624AA7 /* building.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = building.h; sourceTree = "<group>"; };
2630
379E257B2C76CD5400624AA7 /* debugging.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = debugging.h; sourceTree = "<group>"; };
2731
379E257C2C76CD5400624AA7 /* parsing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = parsing.h; sourceTree = "<group>"; };
@@ -423,6 +427,7 @@
423427
2F2E8465248E555C831C9B55 /* LiveNxIREE */ = {
424428
isa = PBXGroup;
425429
children = (
430+
373496892C7707F700FD2E6F /* NxAddon */,
426431
379E27692C76D3E500624AA7 /* c_src */,
427432
379E27432C76CD5400624AA7 /* nx_iree */,
428433
163C4DE8D68444A97E61DD40 /* Preview Content */,
@@ -434,10 +439,19 @@
434439
FB615E539217C456B9FBC1F5 /* LiveNxIREE.swift */,
435440
0C32E6E8FE5182B70F4A8001 /* ReconnectingView.swift */,
436441
379E27672C76D25900624AA7 /* LiveNxIREE-Bridging-Header.h */,
442+
373496872C7707DE00FD2E6F /* NxAddon.swift */,
437443
);
438444
path = LiveNxIREE;
439445
sourceTree = "<group>";
440446
};
447+
373496892C7707F700FD2E6F /* NxAddon */ = {
448+
isa = PBXGroup;
449+
children = (
450+
3734968A2C77081100FD2E6F /* NxFunctionView.swift */,
451+
);
452+
path = NxAddon;
453+
sourceTree = "<group>";
454+
};
441455
379E257D2C76CD5400624AA7 /* flatcc */ = {
442456
isa = PBXGroup;
443457
children = (
@@ -1714,9 +1728,11 @@
17141728
137E19B83B668B9C3130A3D7 /* ContentView.swift in Sources */,
17151729
0A6CE5F5167F6157FF061569 /* DisconnectedView.swift in Sources */,
17161730
E8ABDB597CE60B7A14F06131 /* ErrorView.swift in Sources */,
1731+
373496882C7707DE00FD2E6F /* NxAddon.swift in Sources */,
17171732
019462C5C187024761226CEE /* LiveNxIREE.swift in Sources */,
17181733
BFA36AAE5D8350C95692758F /* ReconnectingView.swift in Sources */,
17191734
379E276B2C76D40900624AA7 /* nx_iree.cpp in Sources */,
1735+
3734968B2C77081100FD2E6F /* NxFunctionView.swift in Sources */,
17201736
);
17211737
runOnlyForDeploymentPostprocessing = 0;
17221738
};
@@ -1727,6 +1743,7 @@
17271743
isa = XCBuildConfiguration;
17281744
buildSettings = {
17291745
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
1746+
CLANG_CXX_LANGUAGE_STANDARD = "c++17";
17301747
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
17311748
CLANG_WARN_BOOL_CONVERSION = YES;
17321749
CLANG_WARN_COMMA = YES;
@@ -1750,6 +1767,7 @@
17501767
ENABLE_STRICT_OBJC_MSGSEND = YES;
17511768
ENABLE_TESTABILITY = YES;
17521769
ENABLE_USER_SCRIPT_SANDBOXING = YES;
1770+
GCC_C_LANGUAGE_STANDARD = "compiler-default";
17531771
GCC_NO_COMMON_BLOCKS = YES;
17541772
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
17551773
GCC_WARN_ABOUT_RETURN_TYPE = YES;
@@ -1758,6 +1776,7 @@
17581776
GCC_WARN_UNUSED_FUNCTION = YES;
17591777
GCC_WARN_UNUSED_VARIABLE = YES;
17601778
GENERATE_INFOPLIST_FILE = YES;
1779+
HEADER_SEARCH_PATHS = "";
17611780
INFOPLIST_KEY_CFBundleDisplayName = LiveNxIREE;
17621781
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
17631782
INFOPLIST_KEY_WKCompanionAppBundleIdentifier = com.example.LiveNxIREE;
@@ -1776,6 +1795,7 @@
17761795
OTHER_LDFLAGS = "-lnx_iree_runtime";
17771796
"OTHER_LDFLAGS[arch=*]" = "";
17781797
SWIFT_OBJC_BRIDGING_HEADER = "$(PROJECT_NAME)/$(PROJECT_NAME)-Bridging-Header.h";
1798+
SYSTEM_HEADER_SEARCH_PATHS = "";
17791799
TVOS_DEPLOYMENT_TARGET = 16.0;
17801800
WATCHOS_DEPLOYMENT_TARGET = 9.0;
17811801
};
@@ -1784,8 +1804,11 @@
17841804
556320541024795EE191F9E8 /* Release */ = {
17851805
isa = XCBuildConfiguration;
17861806
buildSettings = {
1807+
CLANG_CXX_LANGUAGE_STANDARD = "c++17";
17871808
CLANG_ENABLE_MODULES = YES;
17881809
CLANG_ENABLE_OBJC_WEAK = YES;
1810+
GCC_C_LANGUAGE_STANDARD = "compiler-default";
1811+
HEADER_SEARCH_PATHS = "$(SRCROOT)/LiveNxIREE/nx_iree/include";
17891812
IPHONEOS_DEPLOYMENT_TARGET = 17.3;
17901813
LIBRARY_SEARCH_PATHS = (
17911814
"$(inherited)",
@@ -1805,15 +1828,19 @@
18051828
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
18061829
SUPPORTS_MACCATALYST = NO;
18071830
SWIFT_VERSION = 5.0;
1831+
SYSTEM_HEADER_SEARCH_PATHS = "";
18081832
TARGETED_DEVICE_FAMILY = 2;
18091833
};
18101834
name = Release;
18111835
};
18121836
5B0E672056F80B1EDCDCE967 /* Debug */ = {
18131837
isa = XCBuildConfiguration;
18141838
buildSettings = {
1839+
CLANG_CXX_LANGUAGE_STANDARD = "c++17";
18151840
CLANG_ENABLE_MODULES = YES;
18161841
CLANG_ENABLE_OBJC_WEAK = YES;
1842+
GCC_C_LANGUAGE_STANDARD = "compiler-default";
1843+
HEADER_SEARCH_PATHS = "$(SRCROOT)/LiveNxIREE/nx_iree/include";
18171844
IPHONEOS_DEPLOYMENT_TARGET = 17.3;
18181845
LIBRARY_SEARCH_PATHS = (
18191846
"$(inherited)",
@@ -1833,6 +1860,7 @@
18331860
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
18341861
SUPPORTS_MACCATALYST = NO;
18351862
SWIFT_VERSION = 5.0;
1863+
SYSTEM_HEADER_SEARCH_PATHS = "";
18361864
TARGETED_DEVICE_FAMILY = 2;
18371865
};
18381866
name = Debug;
@@ -1841,6 +1869,7 @@
18411869
isa = XCBuildConfiguration;
18421870
buildSettings = {
18431871
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
1872+
CLANG_CXX_LANGUAGE_STANDARD = "c++17";
18441873
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
18451874
CLANG_WARN_BOOL_CONVERSION = YES;
18461875
CLANG_WARN_COMMA = YES;
@@ -1863,6 +1892,7 @@
18631892
DEAD_CODE_STRIPPING = YES;
18641893
ENABLE_STRICT_OBJC_MSGSEND = YES;
18651894
ENABLE_USER_SCRIPT_SANDBOXING = YES;
1895+
GCC_C_LANGUAGE_STANDARD = "compiler-default";
18661896
GCC_NO_COMMON_BLOCKS = YES;
18671897
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
18681898
GCC_WARN_ABOUT_RETURN_TYPE = YES;
@@ -1871,6 +1901,7 @@
18711901
GCC_WARN_UNUSED_FUNCTION = YES;
18721902
GCC_WARN_UNUSED_VARIABLE = YES;
18731903
GENERATE_INFOPLIST_FILE = YES;
1904+
HEADER_SEARCH_PATHS = "";
18741905
INFOPLIST_KEY_CFBundleDisplayName = LiveNxIREE;
18751906
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
18761907
INFOPLIST_KEY_WKCompanionAppBundleIdentifier = com.example.LiveNxIREE;
@@ -1903,6 +1934,7 @@
19031934
OTHER_LDFLAGS = "-lnx_iree_runtime";
19041935
SWIFT_COMPILATION_MODE = wholemodule;
19051936
SWIFT_OBJC_BRIDGING_HEADER = "$(PROJECT_NAME)/$(PROJECT_NAME)-Bridging-Header.h";
1937+
SYSTEM_HEADER_SEARCH_PATHS = "";
19061938
TVOS_DEPLOYMENT_TARGET = 16.0;
19071939
WATCHOS_DEPLOYMENT_TARGET = 9.0;
19081940
};

liveview_native/live_nx_iree/native/swiftui/LiveNxIREE/ContentView.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ struct ContentView: View {
1515
production: URL(string: "https://example.com")!
1616
),
1717
addons: [
18-
.liveForm
18+
.liveForm,
19+
.nxAddon
1920
]
2021
) {
2122
ConnectingView()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// NxAddon.swift
3+
// LiveNxIREE
4+
//
5+
// Created by Paulo.Valente on 8/22/24.
6+
//
7+
8+
import LiveViewNative
9+
import SwiftUI
10+
11+
public extension Addons {
12+
@Addon
13+
struct NxAddon<Root: RootRegistry> {
14+
public enum TagName: String {
15+
case nxFunction = "NxFunction"
16+
}
17+
18+
@ViewBuilder
19+
public static func lookup(_ name: TagName, element: ElementNode) -> some View {
20+
switch name {
21+
case .nxFunction:
22+
NxFunctionView<Root>()
23+
}
24+
}
25+
}
26+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// NxFunction.swift
3+
// LiveNxIREE
4+
//
5+
// Created by Paulo.Valente on 8/22/24.
6+
//
7+
8+
import SwiftUI
9+
import LiveViewNative
10+
11+
struct NxFunctionView<Root: RootRegistry>: View {
12+
var body: some View {
13+
Text("NxFunction Component")
14+
.padding()
15+
}
16+
}
17+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// NxInputView.swift
3+
// LiveNxIREE
4+
//
5+
// Created by Paulo.Valente on 8/22/24.
6+
//
7+
8+
import SwiftUI
9+
10+
struct NxInputView: View {
11+
var body: some View {
12+
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
13+
}
14+
}
15+
16+
#Preview {
17+
NxInputView()
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// NxOutputView.swift
3+
// LiveNxIREE
4+
//
5+
// Created by Paulo.Valente on 8/22/24.
6+
//
7+
8+
import SwiftUI
9+
10+
struct NxOutputView: View {
11+
var body: some View {
12+
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
13+
}
14+
}
15+
16+
#Preview {
17+
NxOutputView()
18+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//
2+
// NxIREECppBridge.swift
3+
// LiveNxIREE
4+
//
5+
// Created by Paulo.Valente on 8/22/24.
6+
//
7+
8+
import SwiftUI
9+
10+
struct NxIREECppBridge {
11+
12+
}

liveview_native/live_nx_iree/native/swiftui/LiveNxIREE/c_src/nx_iree.cpp

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,51 @@
66
//
77

88
#include "nx_iree.h"
9-
#include "nx_iree/runtime.h"
109

11-
extern "C" {
10+
#include <string>
11+
#include <vector>
1212

13-
int nx_iree_initialize(iree_vm_instance_t* instance, iree_hal_driver_registry_t* driver_registry, iree_hal_device_t* device) {
13+
int func(int x) {
14+
return x;
15+
}
16+
17+
/*
18+
int nx_iree_initialize(iree_vm_instance_t* vm_instance, iree_hal_driver_registry_t* driver_registry, iree_hal_device_t* device, char* device_uri, char* error_message) {
19+
vm_instance = create_instance();
20+
driver_registry = get_driver_registry();
21+
auto status = register_all_drivers(driver_registry);
22+
23+
if (!is_ok(status)) {
24+
if (error_message) {
25+
std::string msg = get_status_message(status);
26+
strncpy(error_message, msg.c_str(), msg.length());
27+
}
28+
29+
return 1;
30+
}
31+
32+
33+
device = create_device(std::string(device_uri));
34+
35+
if (!device) {
36+
const char* msg = "Unable to initialize device\0";
37+
strncpy(error_message, msg, strlen(msg));
38+
return 1;
39+
}
1440
41+
return 0;
1542
}
1643
17-
int nx_iree_call(uint64_t bytecode_size, char* bytecode, uint64_t num_inputs, char** serialized_inputs, uint64_t num_outputs, char** serialized_outputs, char* error_message) {
18-
std::vector<iree::runtime::IREETensor> inputs;
44+
int nx_iree_call(iree_vm_instance_t* vm_instance, iree_hal_device_t* device, uint64_t bytecode_size, unsigned char* bytecode, uint64_t num_inputs, char** serialized_inputs, uint64_t num_outputs, char** serialized_outputs, char* error_message) {
45+
std::vector<iree::runtime::IREETensor*> inputs;
1946
2047
for (size_t i = 0; i < num_inputs; i++) {
21-
inputs.push_back(iree::runtime::IREETensor(serialized_inputs[i]));
48+
inputs.push_back(new iree::runtime::IREETensor(serialized_inputs[i]));
2249
}
2350
24-
auto [status, optional_result] = call(vm_instance, device, driver_name, static_cast<size_t>(bytecode_size), inputs);
25-
51+
// driver name is hardcoded because there is only a check for CUDA
52+
auto [status, optional_result] = call(vm_instance, device, "not_cuda", bytecode, static_cast<size_t>(bytecode_size), inputs);
53+
2654
if (!is_ok(status)) {
2755
if (error_message) {
2856
std::string msg = get_status_message(status);
@@ -34,12 +62,15 @@ int nx_iree_call(uint64_t bytecode_size, char* bytecode, uint64_t num_inputs, ch
3462
3563
serialized_outputs = new char*[num_outputs];
3664
65+
auto result = optional_result.value();
3766
for (size_t i = 0; i < num_outputs; i++) {
38-
std::vector<char> *serialized = optional_result.value().serialize();
67+
std::vector<char> *serialized = result[i]->serialize();
3968
serialized_outputs[i] = new char[serialized->size()];
4069
memcpy(serialized_outputs[i], serialized->data(), serialized->size());
4170
}
4271
4372
return 0;
4473
}
74+
4575
}
76+
*/

liveview_native/live_nx_iree/native/swiftui/LiveNxIREE/c_src/nx_iree.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,20 @@
88
#ifndef nx_iree_h
99
#define nx_iree_h
1010

11-
#include <cstdint>
11+
#include <iree/hal/api.h>
12+
#include <iree/vm/api.h>
1213

14+
#ifdef __cplusplus
1315
extern "C" {
14-
int nx_iree_initialize(iree_vm_instance_t* instance, iree_hal_driver_registry_t* driver_registry, iree_hal_device_t* device);
15-
int nx_iree_call(uint64_t bytecode_size, char* bytecode, uint64_t num_inputs, char** serialized_inputs, uint64_t num_outputs, char** serialized_outputs, char* error_message);
16+
#endif
17+
18+
int nx_iree_initialize(iree_vm_instance_t* vm_instance, iree_hal_driver_registry_t* driver_registry, iree_hal_device_t* device, char* device_uri, char* error_message);
19+
int nx_iree_call(iree_vm_instance_t* vm_instance, iree_hal_device_t* device, uint64_t bytecode_size, unsigned char* bytecode, uint64_t num_inputs, char** serialized_inputs, uint64_t num_outputs, char** serialized_outputs, char* error_message);
20+
21+
22+
#ifdef __cplusplus
1623
}
24+
#endif
25+
1726

1827
#endif /* nx_iree_h */

0 commit comments

Comments
 (0)