Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion book/src/arch/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)).

Expand Down
44 changes: 43 additions & 1 deletion book/src/using_rusty.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,46 @@ int main() {

return 0;
}
```
```

## 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/<USERNAME HERE>/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
```
4 changes: 2 additions & 2 deletions libs/stdlib/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");`)
Expand Down
10 changes: 3 additions & 7 deletions src/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,8 @@ impl Linker {
return Err(LinkerError::Target(target.into()));
};
match (platform, target_os) {
(_, "win32") | (_, "windows") | ("win32", _) | ("windows", _) => {
return Err(LinkerError::Target(target_os.into()))
}

(_, "win32") | (_, "windows") | ("win32", _) | ("windows", _) => Box::new(CcLinker::new("clang")), //only clang from llvm is supported in windows
(_, "darwin") => Box::new(CcLinker::new("clang")),

_ => Box::new(LdLinker::new()),
}
}
Expand Down Expand Up @@ -290,7 +286,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",
Expand All @@ -305,7 +301,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());
}
}

Expand Down
Loading