File tree Expand file tree Collapse file tree 16 files changed +96
-40
lines changed
Expand file tree Collapse file tree 16 files changed +96
-40
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
1010### Fixed
1111
12+ * [ Rust] Fixed import path rewrite (by @ncave )
1213* [ Rust] Updated derived interfaces (by @ncave )
1314* [ Rust] Updated string comparisons (by @ncave )
1415* [ Rust] Fixed derived traits mapping (by @ncave )
Original file line number Diff line number Diff line change @@ -442,7 +442,21 @@ module Rust =
442442 let stream = new IO.StreamWriter( targetPath)
443443
444444 interface Printer.Writer with
445- member _.Write ( str ) =
445+ member self.Write ( str ) =
446+
447+ let str =
448+ // rewrite import paths in last file
449+ if com.CurrentFile = ( Array.last com.SourceFiles) then
450+ System.Text.RegularExpressions.Regex.Replace(
451+ str,
452+ @" (#\[path\s*=\s*\"" )([^"" ]*)(\"" ])" ,
453+ fun m ->
454+ let path = ( self :> Printer.Writer) .MakeImportPath( m.Groups[ 2 ]. Value)
455+ m.Groups[ 1 ]. Value + path + m.Groups[ 3 ]. Value
456+ )
457+ else
458+ str
459+
446460 stream.WriteAsync( str) |> Async.AwaitTask
447461
448462 member _.MakeImportPath ( path ) =
Original file line number Diff line number Diff line change @@ -617,7 +617,10 @@ module Imports =
617617 importPath
618618
619619 if isAbsolutePath importPath then
620- if importPath.EndsWith( " .fs" , StringComparison.Ordinal) then
620+ if
621+ importPath.EndsWith( " .fs" , StringComparison.Ordinal)
622+ || importPath.EndsWith( " .rs" , StringComparison.Ordinal)
623+ then
621624 getTargetRelativePath pathResolver importPath targetDir projDir outDir
622625 else
623626 getRelativePath targetDir importPath
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ module Naming =
2020 let rustPrelude = HashSet( kw.RustPrelude)
2121
2222 let rawIdent ( ident : string ) =
23- if ident.StartsWith( " r#" ) then
23+ if ident = " " || ident = " _ " || ident .StartsWith( " r#" ) then
2424 ident
2525 else
2626 " r#" + ident
Original file line number Diff line number Diff line change @@ -2228,9 +2228,8 @@ module Util =
22282228
22292229 let maybeAddParens fableExpr ( expr : Rust.Expr ) : Rust.Expr =
22302230 match fableExpr with
2231- | Fable.IfThenElse _ -> mkParenExpr expr
2232- // TODO: add more expressions that need parens
2233- | _ -> expr
2231+ | Fable.Value _ -> expr
2232+ | _ -> mkParenExpr expr
22342233
22352234 let transformOperation com ctx range typ opKind : Rust.Expr =
22362235 match opKind with
@@ -5103,6 +5102,7 @@ module Util =
51035102 let isFableLibraryPath ( com : IRustCompiler ) ( path : string ) =
51045103 not ( isFableLibrary com)
51055104 && ( path.StartsWith( com.LibraryDir, StringComparison.Ordinal)
5105+ || path.Contains( " fable-library-rust" )
51065106 || path = " fable_library_rust" )
51075107
51085108 let getImportModulePath ( com : IRustCompiler ) ( path : string ) =
@@ -5235,7 +5235,8 @@ module Compiler =
52355235 // add import module to a global list (across files)
52365236 if
52375237 path.Length > 0
5238- && path <> " fable_library_rust"
5238+ && not ( path = " fable_library_rust" )
5239+ && not ( path.Contains( " fable-library-rust" ))
52395240 && not ( isFableLibraryPath self path)
52405241 then
52415242 importModules.TryAdd( modulePath, true ) |> ignore
Original file line number Diff line number Diff line change @@ -5,3 +5,5 @@ perf*.data
55perf * .svg
66build /
77dist /
8+ target /
9+ Cargo.lock
Original file line number Diff line number Diff line change 1+ [package ]
2+ name = " bench-compiler"
3+ version = " 0.1.0"
4+ edition = " 2021"
5+
6+ [[bin ]]
7+ name = " bench-compiler"
8+ path = " ./out-rust/app.rs"
9+
10+ [features ]
11+ threaded = [" fable_library_rust/threaded" ]
12+ default = [" threaded" ]
13+
14+ [dependencies ]
15+ fable_library_rust = { path = " ./out-rust/fable_modules/fable-library-rust" }
Original file line number Diff line number Diff line change @@ -84,7 +84,26 @@ let getGlobFiles (path: string) =
8484let serializeToJson ( value : obj ) =
8585 System.Text.Json.JsonSerializer.Serialize( value)
8686
87- #else
87+ #endif
88+
89+ #if FABLE_ COMPILER_ RUST
90+
91+ let readAllBytes ( filePath : string ) : byte [] = [||]
92+ let readAllText ( filePath : string ) : string = " "
93+ let writeAllText ( filePath : string ) ( text : string ) : unit = ()
94+ let measureTime ( f : 'a -> 'b ) x = f x, 0
95+ let ensureDirExists ( path : string ) : unit = ()
96+ let normalizePath ( path : string ) = path.Replace( '\\' , '/' )
97+ let normalizeFullPath ( path : string ) = path
98+ let getRelativePath ( path : string ) ( pathTo : string ) = path
99+ let getHomePath () = " "
100+ let getDirFiles ( path : string ) ( extension : string ) : string [] = [||]
101+ let getGlobFiles ( path : string ) : string [] = [||]
102+ let serializeToJson ( value : obj ) = " "
103+
104+ #endif
105+
106+ #if FABLE_ COMPILER_ JAVASCRIPT || FABLE_ COMPILER_ TYPESCRIPT
88107
89108open Fable.Core .JsInterop
90109
File renamed without changes.
Original file line number Diff line number Diff line change @@ -4,10 +4,10 @@ open Fable.Compiler.Platform
44open Fable.Compiler .ProjectParser
55
66let getMetadataDir () : string =
7- __ SOURCE_ DIRECTORY__ + " /../../../../ fable-metadata/lib/"
7+ __ SOURCE_ DIRECTORY__ + " /../../../fable-metadata/lib/"
88
99let getFableLibDir () : string =
10- __ SOURCE_ DIRECTORY__ + " /../../../../../ temp/fable-library-js"
10+ __ SOURCE_ DIRECTORY__ + " /../../../../temp/fable-library-js"
1111
1212let getVersion () : string = " .next"
1313
You can’t perform that action at this time.
0 commit comments