-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix
Swift
umbrella header includes (#19)
* feat: Try bridge more Swift * Make all Promises `async` in swift * Rename `Promise` to `JSPromise` * Update JSPromise.hpp * Update JSICache.cpp * fix import * fix: Init props * fix: Remove AnyMap and ArrayBuffer apis for now * fix import * no more async? idk * feat: Convert `std::optional<T>` to `swift::Optional<T>` * Remove all funcs except hello * fix: Generate Swift Umbrella header * fix: Organize * fix: Hardcode forward-decl * feat: Properly generate umbrella header from known types * fix: Fix indentation * order * feat: Try bridging some primitives over... * Update NitroDefines.hpp * Update Property.ts * fallthrough looks better * better error * fix: Fix wrong enum `maxLength` * feat: Try `CarSwift` experiment * Revert "feat: Try `CarSwift` experiment" This reverts commit 7794f38.
- Loading branch information
Showing
86 changed files
with
686 additions
and
1,382 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
packages/nitrogen/src/autolinking/createSwiftUmbrellaHeader.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { NitroConfig } from '../config/NitroConfig.js' | ||
import { getForwardDeclaration } from '../syntax/c++/getForwardDeclaration.js' | ||
import { includeHeader } from '../syntax/c++/includeNitroHeader.js' | ||
import { getAllKnownTypes } from '../syntax/createType.js' | ||
import { getHybridObjectName } from '../syntax/getHybridObjectName.js' | ||
import { createFileMetadataString, isNotDuplicate } from '../syntax/helpers.js' | ||
import type { SourceFile } from '../syntax/SourceFile.js' | ||
import { getTypeAs } from '../syntax/types/getTypeAs.js' | ||
import { HybridObjectType } from '../syntax/types/HybridObjectType.js' | ||
|
||
export function createSwiftUmbrellaHeader(): SourceFile { | ||
const moduleName = NitroConfig.getIosModuleName() | ||
const filename = `${moduleName}-Swift-Cxx-Umbrella.hpp` | ||
|
||
const types = getAllKnownTypes() | ||
|
||
const swiftForwardDeclares = types | ||
.filter((t) => t.kind === 'hybrid-object') | ||
.map((t) => { | ||
const hybridObjectType = getTypeAs(t, HybridObjectType) | ||
const name = getHybridObjectName(hybridObjectType.hybridObjectName) | ||
return getForwardDeclaration('class', name.HybridTSpecCxx, moduleName) | ||
}) | ||
.filter(isNotDuplicate) | ||
|
||
const imports = types.flatMap((t) => t.getRequiredImports()) | ||
const forwardDeclarations = imports | ||
.map((i) => i.forwardDeclaration) | ||
.filter((f) => f != null) | ||
.filter(isNotDuplicate) | ||
const includes = imports.map((i) => includeHeader(i)).filter(isNotDuplicate) | ||
|
||
const code = ` | ||
${createFileMetadataString(filename, '///')} | ||
#pragma once | ||
// Forward declarations of C++ defined types | ||
${forwardDeclarations.sort().join('\n')} | ||
// Include C++ defined types | ||
${includes.sort().join('\n')} | ||
// Forward declarations of Swift defined types | ||
${swiftForwardDeclares.sort().join('\n')} | ||
// Include Swift defined types | ||
#if __has_include("${moduleName}-Swift.h") | ||
#include "${moduleName}-Swift.h" | ||
#else | ||
#error ${moduleName}'s autogenerated Swift header cannot be found! Make sure the Swift module's name is actually "${moduleName}", and try building the app first. | ||
#endif | ||
` | ||
|
||
return { | ||
content: code, | ||
language: 'c++', | ||
name: filename, | ||
platform: 'ios', | ||
subdirectory: [], | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.