- 
                Notifications
    You must be signed in to change notification settings 
- Fork 10.6k
[Macros] Add support for wasm macros #73031
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
      
            kabiroberai
  wants to merge
  132
  commits into
  swiftlang:main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
kabiroberai:kabir/wasm-plugins
  
      
      
   
  
    
  
  
  
 
  
      
    base: main
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
      
        
          +1,084
        
        
          −23
        
        
          
        
      
    
  
  
     Open
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            132 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      e5c191d
              
                wip
              
              
                kabiroberai e5342e7
              
                wip
              
              
                kabiroberai d5d1cb7
              
                wip
              
              
                kabiroberai f776c28
              
                revert swift-plugin-server
              
              
                kabiroberai 43fc233
              
                use jsc in-proc
              
              
                kabiroberai 961fd54
              
                Allow wasm in sandbox, don’t disable it
              
              
                kabiroberai a771631
              
                fix warning, prune version check
              
              
                kabiroberai 3f8ef81
              
                Factor out JSCWasmPlugin
              
              
                kabiroberai 23426e0
              
                the continuation just... works now?
              
              
                kabiroberai 9fe505f
              
                more tweaks to JSCWasmPlugin
              
              
                kabiroberai 89158e2
              
                Create SwiftPluginServerSupport
              
              
                kabiroberai f084e25
              
                JSCWasmPlugin: memoize, improve errors
              
              
                kabiroberai 5ef86da
              
                steps towards x-plat
              
              
                kabiroberai 02f4324
              
                more modularity
              
              
                kabiroberai bddde66
              
                Add wasm-plugin-server-path frontend opt
              
              
                kabiroberai ca22e2d
              
                Start adding WasmKit support
              
              
                kabiroberai 6a9bbe7
              
                Update WasmKitPlugin
              
              
                kabiroberai e598064
              
                safety, tweaks
              
              
                kabiroberai 7d1510e
              
                tweaks to JSC
              
              
                kabiroberai 37b8a61
              
                Merge remote-tracking branch 'upstream/main' into kabir/wasm-plugins
              
              
                kabiroberai da74f38
              
                Proper WasmKit integration
              
              
                kabiroberai 7a18da2
              
                tweaks
              
              
                kabiroberai 1076b16
              
                Check ABI version
              
              
                kabiroberai 805c659
              
                Merge remote-tracking branch 'upstream/main' into kabir/wasm-plugins
              
              
                kabiroberai 4527842
              
                move ABI check into WasmEnginePlugin
              
              
                kabiroberai f9dbbb1
              
                build fixes
              
              
                kabiroberai 6511672
              
                Elide copies of wasm blob
              
              
                kabiroberai dd481fe
              
                fix duplicate libraries warning
              
              
                kabiroberai 4ce4749
              
                Merge remote-tracking branch 'upstream/main' into kabir/wasm-plugins
              
              
                kabiroberai 482871c
              
                add SWIFT_WASM_USE_JSC
              
              
                kabiroberai 771acb0
              
                Merge remote-tracking branch 'upstream/main' into kabir/wasm-plugins
              
              
                kabiroberai 2460e98
              
                Skip wasmkit CLI for now
              
              
                kabiroberai 150f3d2
              
                Or actually build wasmkit-cli
              
              
                kabiroberai 34ed5b0
              
                use stdio for ipc
              
              
                kabiroberai 94d525e
              
                No need for memory witness
              
              
                kabiroberai a99f6b3
              
                Byte-swap length if needed
              
              
                kabiroberai c5dc6bd
              
                Improve error handling
              
              
                kabiroberai 6375faf
              
                Merge branch 'main' into kabir/wasm-plugins
              
              
                kabiroberai 826a80f
              
                Fix linkage
              
              
                kabiroberai f053859
              
                No C dep needed for wasm
              
              
                kabiroberai 6c0b40c
              
                Drop foundation (mostly); lower min os
              
              
                kabiroberai d72e165
              
                More foundation pruning
              
              
                kabiroberai 564f844
              
                interop mode cxx -> c
              
              
                kabiroberai a670f32
              
                Target
              
              
                kabiroberai aaaaae3
              
                tweaks
              
              
                kabiroberai 7b16cbd
              
                We don’t need WasmKitPluginError
              
              
                kabiroberai 7d9d015
              
                Change wasm versioning approach
              
              
                kabiroberai ea81405
              
                Merge branch 'main' into kabir/wasm-plugins
              
              
                kabiroberai b472f4f
              
                Merge branch 'main' into kabir/wasm-plugins
              
              
                kabiroberai 3baf627
              
                Merge branch 'main' into kabir/wasm-plugins
              
              
                kabiroberai eee48e0
              
                swift-wasm-plugin-server => swift-plugin-server
              
              
                kabiroberai 4fca102
              
                swift-plugin-server doesn’t need a product
              
              
                kabiroberai d465d36
              
                We don’t need Dispatch here
              
              
                kabiroberai c4efcee
              
                Improve diagnostics
              
              
                kabiroberai b3f53c2
              
                Remove JSC for now
              
              
                kabiroberai b629484
              
                Explicitly depend on System
              
              
                kabiroberai af2b87e
              
                Nevermind SwiftPM didn’t like that
              
              
                kabiroberai bbb916c
              
                Lower swift-tools-version
              
              
                kabiroberai 77c273f
              
                Fix WASI dep
              
              
                kabiroberai b56e28a
              
                Add missing header
              
              
                kabiroberai 94f0ad7
              
                Merge branch 'main' into kabir/wasm-plugins
              
              
                kabiroberai 14b5b79
              
                Include position in diagnostics if possible
              
              
                kabiroberai af68825
              
                Merge branch 'main' into kabir/wasm-plugins
              
              
                kabiroberai 92aef4e
              
                this comment is now stale
              
              
                kabiroberai 9b1e4ee
              
                No wasm_plugin_server_path
              
              
                kabiroberai f93df4d
              
                Remove debug code
              
              
                kabiroberai 95f254c
              
                error_load_plugin diagnostic
              
              
                kabiroberai ca27b45
              
                Merge branch 'main' into kabir/wasm-plugins
              
              
                kabiroberai caa1a8c
              
                Elide copy
              
              
                kabiroberai 2ee417f
              
                Merge branch 'main' into kabir/wasm-plugins
              
              
                kabiroberai fa52ecd
              
                Feedback
              
              
                kabiroberai f2f2ea2
              
                nit
              
              
                kabiroberai c0a75e1
              
                record ServerPath
              
              
                kabiroberai 011a0a5
              
                Basic test
              
              
                kabiroberai d2d3b94
              
                Parameterize
              
              
                kabiroberai e2a455a
              
                Merge branch 'main' into kabir/wasm-plugins
              
              
                kabiroberai b307eb4
              
                Fix deprecation warning
              
              
                kabiroberai 782956a
              
                working test
              
              
                kabiroberai 8a88dc5
              
                simplify
              
              
                kabiroberai fcb838d
              
                remove wasm_sdk_root
              
              
                kabiroberai 469d84a
              
                error tests
              
              
                kabiroberai cc41cf1
              
                Update WasmKit to 0.0.5
              
              
                kateinoigakukun 7499295
              
                Merge branch 'main' into kabir/wasm-plugins
              
              
                kabiroberai e89fd6a
              
                post-merge fixup
              
              
                kabiroberai 2b47724
              
                no opaque types
              
              
                kabiroberai 4285cf1
              
                tentative fix for lldb build
              
              
                kabiroberai 56b6cae
              
                don’t depend on ArgumentParser
              
              
                kabiroberai 96363e1
              
                temporarily update wasmkit checkout
              
              
                kabiroberai 913041b
              
                Revert "temporarily update wasmkit checkout"
              
              
                kateinoigakukun 6cd389e
              
                Update WasmKit to 0.0.6
              
              
                kateinoigakukun c3f4276
              
                [test] Annotate macro tests that require the WebAssembly code generator
              
              
                kateinoigakukun 4341058
              
                Update WasmKit to 0.0.7
              
              
                kateinoigakukun 393933a
              
                Add temporary workaround for Windows pipe support of swift-system
              
              
                kateinoigakukun 9c5e7fc
              
                [test] Remove usage of unused lit variables for building wasm plugins
              
              
                kateinoigakukun 5890c3e
              
                Change the first `-load-plugin` path separator from `:` to `#`
              
              
                kateinoigakukun 0f39ec8
              
                [test] Fix path segment separator of plugin path for Windows
              
              
                kateinoigakukun 48dd97f
              
                Merge branch 'main' into kabir/wasm-plugins
              
              
                MaxDesiatov c3f41c7
              
                Merge branch 'main' into kabir/wasm-plugins
              
              
                MaxDesiatov ee82b85
              
                Merge branch 'main' of github.com:apple/swift into kabir/wasm-plugins
              
              
                MaxDesiatov 1dcdd7b
              
                Merge branch 'main' of github.com:apple/swift into kabir/wasm-plugins
              
              
                MaxDesiatov 6e56934
              
                Attempt to use `main` branch of WasmKit
              
              
                MaxDesiatov dd13597
              
                Merge branch 'main' into kabir/wasm-plugins
              
              
                kabiroberai 5770553
              
                Revert wasmkit bump
              
              
                kabiroberai 94f870c
              
                Merge branch 'main' into kabir/wasm-plugins
              
              
                MaxDesiatov ed54400
              
                Bump WasmKit to 0.1.0 in `update-checkout-config.json`
              
              
                MaxDesiatov d568d67
              
                Update for WasmKit 0.1.0 API
              
              
                MaxDesiatov 75bd7ca
              
                Fix missing imports in `WasmKitEngine.swift`
              
              
                MaxDesiatov c1e928d
              
                Bump wasmkit to 0.1.1 to enable WMO
              
              
                kateinoigakukun 0d2c140
              
                Merge remote-tracking branch 'origin/main' into kabir/wasm-plugins
              
              
                kateinoigakukun 7683e83
              
                Bump WasmKit to 0.1.2 in `update-checkout-config.json`
              
              
                MaxDesiatov e0427b2
              
                Bump stack size in `WasmKitEngine.swift` to avoid OOB
              
              
                MaxDesiatov be04533
              
                Merge branch 'main' of github.com:apple/swift into kabir/wasm-plugins
              
              
                MaxDesiatov 1852df9
              
                Remove outdated use of `PluginSearchOption::LoadPlugin`
              
              
                MaxDesiatov e49c980
              
                Bump WasmKit to 0.1.3 in `update-checkout-config.json`
              
              
                MaxDesiatov 052058a
              
                Remove outdated `case OPT_load_plugin` in `CompilerInvocation.cpp`
              
              
                MaxDesiatov f860528
              
                Remove outdated use of `LoadPlugin` from `swift-ide-test.cpp`
              
              
                MaxDesiatov 28a9efa
              
                Update lit tests to use `-load-resolved-plugin`
              
              
                MaxDesiatov 19eef9a
              
                Merge branch 'main' of github.com:apple/swift into kabir/wasm-plugins
              
              
                MaxDesiatov db325e8
              
                Merge branch 'main' of github.com:apple/swift into kabir/wasm-plugins
              
              
                MaxDesiatov 54eb483
              
                Adopt new `shutDown` API introduced in `swift-syntax`
              
              
                MaxDesiatov 224ac09
              
                Add a trivial echo macro test to the package
              
              
                MaxDesiatov dc8cd3c
              
                Test `WasmEnginePlugin` APIs in `WasmEngineTests`
              
              
                MaxDesiatov 6817517
              
                Merge branch 'main' of github.com:apple/swift into kabir/wasm-plugins
              
              
                MaxDesiatov f56ec6a
              
                Make formatting consistent in `swift-plugin-server`
              
              
                MaxDesiatov 1626ad8
              
                Create stdin/stdout pipes for plugins with `mkfifo`
              
              
                MaxDesiatov 4204eef
              
                Clean up temp Wasm fixture file in `WasmEngineTests`
              
              
                MaxDesiatov 1cf1e20
              
                Make `init` parameter names more explicit in `WasmEngine`
              
              
                MaxDesiatov 6277098
              
                Merge branch 'main' into kabir/wasm-plugins
              
              
                MaxDesiatov 0da4f22
              
                Remove use of named pipes as engine-specific
              
              
                MaxDesiatov 3991b60
              
                Fix renaming in `tools/swift-plugin-server/CMakeLists.txt`
              
              
                MaxDesiatov 636fa0e
              
                Fix Windows compatibility
              
              
                MaxDesiatov f915c05
              
                Merge branch 'main' of github.com:apple/swift into kabir/wasm-plugins
              
              
                MaxDesiatov File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or 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 hidden or 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 hidden or 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,55 @@ | ||
| // definitions from | ||
| // https://github.com/WebAssembly/wasi-libc/blob/320bbbcced68ce8e564b0dc4c8f80a5a5ad21a9c/libc-bottom-half/headers/public/wasi/api.h | ||
|  | ||
| typedef unsigned char uint8_t; | ||
| typedef unsigned short uint16_t; | ||
| typedef unsigned int uint32_t; | ||
| typedef unsigned long long uint64_t; | ||
|  | ||
| typedef uint8_t wasi_signal_t; | ||
| typedef uint16_t wasi_errno_t; | ||
| typedef uint32_t wasi_exitcode_t; | ||
| typedef int wasi_fd_t; | ||
| typedef __SIZE_TYPE__ wasi_size_t; | ||
|  | ||
| typedef struct wasi_ciovec_t { | ||
| const uint8_t *buf; | ||
| wasi_size_t buf_len; | ||
| } wasi_ciovec_t; | ||
|  | ||
| wasi_errno_t wasi_fd_write( | ||
| wasi_fd_t fd, | ||
| const wasi_ciovec_t *iovs, | ||
| wasi_size_t iovs_len, | ||
| wasi_size_t *nwritten | ||
| ) __attribute__(( | ||
| __import_module__("wasi_snapshot_preview1"), | ||
| __import_name__("fd_write"), | ||
| __warn_unused_result__ | ||
| )); | ||
|  | ||
| _Noreturn void wasi_proc_exit( | ||
| wasi_exitcode_t code | ||
| ) __attribute__(( | ||
| __import_module__("wasi_snapshot_preview1"), | ||
| __import_name__("proc_exit") | ||
| )); | ||
|  | ||
| // libc shims | ||
|  | ||
| static inline wasi_size_t swift_strlen(const char *buf) { | ||
| wasi_size_t len = 0; | ||
| while (buf[len]) len++; | ||
| return len; | ||
| } | ||
|  | ||
| static inline wasi_errno_t swift_write(int fd, const void *buf, wasi_size_t len) { | ||
| struct wasi_ciovec_t vec = { .buf = (const uint8_t *)buf, .buf_len = len }; | ||
| wasi_size_t nwritten = 0; | ||
| return wasi_fd_write(fd, &vec, 1, &nwritten); | ||
| } | ||
|  | ||
| _Noreturn static inline void swift_abort(const char *message) { | ||
| swift_write(2, message, swift_strlen(message)); | ||
| wasi_proc_exit(1); | ||
| } | 
  
    
      This file contains hidden or 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 hidden or 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,60 @@ | ||
| // REQUIRES: swift_swift_parser | ||
| // REQUIRES: CODEGENERATOR=WebAssembly | ||
|  | ||
| // RUN: %empty-directory(%t) | ||
|  | ||
| // RUN: split-file %s %t | ||
|  | ||
| //#-- Prepare the Wasm macro plugin. | ||
| // RUN: %swift-build-wasm-c-plugin %t/MacroDefinition.c -o %t/Plugin.wasm | ||
|  | ||
| // RUN: env SWIFT_DUMP_PLUGIN_MESSAGING=1 %target-swift-frontend \ | ||
| // RUN: -typecheck \ | ||
| // RUN: -swift-version 5 \ | ||
| // RUN: -load-resolved-plugin %t/Plugin.wasm#%swift-plugin-server#MacroDefinition \ | ||
| // RUN: -Rmacro-loading \ | ||
| // RUN: -module-name MyApp \ | ||
| // RUN: %t/test.swift \ | ||
| // RUN: > %t/macro-loading.txt 2>&1 | ||
|  | ||
| // RUN: %FileCheck %s < %t/macro-loading.txt | ||
|  | ||
| // CHECK: ->(plugin:[[#PID:]]) {"getCapability":{"capability":{"protocolVersion":[[#PROTOCOL_VERSION:]]}}} | ||
| // CHECK: <-(plugin:[[#PID]]) {"getCapabilityResult":{"capability":{"features":["load-plugin-library"],"protocolVersion":7}}} | ||
| // CHECK: ->(plugin:[[#PID]]) {"loadPluginLibrary":{"libraryPath":"{{.*[\\/]}}Plugin.wasm","moduleName":"MacroDefinition"}} | ||
| // CHECK: <-(plugin:[[#PID]]) {"loadPluginLibraryResult":{"diagnostics":[],"loaded":true}} | ||
| // CHECK: ->(plugin:[[#PID]]) {"expandFreestandingMacro":{"discriminator":"$s{{.+}}","lexicalContext":[{{.*}}],"macro":{"moduleName":"MacroDefinition","name":"constInt","typeName":"ConstMacro"},"macroRole":"expression","syntax":{"kind":"expression","location":{"column":16,"fileID":"MyApp/test.swift","fileName":"{{.+}}test.swift","line":4,"offset":143},"source":"#constInt"}}} | ||
| // CHECK: <-(plugin:[[#PID]]) {"expandMacroResult":{"diagnostics":[],"expandedSource":"1"}} | ||
|  | ||
| //--- test.swift | ||
| @freestanding(expression) macro constInt() -> Int = #externalMacro(module: "MacroDefinition", type: "ConstMacro") | ||
|  | ||
| func foo() { | ||
| let _: Int = #constInt | ||
| } | ||
|  | ||
| //--- MacroDefinition.c | ||
| #include "Inputs/wasi_shim.h" | ||
|  | ||
| static void write_json(const char *json) { | ||
| wasi_size_t len = swift_strlen(json); | ||
| uint64_t len64 = (uint64_t)len; | ||
| swift_write(1, &len64, sizeof(len64)); | ||
| swift_write(1, json, len); | ||
| } | ||
|  | ||
| int was_start_called = 0; | ||
| int pump_calls = 0; | ||
|  | ||
| __attribute__((export_name("_start"))) | ||
| void _start(void) { | ||
| if (was_start_called) swift_abort("_start called twice!"); | ||
| was_start_called = 1; | ||
| } | ||
|  | ||
| __attribute__((export_name("swift_wasm_macro_v1_pump"))) | ||
| void pump(void) { | ||
| if (!was_start_called) swift_abort("_start not called!"); | ||
| if (pump_calls++ != 0) swift_abort("expected pump to be called once"); | ||
| write_json("{\"expandMacroResult\": {\"expandedSource\": \"1\", \"diagnostics\": []}}"); | ||
| } | 
  
    
      This file contains hidden or 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,33 @@ | ||
| // REQUIRES: swift_swift_parser | ||
| // REQUIRES: CODEGENERATOR=WebAssembly | ||
|  | ||
| // RUN: %empty-directory(%t) | ||
|  | ||
| // RUN: split-file %s %t | ||
|  | ||
| //#-- Prepare the Wasm macro plugin. | ||
| // RUN: %swift-build-wasm-c-plugin %t/MacroDefinition.c -o %t/Plugin.wasm | ||
|  | ||
| // RUN: %target-swift-frontend \ | ||
| // RUN: -typecheck -verify \ | ||
| // RUN: -swift-version 5 \ | ||
| // RUN: -load-resolved-plugin %t/Plugin.wasm#%swift-plugin-server#MacroDefinition \ | ||
| // RUN: -module-name MyApp \ | ||
| // RUN: %t/test.swift | ||
|  | ||
| //--- test.swift | ||
| // expected-warning @+2 {{Wasm plugin has an unknown ABI (could not find 'swift_wasm_macro_v1_pump')}} | ||
| // expected-note @+1 {{declared here}} | ||
| @freestanding(expression) macro constInt() -> Int = #externalMacro(module: "MacroDefinition", type: "ConstMacro") | ||
|  | ||
| func foo() { | ||
| // expected-error @+1 {{Wasm plugin has an unknown ABI (could not find 'swift_wasm_macro_v1_pump')}} | ||
| let _: Int = #constInt | ||
| } | ||
|  | ||
| //--- MacroDefinition.c | ||
| __attribute__((export_name("_start"))) | ||
| void _start(void) {} | ||
|  | ||
| __attribute__((export_name("swift_wasm_macro_v100_pump"))) | ||
| void pump(void) {} | 
  
    
      This file contains hidden or 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,40 @@ | ||
| // REQUIRES: swift_swift_parser | ||
| // REQUIRES: CODEGENERATOR=WebAssembly | ||
|  | ||
| // RUN: %empty-directory(%t) | ||
|  | ||
| // RUN: split-file %s %t | ||
|  | ||
| //#-- Prepare the Wasm macro plugin. | ||
| // RUN: %swift-build-wasm-c-plugin %t/MacroDefinition.c -o %t/Plugin.wasm | ||
|  | ||
| // RUN: %target-swift-frontend \ | ||
| // RUN: -typecheck -verify \ | ||
| // RUN: -swift-version 5 \ | ||
| // RUN: -load-resolved-plugin %t/Plugin.wasm#%swift-plugin-server#MacroDefinition \ | ||
| // RUN: -module-name MyApp \ | ||
| // RUN: %t/test.swift \ | ||
| // RUN: 2>%t/macro-loading.txt | ||
|  | ||
| // RUN: %FileCheck %s < %t/macro-loading.txt | ||
|  | ||
| // CHECK: guest error! | ||
|  | ||
| //--- test.swift | ||
| @freestanding(expression) macro constInt() -> Int = #externalMacro(module: "MacroDefinition", type: "ConstMacro") | ||
|  | ||
| func foo() { | ||
| // expected-error @+1 {{failed to communicate with external macro}} | ||
| let _: Int = #constInt | ||
| } | ||
|  | ||
| //--- MacroDefinition.c | ||
| #include "Inputs/wasi_shim.h" | ||
|  | ||
| __attribute__((export_name("_start"))) | ||
| void _start(void) {} | ||
|  | ||
| __attribute__((export_name("swift_wasm_macro_v1_pump"))) | ||
| void pump(void) { | ||
| swift_abort("guest error!\n"); | ||
| } | 
  
    
      This file contains hidden or 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,33 @@ | ||
| // REQUIRES: swift_swift_parser | ||
| // REQUIRES: CODEGENERATOR=WebAssembly | ||
|  | ||
| // RUN: %empty-directory(%t) | ||
|  | ||
| // RUN: split-file %s %t | ||
|  | ||
| //#-- Prepare the Wasm macro plugin. | ||
| // RUN: %swift-build-wasm-c-plugin %t/MacroDefinition.c -o %t/Plugin.wasm | ||
|  | ||
| // RUN: %target-swift-frontend \ | ||
| // RUN: -typecheck -verify \ | ||
| // RUN: -swift-version 5 \ | ||
| // RUN: -load-resolved-plugin %t/Plugin.wasm#%swift-plugin-server#MacroDefinition \ | ||
| // RUN: -module-name MyApp \ | ||
| // RUN: %t/test.swift | ||
|  | ||
| //--- test.swift | ||
| // expected-warning @+2 {{Wasm plugin does not have a '_start' entrypoint}} | ||
| // expected-note @+1 {{declared here}} | ||
| @freestanding(expression) macro constInt() -> Int = #externalMacro(module: "MacroDefinition", type: "ConstMacro") | ||
|  | ||
| func foo() { | ||
| // expected-error @+1 {{Wasm plugin does not have a '_start' entrypoint}} | ||
| let _: Int = #constInt | ||
| } | ||
|  | ||
| //--- MacroDefinition.c | ||
| __attribute__((export_name("_tart"))) | ||
| void _start(void) {} | ||
|  | ||
| __attribute__((export_name("swift_wasm_macro_v1_pump"))) | ||
| void pump(void) {} | 
  
    
      This file contains hidden or 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 hidden or 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,9 @@ | ||
| # editorconfig.org | ||
|  | ||
| root = true | ||
|  | ||
| [*] | ||
| indent_style = space | ||
| indent_size = 2 | ||
| trim_trailing_whitespace = true | ||
| insert_final_newline = true | 
  
    
      This file contains hidden or 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 @@ | ||
| Package.resolved | 
  
    
      This file contains hidden or 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,3 @@ | ||
| --indent 2 | ||
| --self insert | ||
|  | 
  
    
      This file contains hidden or 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 hidden or 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.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose the alternative to this is to thread new variables for these paths throughout
build-scriptandbuild.ps1, which is... a lot of boilerplate.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, do you think it's worth doing that right now? Or would it be preferable to merge as-is?