Skip to content

Commit 4cfda4c

Browse files
committed
feat: basic swift bindings
1 parent 62d15e3 commit 4cfda4c

File tree

15 files changed

+1177
-0
lines changed

15 files changed

+1177
-0
lines changed

Makefile.toml

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
[config]
2+
skip_core_tasks = true
3+
skip_git_env_info = true
4+
init_task = "init"
5+
6+
[env]
7+
CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true
8+
CARGO_MAKE_CARGO_VERBOSE_FLAGS = { source = "${CARGO_MAKE_CI}", default_value = "", mapping = { "true" = "--verbose" } }
9+
CARGO_MAKE_RUST_SCRIPT_PROVIDER = "rust-script"
10+
CARGO_MAKE_USE_WORKSPACE_PROFILE = true
11+
CARGO_MAKE_CARGO_BUILD_TEST_FLAGS = "--no-fail-fast"
12+
CARGO_TARGET_DIR = { value = "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/target", condition = { env_not_set = ["CARGO_TARGET_DIR"] } }
13+
CARGO_MAKE_TOOLCHAIN_DEFAULT = { source = "${CARGO_MAKE_CI}", default_value = "nightly", mapping = { "true" = "nightly-2022-08-08", "false" = "nightly" } }
14+
CARGO_MAKE_TOOLCHAIN = { value = "${CARGO_MAKE_TOOLCHAIN_DEFAULT}", condition = { env_not_set = ["CARGO_MAKE_TOOLCHAIN"] } }
15+
CARGO_BUILD_TYPE = { source = "${CARGO_MAKE_PROFILE}", default_value = "debug", mapping = { "dev" = "debug", "release" = "release" } }
16+
BACKTRACE_DEFAULT = { source = "${CARGO_MAKE_CI}", mapping = { "true" = "1", "false" = "0" } }
17+
RUST_BACKTRACE = { value = "${BACKTRACE_DEFAULT}", condition = { env_not_set = ["RUST_BACKTRACE"] } }
18+
19+
[tasks.init]
20+
condition = { env_set = ["VERBOSE"] }
21+
run_task = "print-env"
22+
23+
[tasks.default]
24+
description = "Empty Task"
25+
26+
[tasks.print-env]
27+
category = "Tools"
28+
run_task = [{ name = ["print-build-env", "print-ci-env", "print-rust-env", "print-cargo-env"] }]
29+
30+
[tasks.print-build-env]
31+
private = true
32+
script = [
33+
'''
34+
#!@duckscript
35+
echo "*************************************"
36+
echo "Build Environment:"
37+
echo " Task: ${CARGO_MAKE_TASK}"
38+
echo " Task Arguments: ${CARGO_MAKE_TASK_ARGS}"
39+
echo " Command: ${CARGO_MAKE_COMMAND}"
40+
echo " Working Directory: ${CARGO_MAKE_WORKING_DIRECTORY}"
41+
echo " Target Directory: ${CARGO_TARGET_DIR}"
42+
echo " Target Triple: ${CARGO_MAKE_RUST_TARGET_TRIPLE}"
43+
echo ""
44+
echo " RUST_BACKTRACE: ${RUST_BACKTRACE}"
45+
echo "*************************************"
46+
'''
47+
]
48+
49+
[tasks.print-ci-env]
50+
private = true
51+
condition = { env = { "CARGO_MAKE_CI" = "true" } }
52+
script = [
53+
'''
54+
#!@duckscript
55+
echo "*************************************"
56+
echo "CI:"
57+
echo " CI: ${CARGO_MAKE_CI}"
58+
echo " PR: ${CARGO_MAKE_PR}"
59+
echo " Branch Name: ${CARGO_MAKE_CI_BRANCH_NAME}"
60+
echo " CI Vendor: ${CARGO_MAKE_CI_VENDOR}"
61+
echo "*************************************"
62+
'''
63+
]
64+
65+
[tasks.print-rust-env]
66+
category = "Tools"
67+
condition = { env_set = [ "CARGO_MAKE_RUST_CHANNEL" ] }
68+
script = [
69+
'''
70+
#!@duckscript
71+
echo "*************************************"
72+
echo "Rust:"
73+
echo " Version: ${CARGO_MAKE_RUST_VERSION}"
74+
echo " Channel: ${CARGO_MAKE_RUST_CHANNEL}"
75+
echo " Toolchain: ${CARGO_MAKE_TOOLCHAIN}"
76+
echo " Target Arch: ${CARGO_MAKE_RUST_TARGET_ARCH}"
77+
echo " Target Env: ${CARGO_MAKE_RUST_TARGET_ENV}"
78+
echo " Target OS: ${CARGO_MAKE_RUST_TARGET_OS}"
79+
echo " Pointer Width: ${CARGO_MAKE_RUST_TARGET_POINTER_WIDTH}"
80+
echo " Target Triple: ${CARGO_MAKE_RUST_TARGET_TRIPLE}"
81+
echo "*************************************"
82+
'''
83+
]
84+
85+
[tasks.print-cargo-env]
86+
category = "Tools"
87+
condition = { env_set = [ "CARGO_MAKE_CARGO_HOME" ] }
88+
script = [
89+
'''
90+
#!@duckscript
91+
echo "*************************************"
92+
echo "Cargo:"
93+
echo " Home: ${CARGO_MAKE_CARGO_HOME}"
94+
echo " Profile: ${CARGO_MAKE_CARGO_PROFILE}"
95+
echo "*************************************"
96+
'''
97+
]
98+
99+
[tasks.check]
100+
category = "Build"
101+
description = "Runs cargo check"
102+
command = "rustup"
103+
args = ["run", "${CARGO_MAKE_TOOLCHAIN}", "cargo", "check", "${@}"]
104+
105+
[tasks.build]
106+
category = "Build"
107+
description = "Runs cargo build"
108+
command = "rustup"
109+
args = ["run", "${CARGO_MAKE_TOOLCHAIN}", "cargo", "build", "--", "@@remove-empty(CARGO_MAKE_CARGO_VERBOSE_FLAGS)", "${@}"]
110+
111+
[tasks.swift]
112+
workspace = false
113+
category = "Build"
114+
description = "Builds the Swift package"
115+
command = "swift"
116+
args = ["build", "--package-path", "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/swift/LiveViewNative", "--scratch-path", "${CARGO_TARGET_DIR}/swift/.build"]
117+
dependencies = ["build-xcframework"]
118+
119+
[tasks.build-xcframework]
120+
workspace = false
121+
category = "Packaging"
122+
description = "Generates the LiveViewNativeCore.xcframework package"
123+
command = "xcodebuild"
124+
args = [
125+
"-create-xcframework",
126+
"-library", "${CARGO_TARGET_DIR}/aarch64-apple-darwin/debug/libliveview_native_core.a",
127+
"-headers", "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/swift/LiveViewNativeCore/include",
128+
"-library", "${CARGO_TARGET_DIR}/aarch64-apple-ios/debug/libliveview_native_core.a",
129+
"-headers", "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/swift/LiveViewNativeCore/include",
130+
"-library", "${CARGO_TARGET_DIR}/aarch64-apple-ios-sim/debug/libliveview_native_core.a",
131+
"-headers", "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/swift/LiveViewNativeCore/include",
132+
"-output", "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/swift/LiveViewNative/LiveViewNativeCore.xcframework"
133+
]
134+
dependencies = ["build-universal-macos", "build-universal-ios", "remove-existing-xcframework"]
135+
136+
[tasks.remove-existing-xcframework]
137+
workspace = false
138+
private = true
139+
script_runner = "@duckscript"
140+
script = "rm -r ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/swift/LiveViewNative/LiveViewNativeCore.xcframework"
141+
142+
[tasks.build-universal-macos]
143+
workspace = false
144+
category = "Build"
145+
description = "Compiles for all targets needed to produce a universal library for macOS"
146+
command = "rustup"
147+
args = ["run", "${CARGO_MAKE_TOOLCHAIN}", "cargo", "build", "@@remove-empty(CARGO_MAKE_CARGO_VERBOSE_FLAGS)", "--target", "aarch64-apple-darwin", "--target", "x86_64-apple-darwin", "-p", "liveview-native-core"]
148+
dependencies = ["install-targets"]
149+
150+
[tasks.package-universal-macos]
151+
workspace = false
152+
category = "Packaging"
153+
description = "Produces a universal library for macOS"
154+
command = "lipo"
155+
args = ["${CARGO_TARGET_DIR}/aarch64-apple-darwin/debug/libliveview_native_core.a", "${CARGO_TARGET_DIR}/x86_64-apple-darwin/debug/libliveview_native_core.a", "-create", "-output", "${CARGO_TARGET_DIR}/universal-macos/debug/libliveview_native_core.a"]
156+
dependencies = ["build-universal-macos"]
157+
158+
[tasks.build-universal-ios]
159+
workspace = false
160+
category = "Build"
161+
description = "Compiles for all targets needed to produce a universal library for iOS"
162+
command = "rustup"
163+
args = ["run", "${CARGO_MAKE_TOOLCHAIN}", "cargo", "build", "@@remove-empty(CARGO_MAKE_CARGO_VERBOSE_FLAGS)", "--target", "aarch64-apple-ios", "--target", "aarch64-apple-ios-sim", "--target", "x86_64-apple-ios", "-p", "liveview-native-core"]
164+
dependencies = ["prepare-targets"]
165+
166+
[tasks.package-universal-ios]
167+
workspace = false
168+
category = "Packaging"
169+
description = "Produces a universal library for iOS"
170+
command = "lipo"
171+
args = ["${CARGO_TARGET_DIR}/aarch64-apple-ios/debug/libliveview_native_core.a", "${CARGO_TARGET_DIR}/x86_64-apple-ios/debug/libliveview_native_core.a", "-create", "-output", "${CARGO_TARGET_DIR}/universal-ios/debug/libliveview_native_core.a"]
172+
dependencies = ["build-universal-ios"]
173+
174+
[tasks.prepare-targets]
175+
workspace = false
176+
private = true
177+
run_task = { name = ["install-targets", "create-universal-targets"], parallel = true }
178+
179+
[tasks.install-targets]
180+
workspace = false
181+
private = true
182+
description = "Installs all toolchain targets needed for packaging"
183+
command = "rustup"
184+
args = ["target", "add", "--toolchain", "${CARGO_MAKE_TOOLCHAIN}", "aarch64-apple-darwin", "x86_64-apple-darwin", "aarch64-apple-ios", "aarch64-apple-ios-sim", "x86_64-apple-ios"]
185+
186+
[tasks.create-universal-targets]
187+
workspace = false
188+
private = true
189+
script_runner = "@duckscript"
190+
script = '''
191+
macos_dir = set "${CARGO_TARGET_DIR}/universal-macos/${CARGO_BUILD_TYPE}"
192+
ios_dir = set "${CARGO_TARGET_DIR}/universal-ios/${CARGO_BUILD_TYPE}"
193+
194+
echo Creating ${macos_dir}
195+
mkdir ${macos_dir}
196+
197+
echo "Creating ${ios_dir}"
198+
mkdir "${ios_dir}"
199+
'''
200+
201+
[tasks.clean]
202+
category = "Build"
203+
description = "Clean build artifacts"
204+
command = "cargo"
205+
args = ["clean"]
206+
207+
[tasks.test]
208+
category = "Test"
209+
description = "Runs all tests"
210+
dependencies = ["test-rust"]
211+
212+
[tasks.test-rust]
213+
category = "Test"
214+
description = "Runs tests written in Rust"
215+
command = "rustup"
216+
args = ["run", "${CARGO_MAKE_TOOLCHAIN}", "cargo", "test", "@@remove-empty(CARGO_MAKE_CARGO_VERBOSE_FLAGS)", "@@split(CARGO_MAKE_CARGO_BUILD_TEST_FLAGS, )", "${@}"]
217+
218+
[tasks.bloat]
219+
category = "Development"
220+
description = "Run cargo-bloat"
221+
command = "cargo"
222+
args = ["bloat", "${@}"]

crates/core/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ publish.workspace = true
1515

1616
build = "build.rs"
1717

18+
[lib]
19+
crate-type = ["staticlib", "rlib"]
20+
1821
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1922

2023
[dependencies]
@@ -23,6 +26,7 @@ fixedbitset = "0.4"
2326
fxhash = "0.2"
2427
html5gum = "0.5"
2528
intrusive-collections = { version = "0.9", features = ["nightly"] }
29+
indexmap = { version = "1.7", features = ["std"] }
2630
lazy_static = "1.4"
2731
petgraph = { version = "0.6", default-features = false, features = ["graphmap"] }
2832
smallvec = { version = "1.9", features = ["union", "const_generics", "specialization"] }

crates/core/src/dom/attribute.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ impl AttributeValue {
6464
Self::String(s) => s.to_string(),
6565
}
6666
}
67+
68+
pub fn as_str(&self) -> Option<&str> {
69+
match self {
70+
Self::None => None,
71+
Self::String(s) => Some(s.as_str()),
72+
}
73+
}
6774
}
6875
impl From<&str> for AttributeValue {
6976
#[inline]

0 commit comments

Comments
 (0)