diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index cc652de9fe9..9197dac472e 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -48,3 +48,12 @@ jobs: name: plc.exe path: target/release/plc.exe + - uses: actions/upload-artifact@master + with: + name: stdlib.dll + path: target/release/iec61131std.dll + + - uses: actions/upload-artifact@master + with: + name: stdlib.lib + path: target/release/iec61131std.lib diff --git a/book/src/arch/architecture.md b/book/src/arch/architecture.md index 225eebda1a6..a47e816f050 100644 --- a/book/src/arch/architecture.md +++ b/book/src/arch/architecture.md @@ -3,7 +3,7 @@ ## Overview RuSTy is a compiler for IEC61131-3 languages. At the moment, ST and CFC ("FBD") are supported. -It utilizes the LLVM compiler infrastructurue and contributes a [Structured Text](https://en.wikipedia.org/wiki/Structured_text) frontend that translates Structured Text into LLVM's language independent intermediate representation (IR). +It utilizes the LLVM compiler infrastructure and contributes a [Structured Text](https://en.wikipedia.org/wiki/Structured_text) frontend that translates Structured Text into LLVM's language independent intermediate representation (IR). [CFC](../cfc/cfc.md) uses a M2M-transformation and reuses most of the ST frontend for compilation. The further optimization and native code generation is performed by the existing LLVM infrastructure, namely LLVM's common optimizer and the platform specific backend (see [here](https://www.aosabook.org/en/llvm.html)). diff --git a/book/src/using_rusty.md b/book/src/using_rusty.md index 83fa8f68d19..5d1fbab95c1 100644 --- a/book/src/using_rusty.md +++ b/book/src/using_rusty.md @@ -161,4 +161,46 @@ int main() { return 0; } -``` \ No newline at end of file +``` + +## Native Windows Usage Example + +- Ensure [`LLVM 14.0.6`](https://github.com/PLC-lang/llvm-package-windows/releases/tag/v14.0.6) is installed and it's `bin` folder is added to your `PATH` environment variable. + +- Install `plc.zip` from the [Windows Build Pipeline](https://github.com/PLC-lang/rusty/actions/workflows/windows.yml). + + - Add it's location to the PATH environment variable. An AppData location is recommended. + +- Install `stdlib.lib` from the same pipeline into the same folder. + +- Install the `Windows SDK` and `MSVC`. You can use the Visual Studio Installer to do this or install them as standalone packages. + +- Create a `LIB` environment variable containing paths to `iec61131std.lib`, `ws2_32.lib`, `ntdll.lib`, `userenv.lib`, `libcmt.lib`, `oldnames.lib` and `libucrt.lib`. + + - Your environment variable should look something like this: + + ``` + C:/Users//AppData/Local/rustycompiler; + C:\Program Files (x86)\Windows Kits\10\Lib\10.0.26100.0\um\x64; + C:\Program Files (x86)\Windows Kits\10\Lib\10.0.26100.0\ucrt\x64; + C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.43.34808\lib\x64; + ``` + +- Restart your terminals to refresh the environment. + +- Create an `exports.def` file in preparation `clang` usage. + +``` +EXPORTS + main + +``` + +This example allows linking with Rusty's Standard Library. + +- Proceed with compilation: + + ``` + plc ./examples/hello_world.st -c -l iec61131std -l ws2_32 -l ntdll -l userenv -o ./hello_world.o + clang ./hello_world.o --shared -l iec61131std -l ws2_32 -l ntdll -l userenv -fuse-ld=lld-link "-Wl,/DEF:exports.def" -o ./hello_world.dll + ``` diff --git a/libs/stdlib/build.rs b/libs/stdlib/build.rs index 45ad1d9cefe..ad47d277896 100644 --- a/libs/stdlib/build.rs +++ b/libs/stdlib/build.rs @@ -34,10 +34,10 @@ fn main() { //link the object file println!("cargo:rustc-link-search=native={out_dir}"); - println!("cargo:rustc-link-lib=static=st"); println!("cargo:rerun-if-changed=iec61131-st/"); + println!("cargo:rustc-link-lib=static:+whole-archive=st"); //create a whole archive without throwing away any object files (https://github.com/rust-lang/rust/pull/105601). - //We can link against the st lib gernerated, but this will only be reflected in static libs. + //We can link against the st lib generated, but this will only be reflected in static libs. // The shared lib still has to be generated later. // There is a planned feature in rust to allow whole-archive linking, but i could not get it to // work (should look something like this : `println!("cargo:rustc-flags=-l static:+whole-archive=st");`) diff --git a/src/linker.rs b/src/linker.rs index 0d4bd065310..a0906c1b742 100644 --- a/src/linker.rs +++ b/src/linker.rs @@ -47,11 +47,9 @@ impl Linker { }; match (platform, target_os) { (_, "win32") | (_, "windows") | ("win32", _) | ("windows", _) => { - return Err(LinkerError::Target(target_os.into())) - } - + Box::new(CcLinker::new("clang")) + } //only clang from llvm is supported in windows (_, "darwin") => Box::new(CcLinker::new("clang")), - _ => Box::new(LdLinker::new()), } } @@ -290,7 +288,7 @@ mod test { use crate::linker::{Linker, LinkerType}; #[test] - fn windows_target_triple_should_result_in_error() { + fn windows_target_triple_should_result_in_ok() { for target in &[ "x86_64-pc-windows-gnu", "x86_64-pc-win32-gnu", @@ -305,7 +303,7 @@ mod test { "i686-windows-gnu", "i686-win32-gnu", ] { - assert!(Linker::new(target, LinkerType::Internal).is_err()); + assert!(Linker::new(target, LinkerType::Internal).is_ok()); } }